Juniper/py-jnpr-wlc

Name: py-jnpr-wlc

Owner: Juniper Networks

Description: EXPERIMENTAL: Python library for Juniper Wireless Lan Controller (WLC) product

Created: 2013-09-26 20:19:11.0

Updated: 2017-02-13 05:12:01.0

Pushed: 2015-10-07 21:56:07.0

Homepage:

Size: 646

Language: Python

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

ABOUT

Python module for Juniper Wireless LAN Controller (WLC)

STATUS: Experimental, under active development.
The WLC XML API is not public, but can be made available to existing customers.

OVERVIEW

The Juniper Wireless LAN Controller products implement a comprehensive XML-RPC API over HTTP/s. This module provides a metaprogramming set of capabilities to fully utilize the API in any easy and consumable manner. To proficiently use this API, you should be familiar with XML and XPath expressions.

This module uses lxml for XML processing. This module uses Jinja2 for template processing.

This module is developed and tested with Python 2.7. If you are using another version and it works, please notify the maintainer. If you are using another version and it does not work, please open an issue.

EXAMPLE
 jnpr.wlc import WirelessLanController as WLC

= WLC( user='jeremy', host='192.168.10.27', password='logmeIn' )

th/login to WLC device
open()

---------------------------------------------------
t all VLANS
---------------------------------------------------
trieve the current VLANs and display them.  The RPC
vocation here is metaprogramming.  The `rpc` object
traprograms whatever comes after.  The response is 
 lxml Element

s = wlc.rpc.get_vlan()

vlan in vlans.xpath('VLAN'):
num = vlan.attrib['number']
name = vlan.attrib['name']
int "VLAN(%s) is named: %s" % (v_num, v_name)

---------------------------------------------------
t only one VLAN
---------------------------------------------------

 = wlc.rpc.get_vlan( name="VoIP" )
 = resp.find('VLAN')
t "VoIP vlan number is %s" % vlan.attrib['number']


eanup/close
close()

For more examples, see the example directory.

“FACTS”

When you make a call to open() the method will retrieve bits of data about the WLC and store them into a dictionary called facts. You can access this data as property, as illustrated:

pprint( wlc.facts )
to-config': 'NO',
ckup-config-location': '',
oted-config-location': 'configuration',
oted-image-location': 'boot0:WC075106.8XX',
oted-version': '7.5.1.6.0',
otflags': '',
uster-active-seed': 'NO',
nsole-timeout': '0',
mainsecurity': 'NONE',
ablepw': 'b5bacf1baa8e028e858c134e3fd2d306cc3b',
ps': 'NO',
le-timeout': '3600',
-addr': '66.129.246.74',
caddress': '78:19:F7:70:96:76',
del': 'WLC880R',
-secret': '',
me': 'WLC880R',
xt-config-location': 'configuration',
xt-image-location': 'boot0:WC075106.8XX',
xt-image-version': '7.5.1.6.0',
jectid': '1.3.6.1.4.1.14525.3.3.1',
atform': '802',
rialnumber': 'JJ0211401124',
nnelsecurity': 'NONE',
pe': 'DP',
time': '0'}


wlc.facts['serialnumber']
211401124'

wlc.facts['macaddress']
19:F7:70:96:76'
RPC METAPROGRAMMING

You can issue WLC XML RPCs in a few different ways. These methods use Python metaprogramming techniques.
Metapgramming means the this module automatically generates the XML RPC commands on-the-fly without having to maintain a static set of function bound to a specifc WLC release of code.

For details on issuing RPCs and metaprogramming, refer to the embbedded links.

“EZ” MICROFRAMEWORK

Each WLC object has an ez attribute that can be used to attach helper functions or packages. The purpose of these functions is provide natural Python language bindings around the WLC XML API so that the results are not XML, but native types, like dictionaries.

There are a few builtin helper functions that are autoinstalled as part of every WLC object. For details, refer to the helpers directory.

Here is an example using the builin helper to save the configuration:

ez.save_config()

For more details on using the “EZ” framework, see here.

LOGGING

Each WLC instance can support transaction logging. You can use this facility by assigning an open file to the WLC instance, for example:

logfile = open(r'/var/tmp/'+wlc.hostname+'.xml', "w+")

The contents of the log file are the XML commands and assocaited responses. Each transaction will flush the results to the file. You are required to perform any file close/cleanup.

TEMPLATING

This module supports using Jinja2 templates in conjuction with the creation of complex RPCs. Template files can be located in either the program's current working directory, or template directory for this module. A configurable search-path option will be added as an enhancement.

There are a few options for using templates. These are described in detail here.

The following uses a template file vlan_set_ports.xml that happens to be stored in the module template directory.

_vars = dict(
mber = 100,
rts = [
dict(port=2, tag=50),
dict(port=3)



= wlc.RpcMaker('set', Template='vlan_set_ports', TemplateVars=vlan_vars )

t "Settting ports on VLAN ..."
= rpc()
EXCEPTIONS

This module provides an RpcError exception, which inherits from StandardError. This exception will be raised if the RPC response is an ERROR-RESP. The RpcError encapsulates both the RPC command and RPC response attributes; both stored as lxml Element. For example usage, see this.

DEPENDENCIES
LICENSE

Apache 2.0

CONTRIBUTORS

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.