The user space interface is xapi. py.
The procedure of the member API functions of xapi. py is as follows:
1. Call connect and log on to xend through serverproxy RPC
2. Execute and execute func (* ARGs). Among them, func and ARGs are input parameters, and * ARGs indicates variable length parameters.
Xapi. py supports the following API commands:
Commands = {
'Host-info': ('', 'Get xen host info '),
'Host-set-name': ('', 'set host name '),
'Pif-list': ('', 'list all PIFs '),
'Sr-list': ('', 'list all SRS '),
'Vbd-list': ('', 'list all VBDs '),
'Vbd-create': ('<domname> <pycfg> [opts]',
'Create vbd attached to domname '),
'Vdi-create': ('<pycfg> [opts]', 'create a VDI '),
'Vdi-list': ('', 'list all VDI '),
'Vdi-rename': ('<vdi_uuid> <new_name>', 'rename VDI '),
'Vdi-destroy': ('<vdi_uuid>', 'delete VDI '),
'Vif-create': ('<domname> <pycfg>', 'create VIF attached to domname '),
'Vtpm-create': ('<domname> <pycfg>', 'create vtpm attached to domainname '),
'Vm-create': ('<pycfg>', 'create Vm with Python config '),
'Vm-destroy': ('<domname>', 'delete VM '),
'Vm-list': ('[-- long]', 'list all domains .'),
'Vm-name': ('<UUID>', 'name of UUID .'),
'Vm-Shutdown ': (' <Name> [opts] ', 'shutdown Vm with name '),
'Vm-start': ('<Name>', 'start Vm with name '),
'Vm-UUID ': (' <Name> ', 'uuid of a domain by name .'),
'Async'-VM-start': ('<Name>', 'start VM asynchronously '),
}
Let's look at an example.
Def xapi_vm_start (ARGs, async = false ):
If Len (ARGs) <1:
Raise optionerror ("no domain name specified .")
# Connect to xend
Server, session = connect ()
# Convert VM name to VM UUID
Vm_uuid = resolve_vm (server, session, argS [0])
Print 'starting VM % s (% s) '% (ARGs [0], vm_uuid)
# Call VM. Start Function
Success = execute (server, 'vm. start', (Session, vm_uuid, false), async = async)
If async:
Print 'Task started: % s' % success
Else:
Print 'did .'