I got the below working yesterday. now today it just keeps cycling the same port over and over.
I was hoping someone could assist in where I made a mistake or help tweak this.
I am trying to cycle any port in a defined net id that is set to the target vlan.
import meraki
target_vlan = 5
# Create Meraki API Dashboard interface
dashboard = meraki.DashboardAPI(API_KEY, suppress_logging=True)
devices = dashboard.organizations.getOrganizationDevices(ORG_ID, total_pages='all', networkIds=[NET_ID])
for device in devices:
if device['productType'] == 'switch':
device_ports = dashboard.switch.getDeviceSwitchPorts(device['serial'])
# Filter ports by VLAN
ports_to_cycle = []
for port in device_ports:
if port['vlan'] == target_vlan:
ports_to_cycle.append(str(port['portId']))
# Cycle the selected ports
if ports_to_cycle:
dashboard.switch.cycleDeviceSwitchPorts(device['serial'], ports_to_cycle)
print(f"Successfully cycled ports {ports_to_cycle} on switch {device['name']} in VLAN {target_vlan}")
else:
print(f"No ports found in VLAN {target_vlan} on switch {device['name']}")