} ret_data = {} # empty dictionary for svc, rpc in run_list.items(): rsp = rpc() # execute the RPC ret_data[svc] = dict(rsp[0].attrib) # copy the attributes into a dictionary return ret_data ##### ------------------------------------------------------------------------- ##### MAIN BLOCK ##### ------------------------------------------------------------------------- # add this new routine to the WLC "ez" section. wlc.ez( helper=system_services ) # now call the service print "Retrieving System Services ..." si = wlc.ez.system_services() # now show the info: print "System Services:" pp(si) # and you could do things like: # >>> [svc for svc in si.keys() if si[svc]['enabled'] == "YES"] # ['httpd', 'sshd', 'telnetd'] # >>> [svc for svc in si.keys() if si[svc]['enabled'] != "YES"] # ['tftpd']
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']) r = rpc() else: raise ValueError("You must provide an AP number") return True # bind the helper to the WLC wlc.ez( helper=show_ap ) wlc.ez( helper=boot_ap )
# now merge the template with the vars as_txt = template.render( env_vars ) # now convert the txt to XML return etree.XML( as_txt ) def create_vlan( wlc, *vargs, **kvargs ): vlan_vars = { 'name': kvargs['name'], 'number': kvargs['number'] } rpc = wlc.RpcMaker( trans='SET', target='vlan-table' ) rpc.data = j2_to_xml( 'create-vlan.j2.xml', vlan_vars ) return wlc.rpc( rpc.as_xml ) # bind the helper to the WLC wlc.ez( show_vlans, alias="vinfo") wlc.ez( create_vlan ) vlan_create_list = [ {'name': 'Bob1', 'number': '1001'}, {'name': 'Bob2', 'number': '1002'}, {'name': 'Bob3', 'number': '1003'}, {'name': 'Bob4', 'number': '1004'}, {'name': 'Bob5', 'number': '1005'}, ] # then you could do something like: #>>> for vlan in vlan_create_list: #... wlc.ez.create_vlan( **vlan )
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 )
ret_data = {} # empty dictionary for svc, rpc in run_list.items(): rsp = rpc() # execute the RPC ret_data[svc] = dict( rsp[0].attrib) # copy the attributes into a dictionary return ret_data ##### ------------------------------------------------------------------------- ##### MAIN BLOCK ##### ------------------------------------------------------------------------- # add this new routine to the WLC "ez" section. wlc.ez(helper=system_services) # now call the service print "Retrieving System Services ..." si = wlc.ez.system_services() # now show the info: print "System Services:" pp(si) # and you could do things like: # >>> [svc for svc in si.keys() if si[svc]['enabled'] == "YES"] # ['httpd', 'sshd', 'telnetd'] # >>> [svc for svc in si.keys() if si[svc]['enabled'] != "YES"] # ['tftpd']
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)
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']) r = rpc() else: raise ValueError("You must provide an AP number") return True # bind the helper to the WLC wlc.ez(helper=show_ap) wlc.ez(helper=boot_ap)