-
Notifications
You must be signed in to change notification settings - Fork 7
XenObject
XenObject is a base class for all XenAPI "classes".
The instance of a class represents a "real" Xen infrastructure object (VM, Task, Event) and its unique identifier is ref
.
If you want to add a new type of "class" and ensure RethinkDB caching, you should add your derived class to objects
list in EventLoop.__init__
and override your class' db_table_name
to what you'd want it to be in RethinkDB.
Set api_class
class variable to corresponding XenAPI "class". Look it up in XenAPI documentation. __getattr__
will do all the dirty work for you, so that all attributes of XenAPI "class" would become class methods of your XenObject derivative. It will provide a session object for you, but you should pass XenAdapter
as a first argument. (but if you'd call XenAPI method from an instance of a class, then it'd provide it for you as XenObject.__init__
requires an XenAdapter
.
If you want to use Asynchronous API, add async_
to the beginning of your method.
For example, in order to destroy a VM asyncronously, do
# vm is an instance of VM object
task = vm.async_destroy()
task will be an str
object containing a ref
for a XenAPI task
. To use it, do:
t = Task(ref=task, xen=info.context.xen)
This example is taken from Mutations.
If you want ACL capabilities, add your derived class to objects
list on top of vmemperor.py
file and subclass your "object" from ACLXenObject
.