Пример #1
0
def provision():
    form = AddProvisionForm()
    if form.validate_on_submit():
        message = []
        postSerials = []
        postNames = []
        
        postNetwork = form.networkField.data
        
        #BUILD ARRAY OF SERIAL NUMBERS FROM FORM
        postSerials.append(form.serialField1.data)
        postSerials.append(form.serialField2.data)
        postSerials.append(form.serialField3.data)
        postSerials.append(form.serialField4.data)
        postSerials.append(form.serialField5.data)
        postSerials.append(form.serialField6.data)
        postSerials.append(form.serialField7.data)
        postSerials.append(form.serialField8.data)
        postSerials = [element.upper() for element in postSerials]; postSerials
        
        postNames.append(form.nameField1.data)
        postNames.append(form.nameField2.data)
        postNames.append(form.nameField3.data)
        postNames.append(form.nameField4.data)
        postNames.append(form.nameField5.data)
        postNames.append(form.nameField6.data)
        postNames.append(form.nameField7.data)
        postNames.append(form.nameField8.data)
        #print(postSerials)
        
        for i,serial in enumerate(postSerials):
            #SKIP EMPTY SERIAL NUMBER TEXT BOXES
            if serial is '':
                continue
            #EASTER EGG
            elif "ILOVEMERAKI" in serial:
                message = Markup("<img src='/static/meraki.png' />")
            else:
                result = merakiapi.adddevtonet(apikey, postNetwork, serial)
                if result == None:
                    #SET ADDRESS AND NAME
                    merakiapi.updatedevice(apikey, postNetwork, serial, name=postNames[i], address=form.addressField.data, move='true')
                    #API RETURNS EMPTY ON SUCCESS, POPULATE SUCCESS MESSAGE MANUALLY
                    netname = merakiapi.getnetworkdetail(apikey, postNetwork)
                    message = Markup('Device with serial <strong>{}</strong> successfully added to Network: <strong>{}</strong>'.format(serial, netname['name']))
                #404 MESSAGE FOR INVALID SERIAL IS BLANK, POPULATE ERROR MESSAGE MANUALLY
                elif result == 'noserial':
                    message = 'Invalid serial {}'.format(serial)
                else:
                    message = result
            #SEND MESSAGE TO SUBMIT PAGE
            flash(message)
        return redirect('/submit')
    return render_template('index.html', title='Meraki Device Provisioning', form=form)
Пример #2
0
def replaceForm():
    form = ReplaceDevice()
    if form.validate_on_submit():
        message = []

        postNetwork = form.networkField.data
        netname = merakiapi.getnetworkdetail(apikey, postNetwork)
        oldMX = form.oldMX.data
        newMX = form.newMX.data
        oldSwitch = form.oldSwitch.data
        newSwitch = form.newSwitch.data
        oldAP = form.oldAP.data
        newAP = form.newAP.data

        if oldMX is not '':
            oldconfig = merakiapi.getdevicedetail(apikey, postNetwork, oldMX)
            merakiapi.updatedevice(apikey,
                                   postNetwork,
                                   newMX,
                                   name=oldconfig['name'],
                                   tags=oldconfig['tags'],
                                   lat=oldconfig['lat'],
                                   lng=oldconfig['lng'],
                                   address=oldconfig['address'],
                                   move='true')
            result = merakiapi.removedevfromnet(apikey, postNetwork, oldMX)
            if result == None:
                message = Markup(
                    'MX with serial <strong>{}</strong> successfully deleted from Network: <strong>{}</strong>'
                    .format(oldMX, netname['name']))
            merakiapi.claim(apikey, organizationid, serial=newMX)
            result = merakiapi.adddevtonet(apikey, postNetwork, newMX)
            if result == None:
                message = Markup(
                    'MX with serial <strong>{}</strong> successfully added to Network: <strong>{}</strong>'
                    .format(newMX, netname['name']))

        if oldSwitch is not '':
            #ADD NEW SWITCH TO NETWORK
            merakiapi.claim(apikey, organizationid, serial=newSwitch)
            result = merakiapi.adddevtonet(apikey, postNetwork, newSwitch)
            oldconfig = merakiapi.getdevicedetail(apikey, postNetwork,
                                                  oldSwitch)
            merakiapi.updatedevice(apikey,
                                   postNetwork,
                                   newSwitch,
                                   name=oldconfig['name'],
                                   tags=oldconfig['tags'],
                                   lat=oldconfig['lat'],
                                   lng=oldconfig['lng'],
                                   address=oldconfig['address'],
                                   move='true')
            if result == None:
                message = Markup(
                    'Switch with serial <strong>{}</strong> successfully added to Network: <strong>{}</strong>'
                    .format(newSwitch, netname['name']))
                #CLONE L2 PORT CONFIGS
                if '24' in oldconfig['model']:
                    numports = 30
                elif '48' in oldconfig['model']:
                    numports = 54
                elif '16' in oldconfig['model']:
                    numports = 22
                elif '32' in oldconfig['model']:
                    numports = 38
                for port in range(1, numports):
                    config = merakiapi.getswitchportdetail(
                        apikey, oldSwitch, port)
                    print(config)
                    # Clone corresponding new switch
                    # Tags needed to be input as a list
                    #if config['tags'] is not '':
                    #    tags = config['tags'].split()
                    #else:
                    tags = []

                    # Access type port
                    if config['type'] == 'access':
                        merakiapi.updateswitchport(
                            apikey,
                            newSwitch,
                            port,
                            name=config['name'],
                            tags=tags,
                            enabled=config['enabled'],
                            porttype=config['type'],
                            vlan=config['vlan'],
                            voicevlan=config['voiceVlan'],
                            poe='true',
                            isolation=config['isolationEnabled'],
                            rstp=config['rstpEnabled'],
                            stpguard=config['stpGuard'],
                            accesspolicynum=config['accessPolicyNumber'])

# Trunk type port
                    elif config['type'] == 'trunk':
                        merakiapi.updateswitchport(
                            apikey,
                            newSwitch,
                            port,
                            name=config['name'],
                            tags=tags,
                            enabled=config['enabled'],
                            porttype=config['type'],
                            vlan=config['vlan'],
                            allowedvlans=config['allowedVlans'],
                            poe='true',
                            isolation=config['isolationEnabled'],
                            rstp=config['rstpEnabled'],
                            stpguard=config['stpGuard'])
            #404 MESSAGE FOR INVALID SERIAL IS BLANK, POPULATE ERROR MESSAGE MANUALLY
            elif result == 'noserial':
                message = Markup(
                    'Invalid serial <strong>{}</strong>'.format(serial))
            else:
                message = result
            #REMOVE OLD SWITCH FROM NETWORK
            merakiapi.removedevfromnet(apikey, postNetwork, oldSwitch)

        if oldAP is not '':
            oldconfig = merakiapi.getdevicedetail(apikey, postNetwork, oldAP)
            merakiapi.updatedevice(apikey,
                                   postNetwork,
                                   newAP,
                                   name=oldconfig['name'],
                                   tags=oldconfig['tags'],
                                   lat=oldconfig['lat'],
                                   lng=oldconfig['lng'],
                                   address=oldconfig['address'],
                                   move='true')
            result = merakiapi.removedevfromnet(apikey, postNetwork, oldAP)
            if result == None:
                message = Markup(
                    'AP with serial <strong>{}</strong> successfully deleted from Network: <strong>{}</strong>'
                    .format(oldMX, netname['name']))
            merakiapi.claim(apikey, organizationid, serial=newAP)
            result = merakiapi.adddevtonet(apikey, postNetwork, newAP)
            if result == None:
                message = Markup(
                    'AP with serial <strong>{}</strong> successfully added to Network: <strong>{}</strong>'
                    .format(newMX, netname['name']))

        #SEND MESSAGE TO SUBMIT PAGE
        flash(message)
        return redirect('/submit')
    return render_template('replace.html',
                           title='Meraki Device Provisioning',
                           form=form)
Пример #3
0
def provisionNetwork():
    form = CreateProvisionForm()
    if form.validate_on_submit():
        message = []
        postSerials = []
        postNames = []

        postNetwork = form.networkTextField.data
        #print(postNetwork)

        postTemplate = form.templateField.data

        #BUILD ARRAY OF SERIAL NUMBERS FROM FORM
        postSerials.append(form.serialField1.data)
        postSerials.append(form.serialField2.data)
        postSerials.append(form.serialField3.data)
        postSerials.append(form.serialField4.data)
        postSerials.append(form.serialField5.data)
        postSerials.append(form.serialField6.data)
        postSerials.append(form.serialField7.data)
        postSerials.append(form.serialField8.data)
        postSerials = [element.upper() for element in postSerials]
        postSerials

        postNames.append(form.nameField1.data)
        postNames.append(form.nameField2.data)
        postNames.append(form.nameField3.data)
        postNames.append(form.nameField4.data)
        postNames.append(form.nameField5.data)
        postNames.append(form.nameField6.data)
        postNames.append(form.nameField7.data)
        postNames.append(form.nameField8.data)

        #CREATE NETWORK AND BIND TO TEMPLATE
        result = merakiapi.addnetwork(apikey, organizationid, postNetwork,
                                      "appliance switch wireless", "",
                                      "America/Los_Angeles")

        #GET NEW NETWORK ID
        networks = merakiapi.getnetworklist(apikey, organizationid)
        for network in networks:
            if network['name'] == postNetwork:
                newnetwork = network['id']
                break
        message = Markup(
            "New Network created: <strong>{}</strong> with ID: <strong>{}</strong>"
            .format(postNetwork, newnetwork))
        flash(message)

        #BIND TO TEMPLATE
        if form.templateField.data is not "":
            bindresult = merakiapi.bindtotemplate(apikey, newnetwork,
                                                  postTemplate)
            message = Markup(
                "Network: <strong>{}</strong> bound to Template: <strong>{}</strong>"
                .format(postNetwork, postTemplate))
            flash(message)

        #ADD SERIALS TO NETWORK
        for i, serial in enumerate(postSerials):
            #SKIP EMPTY SERIAL NUMBER TEXT BOXES
            if serial is '':
                continue
            #EASTER EGG
            elif "ILOVEMERAKI" in serial:
                message = Markup("<img src='/static/meraki.png' />")
            else:
                result = merakiapi.adddevtonet(apikey, newnetwork, serial)
                if result == None:
                    #SET ADDRESS AND NAME
                    merakiapi.updatedevice(apikey,
                                           newnetwork,
                                           serial,
                                           name=postNames[i],
                                           address=form.addressField.data,
                                           move='true')
                    #API RETURNS EMPTY ON SUCCESS, POPULATE SUCCESS MESSAGE MANUALLY
                    netname = merakiapi.getnetworkdetail(apikey, newnetwork)
                    message = Markup(
                        'Device with serial <strong>{}</strong> successfully added to Network: <strong>{}</strong>'
                        .format(serial, netname['name']))
                #404 MESSAGE FOR INVALID SERIAL IS BLANK, POPULATE ERROR MESSAGE MANUALLY
                elif result == 'noserial':
                    message = Markup(
                        'Invalid serial <strong>{}</strong>'.format(serial))
                else:
                    message = result
            #SEND MESSAGE TO SUBMIT PAGE
            flash(message)
        return redirect('/submit')
    return render_template('indextemplate.html',
                           title='Meraki Device Provisioning',
                           form=form)