1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.14"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Raritan PX2/PX3 JSON-RPC API: Python JSON-RPC Client Binding</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">Raritan PX2/PX3 JSON-RPC API
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.14 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">Python JSON-RPC Client Binding </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h2>Pre-Requirements</h2>
<h3>Linux</h3>
<p>Standard Python 2 or Python 3 installations already contain all necessary packages.</p>
<h3>Windows</h3>
<ul>
<li>download and install the latest Python 2 or Python 3 from <a href="https://www.python.org/downloads/">https://www.python.org/downloads/</a></li>
<li>the installation will associated the file extension *.py with python, so you can start python files directly from the command line or the file manager</li>
</ul>
<h2>Note on SSL Certificate Verification</h2>
<p>All Raritan devices enforce use of HTTPS when accessing the JSON-RPC service. By default, programs written with this client binding try to verify the authenticity of the server when connecting. This requires a valid SSL certificate to be installed on the device. When trying to connect to a device without a valid SSL certificate the client program will terminate with an error message.</p>
<p>It is possible to disable the SSL certificate verification by adding a "disable_certificate_verification" option to the arguments of the rpc.Agent instance:</p>
<p>Code: </p><div class="fragment"><div class="line">agent = rpc.Agent(<span class="stringliteral">"https"</span>, <span class="stringliteral">"my-px.example.com"</span>, <span class="stringliteral">"admin"</span>, <span class="stringliteral">"raritan"</span>, disable_certificate_verification = <span class="keyword">True</span>)</div></div><!-- fragment --><h2>Timeout for IDL methods</h2>
<p>Per default, there is no time limit for the IDL method calls configured and so the function calls might not return if the target device is not available.</p>
<p>If necessary, a timeout in seconds can be provided by adding a "timeout" option to the arguments of the rpc.Agent instance.</p>
<p>Code: </p><div class="fragment"><div class="line">agent = rpc.Agent(<span class="stringliteral">"https"</span>, <span class="stringliteral">"my-px.example.com"</span>, <span class="stringliteral">"admin"</span>, <span class="stringliteral">"raritan"</span>, timeout = 5)</div></div><!-- fragment --> <h2>Examples</h2>
<h3>Getting device information:</h3>
<p>Code: </p><div class="fragment"><div class="line"><span class="keyword">from</span> raritan <span class="keyword">import</span> rpc</div><div class="line"><span class="keyword">from</span> raritan.rpc <span class="keyword">import</span> pdumodel</div><div class="line"></div><div class="line">agent = rpc.Agent(<span class="stringliteral">"https"</span>, <span class="stringliteral">"my-px.example.com"</span>, <span class="stringliteral">"admin"</span>, <span class="stringliteral">"raritan"</span>)</div><div class="line">pdu = pdumodel.Pdu(<span class="stringliteral">"/model/pdu/0"</span>, agent)</div><div class="line">metadata = pdu.getMetaData()</div><div class="line">print(metadata)</div></div><!-- fragment --><p>Output produced if there is no error: </p><div class="fragment"><div class="line">pdumodel.Pdu.MetaData:</div><div class="line"> * nameplate = pdumodel.Nameplate:</div><div class="line"> * manufacturer = Raritan</div><div class="line"> * model = PX2-2630U-A1</div><div class="line"> * partNumber =</div><div class="line"> * serialNumber = PKE0954001</div><div class="line"> * rating = pdumodel.Nameplate.Rating:</div><div class="line"> * voltage = 360-415V</div><div class="line"> * current = 24A</div><div class="line"> * frequency = 50/60Hz</div><div class="line"> * power = 15.0-17.3kVA</div><div class="line"> * imageFileURL =</div><div class="line"> * ctrlBoardSerial = PKI9050003</div><div class="line"> * hwRevision = 0x64</div><div class="line"> * fwRevision = 3.0.2.5-41550</div><div class="line"> * macAddress = 00:0d:5d:07:87:5c</div><div class="line"> * hasSwitchableOutlets = <span class="keyword">True</span></div><div class="line"> * hasMeteredOutlets = <span class="keyword">False</span></div><div class="line"> * hasLatchingOutletRelays = <span class="keyword">False</span></div><div class="line"> * isInlineMeter = <span class="keyword">False</span></div></div><!-- fragment --><h3>Switching the first outlet:</h3>
<div class="fragment"><div class="line"><span class="keyword">from</span> raritan <span class="keyword">import</span> rpc</div><div class="line"><span class="keyword">from</span> raritan.rpc <span class="keyword">import</span> pdumodel</div><div class="line"></div><div class="line">agent = rpc.Agent(<span class="stringliteral">"https"</span>, <span class="stringliteral">"my-px.example.com"</span>, <span class="stringliteral">"admin"</span>, <span class="stringliteral">"raritan"</span>)</div><div class="line">pdu = pdumodel.Pdu(<span class="stringliteral">"/model/pdu/0"</span>, agent)</div><div class="line">outlets = pdu.getOutlets()</div><div class="line">outlets[0].setPowerState(pdumodel.Outlet.PowerState.PS_OFF)</div></div><!-- fragment --><h3>Get current reading from first outlet:</h3>
<div class="fragment"><div class="line"><span class="keyword">from</span> raritan <span class="keyword">import</span> rpc</div><div class="line"><span class="keyword">from</span> raritan.rpc <span class="keyword">import</span> pdumodel</div><div class="line"></div><div class="line">agent = rpc.Agent(<span class="stringliteral">"https"</span>, <span class="stringliteral">"my-px.example.com"</span>, <span class="stringliteral">"admin"</span>, <span class="stringliteral">"raritan"</span>)</div><div class="line">pdu = pdumodel.Pdu(<span class="stringliteral">"/model/pdu/0"</span>, agent)</div><div class="line">outlets = pdu.getOutlets()</div><div class="line">outlets[0].getSensors().current.getReading().value</div></div><!-- fragment --><h3>Configuring the SNMP agent:</h3>
<p>Code: </p><div class="fragment"><div class="line"><span class="keyword">from</span> raritan <span class="keyword">import</span> rpc</div><div class="line"><span class="keyword">from</span> raritan.rpc <span class="keyword">import</span> devsettings</div><div class="line"></div><div class="line">agent = rpc.Agent(<span class="stringliteral">"https"</span>, <span class="stringliteral">"my-device.example.com"</span>, <span class="stringliteral">"admin"</span>, <span class="stringliteral">"raritan"</span>)</div><div class="line">snmp_proxy = devsettings.Snmp(<span class="stringliteral">"/snmp"</span>, agent)</div><div class="line">config = snmp_proxy.getConfiguration()</div><div class="line">config.v2enable = <span class="keyword">True</span></div><div class="line">config.readComm = <span class="stringliteral">"public"</span></div><div class="line">config.writeComm = <span class="stringliteral">"private"</span></div><div class="line">snmp_proxy.setConfiguration(config)</div></div><!-- fragment --><p>Note that the URIs given to the object proxies (such as <code>"/model/pdu/0"</code>) 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 <a href="Well-Known-URIs.txt">Well-Known-URIs.txt</a> which comes along with the IDL files.</p>
<h2>IDL-to-Python Mapping</h2>
<h3>Modules and Python Packages</h3>
<p>All supporting and generated symbols are placed underneath common package <code>raritan.rpc</code>. 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):</p>
<div class="fragment"><div class="line"><span class="keyword">from</span> raritan.rpc.pdumodel <span class="keyword">import</span> *</div></div><!-- fragment --><h3>Interfaces and Methods</h3>
<p>IDL interfaces are mapped to Python classes which are defined in the <code><b>init</b></code>.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.</p>
<p>The signature of the methods is slightly altered compared to the IDL signature. All <code>in</code> 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 <code>out</code> 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 <code>out</code> 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.</p>
<h3>Structures</h3>
<p>IDL structures are mapped to Python classes which are, like all other definitions, defined in the <code><b>init</b></code>.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.</p>
<p>The following is an example for enabling a threshold in a sensor:</p>
<div class="fragment"><div class="line"><span class="keyword">from</span> raritan <span class="keyword">import</span> rpc</div><div class="line"><span class="keyword">from</span> raritan.rpc <span class="keyword">import</span> pdumodel, sensors</div><div class="line"></div><div class="line">agent = rpc.Agent(<span class="stringliteral">"https"</span>, <span class="stringliteral">"my-px.example.com"</span>, <span class="stringliteral">"admin"</span>, <span class="stringliteral">"raritan"</span>)</div><div class="line">outlet = pdumodel.Outlet(<span class="stringliteral">"/model/pdu/0/outlet/0"</span>, agent)</div><div class="line">currentsens = outlet.getSensors().current</div><div class="line">thresholds = currentsens.getThresholds()</div><div class="line">thresholds.lowerWarning = 1.0</div><div class="line">thresholds.lowerWarningActive = <span class="keyword">True</span></div><div class="line">currentsens.setThresholds(thresholds)</div></div><!-- fragment --><h3>Enumerations</h3>
<p>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:</p>
<div class="fragment"><div class="line"><span class="comment"># pdumodel has been imported and outlet has been initialized before, see above</span></div><div class="line"></div><div class="line">outlet.setPowerState(pdumodel.Outlet.PowerState.PS_OFF)</div></div><!-- fragment --><p><code>PowerState</code> is an enumerated type defined in the <code>Outlet</code> interface. <code>PS_OFF</code> is a specific enumerated value defined in the <code>PowerState</code> enumeration.</p>
<h3>Vectors</h3>
<p>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:</p>
<div class="fragment"><div class="line"><span class="keyword">from</span> raritan <span class="keyword">import</span> rpc</div><div class="line"><span class="keyword">from</span> raritan.rpc <span class="keyword">import</span> pdumodel</div><div class="line"></div><div class="line">agent = rpc.Agent(<span class="stringliteral">"https"</span>, <span class="stringliteral">"my-px.example.com"</span>, <span class="stringliteral">"admin"</span>, <span class="stringliteral">"raritan"</span>)</div><div class="line">pdu = pdumodel.Pdu(<span class="stringliteral">"/model/pdu/0"</span>, agent)</div><div class="line">outlets = pdu.getOutlets()</div><div class="line"><span class="keywordflow">for</span> outlet <span class="keywordflow">in</span> outlets:</div><div class="line"> print(outlet.getMetaData())</div></div><!-- fragment --><h3>Maps</h3>
<p>IDL maps are mapped to Python dictionaries. Consider the following example for looping over all observed servers of the <code>servermon.ServerMonitor</code> and retrieving their entry id mapped to server entry structure which contains information and status:</p>
<div class="fragment"><div class="line"><span class="keyword">from</span> raritan <span class="keyword">import</span> rpc</div><div class="line"><span class="keyword">from</span> raritan.rpc <span class="keyword">import</span> servermon</div><div class="line"></div><div class="line">agent = rpc.Agent(<span class="stringliteral">"https"</span>, <span class="stringliteral">"my-device.example.com"</span>, <span class="stringliteral">"admin"</span>, <span class="stringliteral">"raritan"</span>)</div><div class="line">srvmonitor = servermon.ServerMonitor(<span class="stringliteral">"/servermon"</span>, agent);</div><div class="line">servers = srvmonitor.listServers()</div><div class="line"><span class="keywordflow">for</span> srvid, srventry <span class="keywordflow">in</span> servers.iteritems():</div><div class="line"> print(srvid, srventry.settings.host, srventry.status.reachable)</div></div><!-- fragment --><h3>Exceptions</h3>
<p>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.</p>
<p>The Python implementation of the JSON-RPC protocol maps these error condtions to exception:</p>
<ul>
<li><p class="startli"><code>raritan.rpc.HttpException</code></p>
<p class="startli">This exception is raised in case a communication error occured. Typical examples include an unreachable server or a failed authentication. The exception contains a descriptive text that gives more details on the error condition.</p>
</li>
<li><p class="startli"><code>raritan.rpc.JsonRpcErrorException</code></p>
<p class="startli">This exception is raised in case an error happened on the server side while processing the request. The device might be in an unexpected state. Also there might be a version mismatch between client and server, which means the communication contract between client and server as specified by IDL is broken. The exception contains a descriptive text that gives more details on the error condition.</p>
</li>
<li><p class="startli"><code>raritan.rpc.JsonRpcSyntaxException</code></p>
<p class="startli">This exception is raised in case demarshaling of a JSON message went wrong. This may indicate a version mismatch between client and server. The exception contains a descriptive text that gives more details on the error condition.</p>
</li>
</ul>
<p>Consider the following example for catching a communication error:</p>
<div class="fragment"><div class="line"><span class="keyword">from</span> raritan <span class="keyword">import</span> rpc</div><div class="line"><span class="keyword">from</span> raritan.rpc <span class="keyword">import</span> pdumodel</div><div class="line"></div><div class="line"><span class="keywordflow">try</span>:</div><div class="line"> agent = rpc.Agent(<span class="stringliteral">"https"</span>, <span class="stringliteral">"my-pdu.example.com"</span>, <span class="stringliteral">"admin"</span>, <span class="stringliteral">"raritan"</span>)</div><div class="line"> pdu = pdumodel.Pdu(<span class="stringliteral">"/model/pdu/0"</span>, agent)</div><div class="line"> print(<span class="stringliteral">"Getting PDU MetaData..."</span>)</div><div class="line"> metadata = pdu.getMetaData()</div><div class="line"> print(<span class="stringliteral">"OK ->"</span>)</div><div class="line"> print(metadata)</div><div class="line"><span class="keywordflow">except</span> rpc.HttpException <span class="keyword">as</span> e:</div><div class="line"> print(<span class="stringliteral">"ERROR:"</span>, str(e))</div></div><!-- fragment --><h3>Bulk Requests</h3>
<p>The Bulk RPC interface allows combining multiple JSON-RPC method calls into a single bulk request that can be sent to the server and processed in a single HTTP request. The <code>raritan.rpc.BulkRequestHelper</code> class provides a convenient interface to collect and execute method calls:</p>
<ol type="1">
<li>Create a BulkRequestHelper instance.</li>
<li>Queue one or more method calls with the <code>add_request()</code> method.</li>
<li>Call perform_bulk() to submit the bulk request.</li>
<li>Use clear() to empty the request and response lists before reusing the BulkRequestHelper instance.</li>
</ol>
<p><code>perform_bulk()</code> returns a list containing one entry per queued request. Each entry can be one of the following:</p><ul>
<li><code>None</code> if the called method returns void and has no out parameters.</li>
<li>A single value if the method has exactly one return type or out parameter.</li>
<li>A tuple if the method has more than one return type/out parameter.</li>
<li>An <code>Exception</code> object if the request has failed and the optional <code>raise_subreq_failure</code> argument is False.</li>
</ul>
<p>Example:</p>
<div class="fragment"><div class="line"><span class="keyword">from</span> raritan <span class="keyword">import</span> rpc</div><div class="line"><span class="keyword">from</span> raritan.rpc <span class="keyword">import</span> devsettings</div><div class="line"></div><div class="line">agent = rpc.Agent(<span class="stringliteral">"https"</span>, <span class="stringliteral">"my-pdu.example.com"</span>, <span class="stringliteral">"admin"</span>, <span class="stringliteral">"raritan"</span>)</div><div class="line">snmp_proxy = devsettings.Snmp(<span class="stringliteral">"/snmp"</span>, agent)</div><div class="line">cfg = snmp_proxy.getConfiguration()</div><div class="line">cfg.v2enable = <span class="keyword">True</span></div><div class="line"></div><div class="line">bulk_helper = rpc.BulkRequestHelper(agent)</div><div class="line">bulk_helper.add_request(snmp_proxy.getV3EngineId)</div><div class="line">bulk_helper.add_request(snmp_proxy.setConfiguration, cfg)</div><div class="line"></div><div class="line">responses = bulk_helper.perform_bulk(raise_subreq_failure = <span class="keyword">False</span>)</div><div class="line"></div><div class="line"><span class="keywordflow">if</span> isinstance(responses[0], Exception):</div><div class="line"> print(<span class="stringliteral">"Snmp.getV3EngineId() failed: %s"</span> % (responses[0]))</div><div class="line"><span class="keywordflow">else</span>:</div><div class="line"> print(<span class="stringliteral">"SNMP engine ID: %s"</span> % (responses[0]))</div><div class="line"></div><div class="line"><span class="keywordflow">if</span> isinstance(responses[1], Exception):</div><div class="line"> print(<span class="stringliteral">"Snmp.setConfiguration() failed: %s"</span> % (responses[1]))</div><div class="line"><span class="keywordflow">else</span>:</div><div class="line"> print(<span class="stringliteral">"Result of setConfiguration(): %d"</span> % (responses[1]))</div></div><!-- fragment --><h2>raritan.rpc.Agent Method Reference</h2>
<h3>Constructor: raritan.rpc.Agent(proto, host, user = None, passwd = None, token = None, debug = False, disable_certificate_verification = False, timeout = None)</h3>
<p>Creates a new agent.</p>
<p>Parameters:</p><ul>
<li><b>proto</b> Used protocol (either "https" or "http")</li>
<li><b>host</b> Hostname or IP address of the target PDU</li>
<li><b>user</b> User Name (optional)</li>
<li><b>passwd</b> Password (optional)</li>
<li><b>token</b> Authentication Token (optional)</li>
<li><b>debug</b> Enables debug output (optional, True/False)</li>
<li><b>disable_certificate_verification</b> Disables the Certificate Verification (True/False)</li>
<li><b>timeout</b> Request timeout (optional, timeout in seconds)</li>
</ul>
<p>If both, username/password and token are omitted, it is necessary to call either set_auth_basic() or set_auth_token() before the first request.</p>
<h3>set_auth_basic(user, password)</h3>
<p>This method enables HTTP basic authentication using username and password.</p>
<p>Parameters:</p><ul>
<li><b>user</b> User Name</li>
<li><b>password</b> Password</li>
</ul>
<h3>set_auth_token(token)</h3>
<p>This method enables HTTP authentication using a session token. A session token can be obtained by calling the newSession method of the session.SessionManager interface.</p>
<p>Parameters:</p><ul>
<li><b>token</b> Session Token</li>
</ul>
<h2>Firmware Update</h2>
<p>It is possible to upload and update the device firmware with the Python JSON-RPC. A file can be uploaded as binary through the firmware upload method. The example uses a file within the current working directory.</p>
<p>Example:</p>
<div class="fragment"><div class="line"><span class="keyword">from</span> raritan <span class="keyword">import</span> rpc</div><div class="line"><span class="keyword">from</span> raritan.rpc <span class="keyword">import</span> firmware</div><div class="line"></div><div class="line">agent = rpc.Agent(<span class="stringliteral">"https"</span>, <span class="stringliteral">"my-pdu.example.com"</span>, <span class="stringliteral">"admin"</span>, <span class="stringliteral">"raritan"</span>)</div><div class="line">firmware_proxy = firmware.Firmware(<span class="stringliteral">"/firmware"</span>, agent)</div><div class="line"></div><div class="line"><span class="comment"># read file in binary mode</span></div><div class="line">fwFile = open(<span class="stringliteral">"pdu-030600-45660.bin"</span>, <span class="stringliteral">"rb"</span>)</div><div class="line"><span class="comment"># upload</span></div><div class="line">firmware.upload(agent, fwFile.read())</div><div class="line"></div><div class="line">image_present, image_info = firmware_proxy.getImageInfo()</div><div class="line"></div><div class="line"><span class="comment"># check for succesfull upload</span></div><div class="line"><span class="keywordflow">if</span> <span class="keywordflow">not</span> image_present:</div><div class="line"> print(<span class="stringliteral">"Upload failed"</span>)</div><div class="line"><span class="keywordflow">else</span>:</div><div class="line"> print(image_info)</div><div class="line"> <span class="comment"># start update</span></div><div class="line"> firmware_proxy.startUpdate([])</div></div><!-- fragment --><h2>Certificate Upload and installation</h2>
<p>It is possible to upload and install own certificates. The Certificate upload needs two files:</p><ol type="1">
<li>certificate file (e.g. my-cert.crt)</li>
<li>key file (e.g. my-key.key) It is recommended that the user verifies the pending certificate before installation.</li>
</ol>
<p>Example:</p>
<div class="fragment"><div class="line"><span class="keyword">from</span> raritan <span class="keyword">import</span> rpc</div><div class="line"><span class="keyword">from</span> raritan.rpc <span class="keyword">import</span> cert</div><div class="line"></div><div class="line">agent = rpc.Agent(<span class="stringliteral">"https"</span>, <span class="stringliteral">"my-pdu.example.com"</span>, <span class="stringliteral">"admin"</span>, <span class="stringliteral">"raritan"</span>)</div><div class="line">ssl_proxy = cert.ServerSSLCert(<span class="stringliteral">"/server_ssl_cert"</span>, agent)</div><div class="line"></div><div class="line"><span class="comment"># read files in binary mode</span></div><div class="line">certFile = open(<span class="stringliteral">"my-cert.crt"</span>, <span class="stringliteral">"rb"</span>)</div><div class="line">keyFile = open(<span class="stringliteral">"my-key.key"</span>, <span class="stringliteral">"rb"</span>)</div><div class="line"><span class="comment"># upload</span></div><div class="line">cert.upload(agent, certFile.read(), keyFile.read())</div><div class="line"></div><div class="line"><span class="comment"># view pending</span></div><div class="line">print(ssl_proxy.getInfo().pendingCertInfo)</div><div class="line"><span class="comment"># install</span></div><div class="line">ssl_proxy.installPendingKeyPair()</div><div class="line"><span class="comment"># view active</span></div><div class="line">print(ssl_proxy.getInfo().activeCertInfo)</div></div><!-- fragment --><h2>Certificate Download</h2>
<p>It is possible to download the installed certificates.</p>
<p>Example:</p>
<div class="fragment"><div class="line"><span class="keyword">from</span> raritan <span class="keyword">import</span> rpc</div><div class="line"><span class="keyword">from</span> raritan.rpc <span class="keyword">import</span> cert</div><div class="line"></div><div class="line">agent = rpc.Agent(<span class="stringliteral">"https"</span>, <span class="stringliteral">"my-pdu.example.com"</span>, <span class="stringliteral">"admin"</span>, <span class="stringliteral">"raritan"</span>)</div><div class="line"></div><div class="line"><span class="comment"># downlaod the current installed certificate</span></div><div class="line">certificate = cert.download(agent)</div><div class="line"><span class="comment"># view the certificate</span></div><div class="line">print(certificate)</div></div><!-- fragment --><h2>Raw Configuration Upload</h2>
<p>It is possible to upload a raw configuration. The raw configuration upload need one file:</p><ol type="1">
<li>raw configuration file (e.g. config.txt)</li>
</ol>
<p>After uploading a raw configuration a response code is returned. Known response codes are:</p>
<table class="markdownTable">
<tr class="markdownTableHead">
<th class="markdownTableHeadNone" colspan="2">Response </th></tr>
<tr class="markdownTableBody" class="markdownTableRowOdd">
<td class="markdownTableBodyNone">0 </td><td class="markdownTableBodyNone">Operation was succesfull. </td></tr>
<tr class="markdownTableBody" class="markdownTableRowEven">
<td class="markdownTableBodyNone">1 </td><td class="markdownTableBodyNone">An internal error occured. </td></tr>
<tr class="markdownTableBody" class="markdownTableRowOdd">
<td class="markdownTableBodyNone">2 </td><td class="markdownTableBodyNone">A parameter error occured. </td></tr>
<tr class="markdownTableBody" class="markdownTableRowEven">
<td class="markdownTableBodyNone">3 </td><td class="markdownTableBodyNone">A raw config update operation is already running. </td></tr>
<tr class="markdownTableBody" class="markdownTableRowOdd">
<td class="markdownTableBodyNone">4 </td><td class="markdownTableBodyNone">The file is too large. </td></tr>
<tr class="markdownTableBody" class="markdownTableRowEven">
<td class="markdownTableBodyNone">5 </td><td class="markdownTableBodyNone">Invalid raw config file provided. </td></tr>
<tr class="markdownTableBody" class="markdownTableRowOdd">
<td class="markdownTableBodyNone">6 </td><td class="markdownTableBodyNone">Invalid device list file or match provided. </td></tr>
<tr class="markdownTableBody" class="markdownTableRowEven">
<td class="markdownTableBodyNone">7 </td><td class="markdownTableBodyNone">Device list file required but missing. It must be the first uploaded file! </td></tr>
<tr class="markdownTableBody" class="markdownTableRowOdd">
<td class="markdownTableBodyNone">8 </td><td class="markdownTableBodyNone">No matching entry in device list found. </td></tr>
<tr class="markdownTableBody" class="markdownTableRowEven">
<td class="markdownTableBodyNone">9 </td><td class="markdownTableBodyNone">Macro subsitution error. </td></tr>
<tr class="markdownTableBody" class="markdownTableRowOdd">
<td class="markdownTableBodyNone">10 </td><td class="markdownTableBodyNone">Decrypting value failed. </td></tr>
<tr class="markdownTableBody" class="markdownTableRowEven">
<td class="markdownTableBodyNone">11 </td><td class="markdownTableBodyNone">Unknown magic line. </td></tr>
<tr class="markdownTableBody" class="markdownTableRowOdd">
<td class="markdownTableBodyNone">12 </td><td class="markdownTableBodyNone">Processing magic line fail. </td></tr>
</table>
<p>Example:</p>
<div class="fragment"><div class="line"><span class="keyword">from</span> raritan <span class="keyword">import</span> rpc</div><div class="line"><span class="keyword">from</span> raritan.rpc <span class="keyword">import</span> rawcfg</div><div class="line"></div><div class="line">agent = rpc.Agent(<span class="stringliteral">"https"</span>, <span class="stringliteral">"my-pdu.example.com"</span>, <span class="stringliteral">"admin"</span>, <span class="stringliteral">"raritan"</span>)</div><div class="line"></div><div class="line"><span class="comment"># read file in binary mode</span></div><div class="line">cfg_file = open(<span class="stringliteral">"config.txt"</span>, <span class="stringliteral">"rb"</span>)</div><div class="line"><span class="comment"># upload</span></div><div class="line">code = rawcfg.upload(agent, cfg_file.read())</div><div class="line"><span class="comment"># output response code</span></div><div class="line">print(code)</div></div><!-- fragment --><h2>Raw Configuration Download</h2>
<p>It is possible to download the raw configuration.</p>
<p>Example:</p>
<div class="fragment"><div class="line"><span class="keyword">from</span> raritan <span class="keyword">import</span> rpc</div><div class="line"><span class="keyword">from</span> raritan.rpc <span class="keyword">import</span> rawcfg</div><div class="line"></div><div class="line">agent = rpc.Agent(<span class="stringliteral">"https"</span>, <span class="stringliteral">"my-pdu.example.com"</span>, <span class="stringliteral">"admin"</span>, <span class="stringliteral">"raritan"</span>)</div><div class="line"></div><div class="line"><span class="comment"># download</span></div><div class="line">rawconfig = rawcfg.download(agent)</div><div class="line"><span class="comment"># output raw configuration</span></div><div class="line">print(rawconfig)</div></div><!-- fragment --><h2>Bulk Configuration Upload</h2>
<p>It is possible to upload a bulk configuration. The bulk configuration upload need one file:</p><ol type="1">
<li>bulk configuration file (e.g. bulk_config.txt)</li>
</ol>
<p>After uploading a bulk configuration a response code is returned. Known response codes are:</p>
<p>Response Code | Description | Comment — | — | — 0 | Operation was successful. | 1 | An internal error occured. | 2 | A parameter error occured. | 3 | Invalid XML data provided. | legacy / unused 4 | The config data is incompatible. Device type mismatch. | 5 | The config data is incompatible. Device model mismatch. | 6 | The config data is incompatible. Firmware version mismatch. | 7 | The config data is incompatible. Unknown data type. | legacy / unused 8 | The config data is invalid. | legacy / unused 9 | Checksum of config data is wrong. | legacy / unused 10 | Mode mismatch (bulk config vs. full config). | legacy / unused 11 | Restore operation already running. | 12 | File too large. | 13 | File invalid. | 14 | Checksum missing or invalid. | 15 | Unknown filters. |</p>
<p>Example:</p>
<div class="fragment"><div class="line"><span class="keyword">from</span> raritan <span class="keyword">import</span> rpc</div><div class="line"><span class="keyword">from</span> raritan.rpc <span class="keyword">import</span> bulkcfg</div><div class="line"></div><div class="line">agent = rpc.Agent(<span class="stringliteral">"https"</span>, <span class="stringliteral">"my-pdu.example.com"</span>, <span class="stringliteral">"admin"</span>, <span class="stringliteral">"raritan"</span>)</div><div class="line"></div><div class="line"><span class="comment"># read file in binary mode</span></div><div class="line">cfg_file = open(<span class="stringliteral">"bulk_config.txt"</span>, <span class="stringliteral">"rb"</span>)</div><div class="line"><span class="comment"># upload</span></div><div class="line">code = bulkcfg.upload(agent, cfg_file.read())</div><div class="line"><span class="comment"># view code</span></div><div class="line">print(code)</div></div><!-- fragment --><p>The bulk configuration upload support different modes, these modes are:</p><ul>
<li>restore a configuration backup (backup or full)</li>
<li>restore a bulk configuration (default)</li>
</ul>
<p>For switching the modes, use the parameters full or backup from the uplaod function.</p>
<p>Example:</p>
<div class="fragment"><div class="line"><span class="comment"># backup mode</span></div><div class="line">code = bulkcfg.upload(agent, cfg_file.read(), backup=<span class="keyword">True</span>)</div></div><!-- fragment --><div class="fragment"><div class="line"><span class="comment"># full mode</span></div><div class="line">code = bulkcfg.upload(agent, cfg_file.read(), full=<span class="keyword">True</span>)</div></div><!-- fragment --><h2>Bulk Configuration Download</h2>
<p>It is possible to download the bulk configuration.</p>
<p>Example:</p>
<div class="fragment"><div class="line"><span class="keyword">from</span> raritan <span class="keyword">import</span> rpc</div><div class="line"><span class="keyword">from</span> raritan.rpc <span class="keyword">import</span> bulkcfg</div><div class="line"></div><div class="line">agent = rpc.Agent(<span class="stringliteral">"https"</span>, <span class="stringliteral">"my-pdu.example.com"</span>, <span class="stringliteral">"admin"</span>, <span class="stringliteral">"raritan"</span>)</div><div class="line"></div><div class="line"><span class="comment"># download</span></div><div class="line">bulkconfig = bulkcfg.download(agent)</div><div class="line"><span class="comment"># output bulk configuration</span></div><div class="line">print(bulkconfig)</div></div><!-- fragment --><p>The bulk configuration download support different modes, these modes are:</p><ul>
<li>restore a configuration backup (backup or full)</li>
<li>restore a bulk configuration (default)</li>
</ul>
<p>For switching the modes, use the parameters full or backup from the uplaod function.</p>
<p>Example:</p>
<div class="fragment"><div class="line"><span class="comment"># backup mode</span></div><div class="line">code = bulkcfg.download(agent, backup=<span class="keyword">True</span>)</div></div><!-- fragment --><div class="fragment"><div class="line"><span class="comment"># full mode</span></div><div class="line">code = bulkcfg.download(agent, full=<span class="keyword">True</span>)</div></div><!-- fragment --><h2>Diagnostic Data Download</h2>
<p>It is possible to download the diagnostic data.</p>
<p>Example:</p>
<div class="fragment"><div class="line"><span class="keyword">from</span> raritan <span class="keyword">import</span> rpc</div><div class="line"><span class="keyword">from</span> raritan.rpc <span class="keyword">import</span> diag</div><div class="line"></div><div class="line">agent = rpc.Agent(<span class="stringliteral">"https"</span>, <span class="stringliteral">"my-pdu.example.com"</span>, <span class="stringliteral">"admin"</span>, <span class="stringliteral">"raritan"</span>)</div><div class="line"><span class="comment"># download</span></div><div class="line">diag = diag.download_diag(agent)</div><div class="line"><span class="comment"># view diagnostic data</span></div><div class="line">print(diag)</div></div><!-- fragment --><h2>ETO Descriptor Download</h2>
<p>It is possible to download the ETO descriptor.</p>
<p>Example:</p>
<div class="fragment"><div class="line"><span class="keyword">from</span> raritan <span class="keyword">import</span> rpc</div><div class="line"><span class="keyword">from</span> raritan.rpc <span class="keyword">import</span> pdumodel</div><div class="line"></div><div class="line">agent = rpc.Agent(<span class="stringliteral">"https"</span>, <span class="stringliteral">"my-pdu.example.com"</span>, <span class="stringliteral">"admin"</span>, <span class="stringliteral">"raritan"</span>)</div><div class="line"><span class="comment"># download</span></div><div class="line">eto_desc = pdumodel.download_eto(agent)</div><div class="line"><span class="comment"># view eto descriptor</span></div><div class="line">print(eto_desc)</div></div><!-- fragment --><h2>PMC Data Download</h2>
<p>It is possible to download the PMC data of:</p><ol type="1">
<li>For all main sensors and circuits of that a specific panel, numbered 1 - 8</li>
<li>For all main sensors of all configured power meters and panels</li>
</ol>
<p>Example:</p>
<div class="fragment"><div class="line"><span class="keyword">from</span> raritan <span class="keyword">import</span> rpc</div><div class="line"><span class="keyword">from</span> raritan.rpc <span class="keyword">import</span> pdumodel</div><div class="line"></div><div class="line">agent = rpc.Agent(<span class="stringliteral">"https"</span>, <span class="stringliteral">"my-pdu.example.com"</span>, <span class="stringliteral">"admin"</span>, <span class="stringliteral">"raritan"</span>)</div><div class="line"><span class="comment"># download specific,for panel 1 (can be in range 1 - 8)</span></div><div class="line">pmc_data = pdumodel.download_panel_csv(agent, 1)</div><div class="line"><span class="comment"># download complete</span></div><div class="line">pmc_data = pdumodel.download_powermeter_csv(agent)</div><div class="line"><span class="comment"># view pmc data</span></div><div class="line">print(pmc_data)</div></div><!-- fragment --><h2>PMC Configuration Upload</h2>
<p>It is possible to upload the pmc configuration. The pmc configuration upload need one file:</p><ol type="1">
<li>pmc configuration file (e.g. pmc_config.txt)</li>
</ol>
<p>Example:</p>
<div class="fragment"><div class="line"><span class="keyword">from</span> raritan <span class="keyword">import</span> rpc</div><div class="line"><span class="keyword">from</span> raritan.rpc <span class="keyword">import</span> pdumodel</div><div class="line"></div><div class="line">agent = rpc.Agent(<span class="stringliteral">"https"</span>, <span class="stringliteral">"my-pdu.example.com"</span>, <span class="stringliteral">"admin"</span>, <span class="stringliteral">"raritan"</span>)</div><div class="line"></div><div class="line"><span class="comment"># read file in binary mode</span></div><div class="line">pmc_config = open(<span class="stringliteral">"config.txt"</span>, <span class="stringliteral">"rb"</span>)</div><div class="line"><span class="comment"># upload</span></div><div class="line">response = pdumodel.upload_pmc_config(agent, pmc_config.read())</div><div class="line"><span class="comment"># output response</span></div><div class="line">print(response)</div></div><!-- fragment --><h2>Zeroconf device discovery</h2>
<p>There is a helper function, that will discover Raritan power products inside of the current subnet and will return a list of ip strings. For this feature there must be the zeroconf python package installed (pip install zeronfonf). This package is only available for python version 3.6 and up.</p>
<p>Example:</p>
<div class="fragment"><div class="line"><span class="keyword">from</span> raritan <span class="keyword">import</span> zeroconf</div><div class="line"></div><div class="line">response = zeroconf.discover()</div><div class="line">print(response)</div></div><!-- fragment --> </div></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Aug 21 2020 10:20:37 for Raritan PX2/PX3 JSON-RPC API by  <a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.14
</small></address>
</body>
</html>
|