RAD Event Handling in Python
This example shows how to subscribe to and handle events. The ZoneManager
instance defines a stateChange
event, which clients can subscribe to for information about changes in the runtime state of a zone.
Example 2-43 Python Language – Subscribing to and Handling RAD Events
import rad.connect as radcon import rad.bindings.com.oracle.solaris.rad.zonemgr as zonemgr import signal def handler(event, payload, user): print "event: %s" % str(event) print "payload: %s" % str(payload) print "zone: %s" % str(payload.zone) print "old: %s" % str(payload.oldstate) print "new: %s" % str(payload.newstate) with radcon.connect_unix() as rc: zm = rc.get_object(zonemgr.ZoneManager()) rc.subscribe(zm, "stateChange", handler, zm) signal.pause()
In this example, you have subscribed to a single event by passing a handler and a reference to the ZoneManager
object. The handler is invoked asynchronously by the framework with various event details and user data. The user data is an optional argument at subscription. If the user data is not provided, the handler receives None
as the user parameter.