Raritan PX2/PX3 JSON-RPC API
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Python JSON-RPC Client Binding

Examples

Getting device information:

Code:

1 from raritan import rpc
2 from raritan.rpc import pdumodel
3 
4 agent = rpc.Agent("https", "my-px.example.com", "admin", "raritan")
5 pdu = pdumodel.Pdu("/model/pdu/0", agent)
6 metadata = pdu.getMetaData()
7 print metadata

Output produced if there is no error:

1 pdumodel.Pdu.MetaData:
2  * nameplate = pdumodel.Nameplate:
3  * manufacturer = Raritan
4  * model = PX2-2630U-A1
5  * partNumber =
6  * serialNumber = PKE0954001
7  * rating = pdumodel.Nameplate.Rating:
8  * voltage = 360-415V
9  * current = 24A
10  * frequency = 50/60Hz
11  * power = 15.0-17.3kVA
12  * imageFileURL =
13  * ctrlBoardSerial = PKI9050003
14  * hwRevision = 0x64
15  * fwRevision = 3.0.2.5-41550
16  * macAddress = 00:0d:5d:07:87:5c
17  * hasSwitchableOutlets = True
18  * hasMeteredOutlets = False
19  * hasLatchingOutletRelays = False
20  * isInlineMeter = False

Switching the first outlet:

1 from raritan import rpc
2 from raritan.rpc import pdumodel
3 
4 agent = rpc.Agent("https", "my-px.example.com", "admin", "raritan")
5 pdu = pdumodel.Pdu("/model/pdu/0", agent)
6 outlets = pdu.getOutlets()
7 outlets[0].setPowerState(pdumodel.Outlet.PowerState.PS_OFF)

Get current reading from first outlet:

1 from raritan import rpc
2 from raritan.rpc import pdumodel
3 
4 agent = rpc.Agent("https", "my-px.example.com", "admin", "raritan")
5 pdu = pdumodel.Pdu("/model/pdu/0", agent)
6 outlets = pdu.getOutlets()
7 outlets[0].getSensors().current.getReading().value

Configuring the SNMP agent:

Code:

1 from raritan import rpc
2 from raritan.rpc import devsettings
3 
4 agent = rpc.Agent("https", "my-device.example.com", "admin", "raritan")
5 snmp_proxy = devsettings.Snmp("/snmp", agent)
6 config = snmp_proxy.getConfiguration()
7 config.v2enable = True
8 config.readComm = "public"
9 config.writeComm = "private"
10 snmp_proxy.setConfiguration(config)

Note that the URIs given to the object proxies (such as "/model/pdu/0") are well-known references to static (i.e. they are always there) object instances implemented by the device. All well-known references along with their interface are documented in file Well-Known-URIs.txt which comes along with the IDL files.

IDL-to-Python Mapping

Modules and Python Packages

All supporting and generated symbols are placed underneath common package raritan.rpc. IDL Modules are mapped to corresponding Python package within this common package. Import of all definitions within a module can be done via (for instance):

1 from raritan.rpc.pdumodel import *

Interfaces and Methods

IDL interfaces are mapped to Python classes which are defined in the init.py file of their according package. The python class implements a proxy that delegates calls to its IDL defined methods to the actual object implementation across the network.

The signature of the methods is slightly altered compared to the IDL signature. All in arguments are expected as arguments to the Python method in the same order as they appear in IDL. The return argument, if any, and all out arguments are returned as a Python tuple in the same order they appear in IDL. That means if there is a return argument defined it will appear as first element in the tuple, otherwise the first out argument is the first element in the tuple. If the IDL method has either only a return value or a single out argument, a single value is returned by the Python method without an embracing tuple.

Structures

IDL structures are mapped to Python classes which are, like all other definitions, defined in the init.py file of their according package. The class has all elements as defined in IDL. In addition there is a constructor with a signature that initializes all elements.

The following is an example for enabling a threshold in a sensor:

1 from raritan import rpc
2 from raritan.rpc import pdumodel, sensors
3 
4 agent = rpc.Agent("https", "my-px.example.com", "admin", "raritan")
5 outlet = pdumodel.Outlet("/model/pdu/0/outlet/0", agent)
6 currentsens = outlet.getSensors().current
7 thresholds = currentsens.getThresholds()
8 thresholds.lowerWarning = 1.0
9 thresholds.lowerWarningActive = true
10 currentsens.setThresholds(thresholds)

Enumerations

An IDL enumeration is mapped to a concrete class which has an element for each enumerated value. That means access to a particular enumerated value is accomplished by naming the enumeration type and the enumerated value. Consider the following example for switching an outlet:

1 # pdumodel has been imported and outlet has been initialized before, see above
2 
3 outlet.setPowerState(pdumodel.Outlet.PowerState.PS_OFF)

PowerState is an enumerated type defined in the Outlet interface. PS_OFF is a specific enumerated value defined in the PowerState enumeration.

Vectors

IDL vectors are mapped to Python lists. Consider the following example for looping over the list of all outlets of a Pdu and printing out informative data:

1 from raritan import rpc
2 from raritan.rpc import pdumodel
3 
4 agent = rpc.Agent("https", "my-px.example.com", "admin", "raritan")
5 pdu = pdumodel.Pdu("/model/pdu/0", agent)
6 outlets = pdu.getOutlets()
7 for outlet in outlets:
8  print outlet.getMetaData()

Maps

IDL maps are mapped to Python dictionaries. Consider the following example for looping over all observed servers of the servermon.ServerMonitor and retrieving their entry id mapped to server entry structure which contains information and status:

1 from raritan import rpc
2 from raritan.rpc import servermon
3 
4 agent = rpc.Agent("https", "my-device.example.com", "admin", "raritan")
5 srvmonitor = servermon.ServerMonitor("/servermon", agent);
6 servers = srvmonitor.listServers()
7 for srvid, srventry in servers.iteritems():
8  print srvid, srventry.settings.host, srventry.status.reachable

Exceptions

Execptional errors conditions may occur because of communication problems or encoding/decoding problems, or because of system errors that occur on the server while processing a request. Reporting of such error conditions is not part a regular IDL signature but part of the JSON-RPC protocol.

The Python implementation of the JSON-RPC protocol maps these error condtions to exception:

Consider the following example for catching a communication error:

1 from raritan import rpc
2 from raritan.rpc import emdmodel
3 
4 try:
5  agent = rpc.Agent("https", "my-emx.example.com", "admin", "raritan")
6  emx = emdmodel.Emd("/model/emd", agent)
7  print "Getting EMD MetaData...",
8  metadata = emx.getMetaData()
9  print "OK ->"
10  print metadata
11 except rpc.HttpException, e:
12  print "ERROR:", str(e)