networks = merakiapi.getnetworklist(apikey, organizationid) cleannetworks = [] for network in networks: for key, value in network.items(): if key == 'id': net_id = value elif key == 'name': net_name = value else: continue cleannetworks.append([net_id, net_name]) cleannetworks.sort(key=lambda x: x[1]) cleannetworks.insert(0, [None, '* Choose...']) #TEMPLATE DROPDOWN templates = merakiapi.gettemplates(apikey, organizationid) cleantemplates = [] for template in templates: for key, value in template.items(): if key == 'id': template_id = value elif key == 'name': template_name = value else: continue cleantemplates.append([template_id, template_name]) cleantemplates.sort(key=lambda x: x[1]) cleantemplates.insert(0, ["", '* No Template']) #TAG DROPDOWN networks = merakiapi.getnetworklist(apikey, organizationid)
class CreateProvisionForm(FlaskForm): #ADDRESS FIELD addressField = TextAreaField( 'Street Address: ', [validators.Optional(), validators.length(max=200)]) #NETWORK CREATE FIELD networkTextField = StringField('New Network Name*', [validators.InputRequired()]) #TEMPLATE DROPDOWN templates = merakiapi.gettemplates(apikey, organizationid) cleantemplates = [] for template in templates: for key, value in template.items(): if key == 'id': template_id = value elif key == 'name': template_name = value else: continue cleantemplates.append([template_id, template_name]) cleantemplates.sort(key=lambda x: x[1]) cleantemplates.insert(0, ["", '* No Template']) templateField = SelectField(u'Template to bind to*', choices=cleantemplates) #SERIAL NUMBER FIELDS serialField1 = StringField('Serial Number 1*: ', [ validators.InputRequired(), validators.Length( min=14, max=14, message='Invalid format. Must be Q2XX-XXXX-XXXX') ]) serialField2 = StringField('Serial Number 2: ', [ validators.Optional(), validators.Length( min=14, max=14, message='Invalid format. Must be Q2XX-XXXX-XXXX') ]) serialField3 = StringField('Serial Number 3: ', [ validators.Optional(), validators.Length( min=14, max=14, message='Invalid format. Must be Q2XX-XXXX-XXXX') ]) serialField4 = StringField('Serial Number 4: ', [ validators.Optional(), validators.Length( min=14, max=14, message='Invalid format. Must be Q2XX-XXXX-XXXX') ]) serialField5 = StringField('Serial Number 5: ', [ validators.Optional(), validators.Length( min=14, max=14, message='Invalid format. Must be Q2XX-XXXX-XXXX') ]) serialField6 = StringField('Serial Number 6: ', [ validators.Optional(), validators.Length( min=14, max=14, message='Invalid format. Must be Q2XX-XXXX-XXXX') ]) serialField7 = StringField('Serial Number 7: ', [ validators.Optional(), validators.Length( min=14, max=14, message='Invalid format. Must be Q2XX-XXXX-XXXX') ]) serialField8 = StringField('Serial Number 8: ') nameField1 = StringField('Device Name: ', [validators.Optional()]) nameField2 = StringField('Device Name: ', [validators.Optional()]) nameField3 = StringField('Device Name: ', [validators.Optional()]) nameField4 = StringField('Device Name: ', [validators.Optional()]) nameField5 = StringField('Device Name: ', [validators.Optional()]) nameField6 = StringField('Device Name: ', [validators.Optional()]) nameField7 = StringField('Device Name: ', [validators.Optional()]) nameField8 = StringField('Device Name: ', [validators.Optional()]) submitField = SubmitField('Submit')
######################################################################################################################## # # Sample Python Script using Meraki API module to migrate non-template bound networks to a specific template name # while retaining and re-applying static VLAN configuration # ######################################################################################################################## import merakiapi apikey = 'ENTER API KEY HERE' orgid = 'ENTER ORG ID HERE' templatename = 'ENTER THE NAME OF THE TARGET TEMPLATE HERE' templates = merakiapi.gettemplates(apikey, orgid) for template in templates: if template['name'] == templatename: templateid = template['id'] mxnetworks = [] orgnets = merakiapi.getnetworklist(apikey, orgid) for network in orgnets: if network['type'] == 'appliance' and network['name'][:2] == 'zz': mxnetworks.append({'id': network['id'], 'name': network['name']}) for mxnetwork in mxnetworks: newnet = True vlans = merakiapi.getvlans(apikey, mxnetwork['id']) if vlans is None: