Because I thought that it might be useful for me in the future. I might have some misses here and there, or not very efficient, but if you're like me and have 40 organizations.. then...
dashboard = meraki.DashboardAPI(x_cisco_meraki_api_key, suppress_logging=True)
organizations = dashboard.organizations.getOrganizations()
SWITCH = True # Set to True if you want to display the vlans from MX
APPLIANCE = True # set to True if you want to display the vlans from MS
print("Organization,Network,Type,Subnet,Vlan name,Vlan ID")
for org in organizations:
networks = dashboard.organizations.getOrganizationNetworks(organizationId=org["id"])
devices = dashboard.organizations.getOrganizationDevices(organizationId=org["id"], productTypes=["appliance", "switch"])
for network in networks:
if "appliance" in network["productTypes"] and APPLIANCE is True:
networkSettings = dashboard.networks.getNetworkSettings(networkId=network["id"])
try:
singleVlan = dashboard.appliance.getNetworkApplianceSingleLan(networkId=network["id"])
print(f"{org['name']},{network['name']},MX,{singleVlan['subnet']},,1")
except Exception as e:
pass
try:
vlans = dashboard.appliance.getNetworkApplianceVlans(networkId=network["id"])
for vlan in vlans:
print(f"{org['name']},{network['name']},MX,{vlan['subnet']},{vlan['name']},{vlan['id']}")
except Exception as e:
pass
if "switch" in network["productTypes"] and SWITCH is True:
switchStacks = dashboard.switch.getNetworkSwitchStacks(networkId=network["id"])
switches = [switch for switch in devices if switch["productType"] == "switch" and switch["networkId"] == network["id"]]
for stack in switchStacks:
for serial in stack['serials']:
for index, switch in enumerate(switches):
switches.pop(index)
stackVlans = dashboard.switch.getNetworkSwitchStackRoutingInterfaces(networkId=network["id"], switchStackId=stack["id"])
for stackVlan in stackVlans:
print(f"{org['name']},{network['name']},MS-stack,{stackVlan['subnet']},{stackVlan['name']},{stackVlan['vlanId']}")
for switch in switches:
switchVlans = dashboard.switch.getDeviceSwitchRoutingInterfaces(serial=switch["serial"])
for switchVlan in switchVlans:
print(f"{org['name']},{network['name']},MS-nonstack,{switchVlan['subnet']},{switchVlan['name']},{switchVlan['vlanId']}")