def find_client(wlc, *vargs, **kvargs): """ create a single dictionary containing information about specific stations. Filter can be username, mac or ip. sessions on a WLC can be found by any combination of mac, ip or username, this fn only uses the most specific attr. """ if 'macaddress' in kvargs: rsp = wlc.rpc.act_findclient(macaddress=kvargs['macaddress']) elif 'ipaddress' in kvargs: rsp = wlc.rpc.act_findclient(ipaddress=kvargs['ipaddress']) elif 'username' in kvargs: rsp = wlc.rpc.act_findclient(username=kvargs['username']) else: raise ValueError("You must provide a mac, ip or username") ret_data = {} # empty dictionary # It is possible for a find client request to return a session which # is not on the same WLC that we initiated the request to. The WLC # will use the Mobility Domain plumbing to locate sessions on other # WLCs. This fn will attempt to connect to the alternate WLC to get # session stats. for session in rsp.findall('.//FINDCLIENT-ENTRY'): dp = session.get('dp-system-ip') sessionid = session.get('session-id') if wlc.facts['ip-addr'] != session.get('dp-system-ip'): print( '### session on different WLC, connect to new WLC using existing credentials ###' ) altwlc = WLC(user=wlc._user, host=dp, password=wlc._password) altwlc.open() rpc = altwlc.RpcMaker('get-stat') else: rpc = wlc.RpcMaker('get-stat') rpc.data = E('USER-SESSION-STATUS') rpc.data.set('session-id', sessionid) sessstats = rpc() sessstat = sessstats.find('.//USER-SESSION-STATUS') locstat = sessstats.find('.//USER-LOCATION-MEMBER') ret_data[sessstat.get('mac-addr')] = dict( sessstat.attrib) # copy the attributes into a dictionary ret_data[sessstat.get('mac-addr')].update(locstat.attrib) return ret_data
import demowlcutils from demowlcutils import ppxml, WLC_login from pprint import pprint as pp from jnpr.wlc import WirelessLanController as WLC wlc = WLC(host='a', user='******', password='******') r = wlc.RpcMaker( target='vlan', name='Jeremy') # you can access the following attributes, refer to the jnpr.wlc.builder # file for more details # r.cmd # r.target # r.args