HP BL680c XenEnterprise Management API - Page 10
Example interactive session
UPC - 884420396314
View all HP BL680c manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 10 highlights
1.5. EXAMPLE INTERACTIVE SESSION CHAPTER 1. INTRODUCTION returns a set of all task IDs known to the system. The status (including any returned result and error codes) of these tasks can then be queried by accessing the fields of the Task object in the usual way. Note that, in order to get a consistent snapshot of a task's state, it is advisable to call the "get record" function. 1.5 Example interactive session This section describes how an interactive session might look, using the python XML-RPC client library. First, initialise python and import the library xmlrpclib: \$ python2.4 ... >>> import xmlrpclib Create a python object referencing the remote server: >>> xen = xmlrpclib.Server("https://localhost:443") Acquire a session reference by logging in with a username and password (error-handling ommitted for brevity; the session reference is returned under the key 'Value' in the resulting dictionary) >>> session = xen.session.login_with_password("user", "passwd")['Value'] When serialised, this call looks like the following: session.login_with_password user passwd Next, the user may acquire a list of all the VMs known to the system: (Note the call takes the session reference as the only parameter) >>> all_vms = xen.VM.get_all(session)['Value'] >>> all_vms ['OpaqueRef:1', 'OpaqueRef:2', 'OpaqueRef:3', 'OpaqueRef:4' ] The VM references here have the form OpaqueRef:X, though they may not be that simple in the future, and you should treat them as opaque strings. Templates are VMs with the is a template field set to true. We can find the subset of template VMs using a command like the following: >>> all_templates = filter(lambda x: xen.VM.get_is_a_template(session, x)['Value'], all_vms) Once a reference to a VM has been acquired a lifecycle operation may be invoked: >>> xen.VM.start(session, all_templates[0], False, False) {'Status': 'Failure', 'ErrorDescription': ['VM_IS_TEMPLATE', 'OpaqueRef:X']} 10