HP BL680c XenServer Software Development Kit Guide 4.1.0 - Page 23
Language bindings, 4.2.1. C
UPC - 884420396314
View all HP BL680c manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 23 highlights
Using the API Events also contain a monotonically increasing ID, the name of the class of object and a snapshot of the object state equivalent to the result of a get_record(). Clients register for events by calling event.register() with a list of class names or the special string "*". Clients receive events by executing event.next() which blocks until events are available and returns the new events. Note Since the queue of generated events on the server is of finite length a very slow client might fail to read the events fast enough; if this happens an EVENTS_LOST error is returned. Clients should be prepared to handle this by re-registering for events and checking that the condition they are waiting for hasn't become true while they were unregistered. The following python code fragment demonstrates how to print a summary of every event generated by a system: (similar code exists in /SDK/client-examples/python/watch-all-events.py) fmt = "%8s %20s %5s %s" session.xenapi.event.register(["*"]) while True: try: for event in session.xenapi.event.next(): name = "(unknown)" if "snapshot" in event.keys(): snapshot = event["snapshot"] if "name_label" in snapshot.keys(): name = snapshot["name_label"] print fmt % (event['id'], event['class'], event['operation'], name) except XenAPI.Failure, e: if e.details == [ "EVENTS_LOST" ]: print "Caught EVENTS_LOST; should reregister" 4.2. Language bindings Although it is possible to write applications which use the XenServer Management API directly through raw XML-RPC calls, the task of developing third-party applications is greatly simplified through the use of a language binding which exposes the individual API calls as first-class functions in the target language. The SDK includes language bindings and example code for the C, C# and python programming languages and for both Linux and Windows clients. 4.2.1. C The SDK includes the source to the C language binding in the directory /SDK/client-examples/c together with a Makefile which compiles the binding into a library. Every API object is associated with a header file which contains declarations for all that object's API functions; for example the type definitions and functions required to invoke VM operations are all contained with xen_vm.h. C binding dependencies Platform supported: Library: Linux The language binding is generated as a "libxen.a" that is linked by C programs. 17