def clone_net_with_devices(self, curr_net_id: str, new_net_name: str, devs: List[str], kind, timezone): """ create a new network by cloning network and adding/moving devices to it """ org_id = self.get_my_org_id() res = meraki.addnetwork(self.apikey, org_id, new_net_name, kind, "", timezone, cloneid=curr_net_id) try: net_id = res.get("id", None) except AttributeError: # because error returns a list... raise NetworkNotFound(res[0]) if not net_id: raise NetworkNotFound() for dev in devs: print( f"adding device {dev} to network {new_net_name} and removing from old network" ) self.remove_device_from_network(dev) devaddstat = meraki.adddevtonet(self.apikey, net_id, dev) print(devaddstat) return res
my_network_devices = meraki.getnetworkdevices(my_key, my_netid) # No device in network yet if len(my_network_devices) == 0: # Pick a random AP from the unused inventory my_ap = random.choice(unused) my_serial = my_ap['serial'] print( 'Part 3: found an unused AP from inventory, with serial number {0}\n'. format(my_serial)) ######################### ##### START EDITING ##### # Call to claim a device into a network # Only one line needs to be filled here, with the same indentation (4 spaces) meraki.adddevtonet() ###### END EDITING ###### ######################### # Check if device was claimed correctly if len(meraki.getnetworkdevices(my_key, my_netid)) == 0: sys.exit('Part 3: AP not successfully claimed\n') else: print('Part 3: added AP {0} into the {1} network\n'.format( my_serial, my_name)) # Device already added else: my_ap = my_network_devices[0] my_serial = my_ap['serial'] print('Part 3: AP {0} already added to network {1}\n'.format( my_serial, my_name))
my_network_devices = meraki.getnetworkdevices(my_key, my_netid) # No device in network yet if len(my_network_devices) == 0: # Pick a random AP from the unused inventory my_ap = random.choice(unused) my_serial = my_ap['serial'] print( 'Part 3: found an unused AP from inventory, with serial number {0}\n'. format(my_serial)) ######################### ##### START EDITING ##### # Call to claim a device into a network # Only one line needs to be filled here, with the same indentation (4 spaces) meraki.adddevtonet(my_key, my_netid, my_serial) ###### END EDITING ###### ######################### # Check if device was claimed correctly if len(meraki.getnetworkdevices(my_key, my_netid)) == 0: sys.exit('Part 3: AP not successfully claimed\n') else: print('Part 3: added AP {0} into the {1} network\n'.format( my_serial, my_name)) # Device already added else: my_ap = my_network_devices[0] my_serial = my_ap['serial'] print('Part 3: AP {0} already added to network {1}\n'.format( my_serial, my_name))
print(device['serial'], " ", device['type']) ##Create a new network net_name = input('Enter Network Name: ') print('Adding network', net_name) new_net = meraki.addnetwork(apikey, orgid, net_name, 'appliance wireless switch', None, 'America/Phoenix') #network id of newly added network is returned in addnetwork function in a dictionary under the key 'id' ##Add all the devices to network for dev in devices: meraki.adddevtonet(apikey, new_net['id'], dev['serial']) ##Update attributes #For each device apply address, move map marker (api has a way to do this) #APs do not get named, however address and map marker are updated for dev in devices: #if device is AP, don't update name if dev['type'] == '': meraki.updatedevice(apikey, networkid=new_net['id'], serial=dev['serial'], address=dev['address'], move='true') #Else it's either SW or FW, so go update the name else:
print(bcolors.ACTION,'Now it is time to add a swtich to the network', bcolors.ENDC) while True: switchsn = input(bcolors.QUESTION + 'What is the Switch Serial Number (QNXX-XXXX-XXXX) (Q2EX-X5WR-SQAU for testing)? ' + bcolors.ENDC) while not re.match("[Q][2][A-Z0-9][A-Z0-9]-[A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9]-[A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9]", switchsn): print (bcolors.FAIL,"Invalid Format for Serial Number. Please try again.",bcolors.FAIL) switchsn = input(bcolors.QUESTION + 'What is the Switch Serial Number (QNXX-XXXX-XXXX) (Q2EX-X5WR-SQAU for testing)? ' + bcolors.ENDC) else: print("Switch Serial number is "+ switchsn) break # Claim a device into a network # https://dashboard.meraki.com/api_docs#claim-a-device-into-a-network #def adddevtonet(apikey, networkid, serial, suppressprint=False): addswitch = mer.adddevtonet(apikey, newnetworkid, switchsn, suppressprint=False) print(bcolors.RESULT, addswitch, bcolors.ENDC) #Add AP to the network, Verify Serial number with Regex print(bcolors.ACTION,'Now it is time to add an Access Point to the network', bcolors.ENDC) while True: apsn = input(bcolors.QUESTION + ' What is the Access Point Serial Number (QNXX-XXXX-XXXX) (Q2KD-3PUQ-K9KX for testing)? ' + bcolors.ENDC) while not re.match("[Q][2][A-Z0-9][A-Z0-9]-[A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9]-[A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9]", apsn): print ("Error! Make sure your ADP Code contains 2 letters, then 3 numbers") switchsn = input(bcolors.QUESTION + ' What is the Access Point Serial Number (QNXX-XXXX-XXXX) (Q2KD-3PUQ-K9KXfor testing)? ' + bcolors.ENDC) else: print("Access Point Serial number is "+ apsn) break