def getPickSwitchContent(): rtn = '''<div class="dropdown"> <button class="btn btn-primary dropdown-toggle btn-block" type="button" data-toggle="dropdown">Choose a switch <span class="caret"></span></button> <ul class="dropdown-menu">''' switches = switchconfig.get_switches() for switch in switches["switches"]: rtn += "<li><a href='/pickports?ip=%s'>%s</a></li>" % (switch['ip_addr'], switch['hostname']) rtn += '</ul></div>' return rtn
def getPickSwitchContent(): rtn = '''<div class="dropdown"> <button class="btn btn-primary dropdown-toggle btn-block" type="button" data-toggle="dropdown">Choose a switch <span class="caret"></span></button> <ul class="dropdown-menu">''' switches = switchconfig.get_switches() for switch in switches["switches"]: rtn += "<li><a href='/pickports?ip=%s'>%s</a></li>" % ( switch['ip_addr'], switch['hostname']) rtn += '</ul></div>' return rtn
# configurator. # Suggested Improvements: # * Allow user to choose switch by model, hostname or ip_addr # * Allow users to choose switchports to be configured by number # * Check all user input to be sure it's in the correct format # * Clean up the format of output being printed to CLI # import switchconfig from switchconfig import * import json print "Thank you for using the configurator." print "Allow one moment while I gather the switch availability.\n" switches = switchconfig.get_switches() print json.dumps(switches, indent = 4) print "\nWhat switch would you like to configure by hostname?" switch = raw_input(">") print "\nLet me gather port and vlan information for switch: " + switch + ".\n" ip_addr = '' for each in switches['switches']: if each['hostname'] == switch: ip_addr = each['ip_addr'] intf = switchconfig.get_intfs(ip_addr) vlan = switchconfig.get_vlans(ip_addr) print 'Interfaces for %s:' % ip_addr