RCI callback

An RCI callback involves two types of actions, demonstrated in the following programs:

The following example shows an RCI request.

Note The highlighted numbers in the sample code correspond to the items in the Program Notes, below.

  import rci			(1)

  request_string="""			(2)
<rci_request version="1.1">
  <query_state>
    <interface_info name="eth0">
      <ip/>
    </interface_info>
  </query_state>
</rci_request>
"""

print rci.process_request(request_string)			(3)

Program notes

  1. The rci module includes the process_request function needed by the program.
  2. A string representing the RCI request is needed. This sample uses the Python multi-line string syntax to make it clear that the XML represents a request for the current IP address of the Ethernet interface. Combining the lines into a single string on one line would work in the same way.
  3. The RCI XML is submitted for parsing, and the resulting string is returned. In this sample, the result is simply printed.

Following example shows a simple RCI callback:

import rci			(1)

def cb(req):			(2)
         print "Received request: " + req				 (3)

r=rci.RciCallback() (4) r.register_callback('test', cb) (5) rci.process_request('<rci_request version="1.1"><do_command target="test"><customxml/></do_command></rci_request>')(6)

Program notes

  1. The RCI module includes the RciCallback class needed by the program.
  2. Create a function to be called whenever a remote entity wants to communicate with this script.
  3. This simple function will simply demonstrate that it received a request that could be parsed and handled however the application saw fit.
  4. Create a callback object.
  5. Assign the target “test” to the new callback object. If a remote entity issues a “do_command” with the target “test”, the supplied callback function will be called.
  6. This is simply an example that causes the callback to be called. This example could also have been a remote SCI query through Remote Manager.