Whoop Whoop, finally made it working... Always had problem, now I got it, after changing the following: Original: # loop over the networks
if networks: # make sure it's not an empty organization
for network in networks:
# create a devicescontroller to fetch devices
devicescontroller = client.devices
# fetch a list of devices in the specified network
devices = devicescontroller.get_network_devices(network['id'])
# prepare the devicescollection to reboot them
devicescollect = {}
for device in devices:
# only interested in MX devices
if 'MX' in device['model']:
devicescollect['serial'] = device['serial']
devicescollect['network_id'] = network['id']
# reboot the device
if devicescollect: # make sure there are devices to reboot
result = devicescontroller.reboot_network_device(devicescollect)
if result['success']:
print("The device with the name ", device['name'], "(", device['model'],
") in the network ", network['name'], " was successfully rebooted.")
else:
print("ERROR: The device with the name ", device['name'], "(", device['model'],
") in the network ", network['name'], " could not be rebooted.") My new setup: # loop over the networks if networks: # make sure it's not an empty organization for network in networks: # create a devicescontroller to fetch devices devicescontroller = client.devices # fetch a list of devices in the specified network devices = devicescontroller.get_network_devices(network['id']) # prepare the devicescollection to reboot them devicescollect = {} for device in devices: # only interested in MX devices if 'MX' in device['model']: devicescollect['serial'] = device['serial'] devicescollect['network_id'] = network['id'] # reboot the device if devicescollect: # make sure there are devices to reboot result = devicescontroller.reboot_network_device(devicescollect) if result['success']: print("SUCCESS: Following devices have been rebooted ", network['name']) else: print("ERROR: Following device could not been rebooted ", network['name']) Only at the End, the results / print messages have to be more to the right, as otherwise the script wants to reboot (in my organization) MR´s on site as well. I´m sure if I would have MS´s in there, they would be restartet as well. In my case, who wants to reboot MX´s thats fine. but you could restart only MS´s / MS´s now as well. Complete Script: from meraki.meraki import Meraki
# user API key
x_cisco_meraki_api_key = 'your API Key'
try:
client = Meraki(x_cisco_meraki_api_key)
# get a list of organizations the user has access to
orgs = client.organizations.get_organizations()
# prepare the orgcollect to be used in the get_organization_networks call
orgcollect = {}
for org in orgs:
#print(org['id'])
# only interested in a specific organization
if org['id'] == 123456: # Your Org here
orgcollect['organization_id'] = org['id']
# fetch all networks in the organization(s)
if orgcollect: # make sure it's not an empty collection
networks = client.networks.get_organization_networks(orgcollect)
# loop over the networks
if networks: # make sure it's not an empty organization
for network in networks:
# create a devicescontroller to fetch devices
devicescontroller = client.devices
# fetch a list of devices in the specified network
devices = devicescontroller.get_network_devices(network['id'])
# prepare the devicescollection to reboot them
devicescollect = {}
for device in devices:
# only interested in MX devices
if 'MX' in device['model']:
devicescollect['serial'] = device['serial']
devicescollect['network_id'] = network['id']
# reboot the device
if devicescollect: # make sure there are devices to reboot
result = devicescontroller.reboot_network_device(devicescollect)
if result['success']:
print("SUCCESS: Following devices have been rebooted ", network['name'])
else:
print("ERROR: Following device could not been rebooted ", network['name'])
else:
print("Empty Organization")
else:
print("No organizations selected")
except:
print("Exception occurred, possibly and invalid API key.")
... View more