Commit b60ab075 authored by Alastair Tse's avatar Alastair Tse

[XEND] Conform to Xen API XMLRPC Wire Protocol Customisation

1. Int(s) all have to be String(s).
2. Enums are not transmitted as Ints, but as Descriptive Strings.
Signed-off-by: default avatarAlastair Tse <>
parent aba2d40c
......@@ -22,8 +22,8 @@ from pprint import pprint
from types import DictType
HOST_INFO_FORMAT = '%-20s: %-50s'
VM_LIST_FORMAT = '%(name_label)-24s %(memory_actual)-5s %(vcpus_number)-5s'\
' %(power_state)-5s %(uuid)-32s'
VM_LIST_FORMAT = '%(name_label)-18s %(memory_actual)-5s %(vcpus_number)-5s'\
' %(power_state)-12s %(uuid)-32s'
LOGIN = ('atse', 'passwd')
......@@ -26,8 +26,23 @@ from xen.xend.XendLogging import log
from xen.xend.XendAPIConstants import *
from types import *
def _stringify(value):
if isinstance(value, IntType) and not isinstance(value, BooleanType):
return str(value)
elif isinstance(value, DictType):
for k, v in value.items():
value[k] = _stringify(v)
return value
elif isinstance(value, (TupleType, ListType)):
return [_stringify(v) for v in value]
return value
def xen_api_success(value):
return {"Status": "Success", "Value": value}
return {"Status": "Success", "Value": _stringify(value)}
def xen_api_success_void():
"""Return success, but caller expects no return value."""
return xen_api_success("")
......@@ -1653,7 +1653,7 @@ class XendDomainInfo:
def get_vcpus_params(self):
return '' # TODO
def get_power_state(self):
return self.state
return XEN_API_VM_POWER_STATE[self.state]
def get_tpm_instance(self):
return '' # TODO
def get_tpm_backend(self):
......@@ -1673,7 +1673,11 @@ class XendDomainInfo:
def get_builder(self):
return 'Linux' # TODO
def get_boot_method(self):
bootloader =['bootloader']
if not bootloader or bootloader not in XEN_API_BOOT_TYPE:
return 'kernel_external'
return bootloader
def get_kernel_image(self):
def get_kernel_initrd(self):
......@@ -1690,30 +1694,33 @@ class XendDomainInfo:
return {} # TODO
def get_on_shutdown(self):
return XEN_API_ON_NORMAL_EXIT.index(['on_poweroff'])
except ValueError, e:
return XEN_API_ON_NORMAL_EXIT.index('restart')
after_shutdown ='on_poweroff')
if not after_shutdown or after_shutdown not in XEN_API_ON_NORMAL_EXIT:
return after_shutdown
def get_on_reboot(self):
return XEN_API_ON_NORMAL_EXIT.index(['on_reboot'])
except ValueError, e:
return XEN_API_ON_NORMAL_EXIT.index('restart')
after_reboot ='on_reboot')
if not after_reboot or after_reboot not in XEN_API_ON_NORMAL_EXIT:
return after_reboot
def get_on_suspend(self):
return 0 # TODO
after_suspend ='on_suspend') # TODO: not supported
if not after_suspend or after_suspend not in XEN_API_ON_NORMAL_EXIT:
return after_suspend
def get_on_crash(self):
return XEN_API_ON_CRASH_BEHAVIOUR.index(['on_crash'])
except ValueError, e:
return XEN_API_ON_CRASH_BEHAVIOUR.index('destroy')
after_crash ='on_crash')
if not after_crash or after_crash not in XEN_API_ON_CRASH_BEHAVIOUR:
return after_crash
def get_dev_config_by_uuid(self, dev_class, dev_uuid):
""" Get's a device configuration either from XendConfig or
from the DevController."""
if self.get_power_state() in (XEN_API_VM_POWER_STATE_HALTED,):
if self.state in (XEN_API_VM_POWER_STATE_HALTED,):
dev =['device'].get(dev_uuid)
if dev:
return dev[1].copy()
......@@ -1768,7 +1775,11 @@ class XendDomainInfo:
config['device'] = config.get('dev', '')
config['driver'] = config.get('uname', '')
config['IO_bandwidth_incoming_kbs'] = 0.0
config['IO_bandwidth_outgoing_kbs'] = 0.0
config['IO_bandwidth_outgoing_kbs'] = 0.0
if config['mode'] == 'r':
config['mode'] = 'RO'
config['mode'] = 'RW'
return config
......@@ -1821,7 +1832,7 @@ class XendDomainInfo:
if not dev_uuid:
raise XendError('Failed to create device')
if self.state in (XEN_API_VM_POWER_STATE_RUNNING,):
if self.state in (DOM_STATE_HALTED,):
sxpr =
devid = self.getDeviceController('vif').createDevice(sxpr)
raise XendError("Device creation failed")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment