import demowlcutils from demowlcutils import ppxml, WLC_login from pprint import pprint as pp wlc = WLC_login() ### just let the user play around with the wlc object ### from the python interpreter wlc.logfile = open(r'/var/tmp/' + wlc.hostname + '.txt', "w+")
import demowlcutils from demowlcutils import ppxml, WLC_login from pprint import pprint as pp import jinja2 from lxml import etree from lxml.builder import E wlc = WLC_login() def show_ap( wlc, *vargs, **kvargs ): rsp = wlc.rpc.get_stat_ap_radio_status() ap_list = rsp.findall('.//DAP') data = {} for ap in ap_list: data[ap.get('apnum')] = {} data[ap.get('apnum')].update(ap.attrib) return data def boot_ap( wlc, *vargs, **kvargs ): # XXX - add a filter for booting AP by name or serial rpc = wlc.RpcMaker('act') rpc.data = E('BOOT', E('BOOT-DAP', E('DAP-REF'))) if 'apnum' in kvargs: dapref = rpc.data.find('.//DAP-REF')
import demowlcutils from demowlcutils import ppxml, WLC_login from pprint import pprint as pp wlc = WLC_login() # just display the dict of the values si = wlc.ez.facts() print "System Name: %s" % si['name'] print "System IP Address: %s" % si['ip-addr'] print "System MAC: %s" % si['macaddress'] print "System Serial Number: %s" % si['serialnumber'] print "S/W Version: %s" % si['booted-version'] print "H/W Model: %s" % si['model'] print "H/W Version: %s" % si['platform'] #print "DUMPNIG ALL DATA": #pp(si)
import demowlcutils from demowlcutils import ppxml, WLC_login from pprint import pprint as pp import jinja2 from lxml import etree wlc = WLC_login() def show_vlans( wlc, *vargs, **kvargs ): if 'name' in kvargs: vlan_xml = wlc.rpc.get_vlan( name = kvargs['name']) else: vlan_xml = wlc.rpc.get_vlan() return [ dict(vlan.attrib) for vlan in vlan_xml.xpath('VLAN')] ##### ------------------------------------------------------------------------- ##### MAIN BLOCK ##### ------------------------------------------------------------------------- j2_ldr = jinja2.FileSystemLoader( searchpath='.' ) j2_env = jinja2.Environment( loader=j2_ldr ) def j2_to_xml( filename, env_vars ): """ render jinja2 template into XML """ # build the j2 template template = j2_env.get_template( filename )
import demowlcutils from demowlcutils import ppxml, WLC_login from pprint import pprint as pp wlc = WLC_login() ##### ------------------------------------------------------------------------- #### add the 'system_services' as an "ez" helper function ##### ------------------------------------------------------------------------- def system_services( wlc, *vargs, **kvargs ): """ create a single dictionary containing information about system services: sshd, httpd, tftpd, and telnetd. for each of these services we will run the associated GET command, and extract the XML attributes into the single/returned dictionary """ run_list = { 'sshd': wlc.rpc.get_sshd, 'httpd': wlc.rpc.get_httpd, 'tftpd': wlc.rpc.get_tftpd, 'telnetd': wlc.rpc.get_telnetd } ret_data = {} # empty dictionary for svc, rpc in run_list.items(): rsp = rpc() # execute the RPC
import demowlcutils from demowlcutils import ppxml, WLC_login from pprint import pprint as pp from lxml.builder import E from jnpr.wlc import WirelessLanController as WLC from client_helper import find_client, clear_client, get_clients wlc = WLC_login() # add client routines to the WLC "ez" section. # XXX - this seems wrong? shouldn't this get loaded automatically? wlc.ez( helper=find_client) wlc.ez( helper=clear_client) wlc.ez( helper=get_clients) # mac address for testing, should be a current session #mac = '10:40:f3:e6:fc:26' #mac = '88:53:95:2a:d4:37' mac = 'bc:67:78:08:25:bb' ##### ------------------------------------------------------------------------- #### run the find client routine, searching for active sessions by mac, ip #### and name. This command does not have an equivalent CLI command. ##### ------------------------------------------------------------------------- # call the service by mac print "Finding user session by mac..." client = wlc.ez.find_client( macaddress = mac )
import demowlcutils from demowlcutils import ppxml, WLC_login wlc = WLC_login() # ----------------------------------------------------------------------------- vlan_vars = {'name': 'Jeremy', 'number': '100'} # use a template and render the vars immediately: rpc = wlc.RpcMaker('SET', Template='vlan_create', TemplateVars=vlan_vars) # alternatively you can invoke the render method if you don't provide # TemplateVars in the constructor, for example: # >>> # vlan_vars['number'] = '200' # rpc.render( vlan_vars ) print "Creating VLAN %s ..." % vlan_vars['name'] # execute the RPC and return the result rsp = rpc()
import demowlcutils from demowlcutils import ppxml, WLC_login from pprint import pprint as pp from lxml.builder import E from lxml import etree from jinja2 import Template wlc = WLC_login() rpc = wlc.RpcMaker('set') # for this example we'll set an example site location of 'SVL' for all converted APs and # assume that we are putting all site radios into the 'default' radio profile site = 'SVL' radioprofile = 'default' # create a jinja2 template for a new AP dap_j2 = Template(u""" <DAP apnum="{{ apnum }}" fingerprint="{{ fp }}" model="{{ model }}" name="{{ name }}" port="{{ port }}" serial-id="{{ serial }}" type="NG"> <AP-BOOTCONFIG boot-image=""/> <AP-RADIO-TABLE> <AP-RADIO antenna-mode="DUAL-BAND-3SS" antennatype="INTERNAL" auto-config="YES" channel="6" designation="INDOOR" enable="YES" external-antennas="0" force-rebalance="NO" load-balance-enable="YES" load-balance-group="" max-tuned-power="default" min-tx-rate="" slot="1" tx-power="21" type="NG"> <RADIO-PROFILE-REF name="{{ radio1profile }}"/> </AP-RADIO> <AP-RADIO antenna-mode="DUAL-BAND-3SS" antennatype="INTERNAL" auto-config="YES" channel="36" designation="INDOOR" enable="YES" external-antennas="0" force-rebalance="NO" load-balance-enable="YES" load-balance-group="" max-tuned-power="default" min-tx-rate="" slot="2" tx-power="11" type="NA">
import demowlcutils from demowlcutils import ppxml, WLC_login from pprint import pprint as pp wlc = WLC_login() ##### ------------------------------------------------------------------------- #### add the 'system_services' as an "ez" helper function ##### ------------------------------------------------------------------------- def system_services(wlc, *vargs, **kvargs): """ create a single dictionary containing information about system services: sshd, httpd, tftpd, and telnetd. for each of these services we will run the associated GET command, and extract the XML attributes into the single/returned dictionary """ run_list = { 'sshd': wlc.rpc.get_sshd, 'httpd': wlc.rpc.get_httpd, 'tftpd': wlc.rpc.get_tftpd, 'telnetd': wlc.rpc.get_telnetd } ret_data = {} # empty dictionary for svc, rpc in run_list.items(): rsp = rpc() # execute the RPC
import demowlcutils from demowlcutils import ppxml, WLC_login from pprint import pprint as pp wlc = WLC_login() # setup an RPC to edit the DAP-TABLE. We set the :data: attribute rather than the # :target: attribute in this case as we are going to be making appends # (child elements) to :data. Using *new* feature that checks the type of # the :data: on setattr. If it's a string, then the RpcMaker will create the # XML element; thus you don't need to import lxml.buildier anymore rpc = wlc.RpcMaker('set') rpc.data = 'DAP-TABLE' # retrieve the DAP template dap_template = wlc.Template('dap') # assume that we are putting all site radios into the 'default' radio profile radioprofile = 'default' # create a list of AP data dictionaries; we're going to feed these through the # template and append into the RPC. ap_data = [ dict( radio1profile=radioprofile, radio2profile=radioprofile, serial='SN12345',
import demowlcutils from demowlcutils import ppxml, WLC_login from pprint import pprint as pp wlc = WLC_login() ### just let the user play around with the wlc object ### from the python interpreter wlc.logfile = open(r'/var/tmp/'+wlc.hostname+'.txt', "w+")
import demowlcutils from demowlcutils import ppxml, WLC_login from pprint import pprint as pp from lxml.builder import E from jnpr.wlc import WirelessLanController as WLC from client_helper import find_client, clear_client, get_clients wlc = WLC_login() # add client routines to the WLC "ez" section. # XXX - this seems wrong? shouldn't this get loaded automatically? wlc.ez(helper=find_client) wlc.ez(helper=clear_client) wlc.ez(helper=get_clients) # mac address for testing, should be a current session #mac = '10:40:f3:e6:fc:26' #mac = '88:53:95:2a:d4:37' mac = 'bc:67:78:08:25:bb' ##### ------------------------------------------------------------------------- #### run the find client routine, searching for active sessions by mac, ip #### and name. This command does not have an equivalent CLI command. ##### ------------------------------------------------------------------------- # call the service by mac print "Finding user session by mac..." client = wlc.ez.find_client(macaddress=mac) # show the info: pp(client)
import demowlcutils from demowlcutils import ppxml, WLC_login from pprint import pprint as pp wlc = WLC_login() vlan_vars = dict(number=100, ports=[dict(port=2, tag=50), dict(port=3)]) rpc = wlc.RpcMaker('set', Template='vlan_set_ports', TemplateVars=vlan_vars) print "Settting ports on VLAN ..." # rsp = rpc()
import demowlcutils from demowlcutils import ppxml, WLC_login from pprint import pprint as pp import jinja2 from lxml import etree from lxml.builder import E wlc = WLC_login() def show_ap(wlc, *vargs, **kvargs): rsp = wlc.rpc.get_stat_ap_radio_status() ap_list = rsp.findall('.//DAP') data = {} for ap in ap_list: data[ap.get('apnum')] = {} data[ap.get('apnum')].update(ap.attrib) return data def boot_ap(wlc, *vargs, **kvargs): # XXX - add a filter for booting AP by name or serial rpc = wlc.RpcMaker('act') rpc.data = E('BOOT', E('BOOT-DAP', E('DAP-REF'))) if 'apnum' in kvargs: dapref = rpc.data.find('.//DAP-REF') dapref.set('dap-id', kvargs['apnum'])