ia64/xen-unstable

changeset 12116:9e0b024a1696

[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: Alastair Tse <atse@xensource.com>
author Alastair Tse <atse@xensource.com>
date Fri Oct 06 22:50:29 2006 +0100 (2006-10-06)
parents 53b8f2b74ab2
children c75716820107
files tools/python/scripts/xapi.py tools/python/xen/xend/XendAPI.py tools/python/xen/xend/XendDomainInfo.py
line diff
     1.1 --- a/tools/python/scripts/xapi.py	Fri Oct 06 18:01:08 2006 +0100
     1.2 +++ b/tools/python/scripts/xapi.py	Fri Oct 06 22:50:29 2006 +0100
     1.3 @@ -22,8 +22,8 @@ from pprint import pprint
     1.4  from types import DictType
     1.5  
     1.6  HOST_INFO_FORMAT = '%-20s: %-50s'
     1.7 -VM_LIST_FORMAT = '%(name_label)-24s %(memory_actual)-5s %(vcpus_number)-5s'\
     1.8 -                 ' %(power_state)-5s %(uuid)-32s'
     1.9 +VM_LIST_FORMAT = '%(name_label)-18s %(memory_actual)-5s %(vcpus_number)-5s'\
    1.10 +                 ' %(power_state)-12s %(uuid)-32s'
    1.11  
    1.12  LOGIN = ('atse', 'passwd')
    1.13  
     2.1 --- a/tools/python/xen/xend/XendAPI.py	Fri Oct 06 18:01:08 2006 +0100
     2.2 +++ b/tools/python/xen/xend/XendAPI.py	Fri Oct 06 22:50:29 2006 +0100
     2.3 @@ -26,8 +26,23 @@ from xen.xend.XendLogging import log
     2.4  
     2.5  from xen.xend.XendAPIConstants import *
     2.6  
     2.7 +from types import *
     2.8 +
     2.9 +def _stringify(value):
    2.10 +    if isinstance(value, IntType) and not isinstance(value, BooleanType):
    2.11 +        return str(value)
    2.12 +    elif isinstance(value, DictType):
    2.13 +        for k, v in value.items():
    2.14 +            value[k] = _stringify(v)
    2.15 +        return value
    2.16 +    elif isinstance(value, (TupleType, ListType)):
    2.17 +        return [_stringify(v) for v in value]
    2.18 +    else:
    2.19 +        return value
    2.20 +    
    2.21  def xen_api_success(value):
    2.22 -    return {"Status": "Success", "Value": value}
    2.23 +    return {"Status": "Success", "Value": _stringify(value)}
    2.24 +
    2.25  def xen_api_success_void():
    2.26      """Return success, but caller expects no return value."""
    2.27      return xen_api_success("")
     3.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Fri Oct 06 18:01:08 2006 +0100
     3.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Fri Oct 06 22:50:29 2006 +0100
     3.3 @@ -1653,7 +1653,7 @@ class XendDomainInfo:
     3.4      def get_vcpus_params(self):
     3.5          return '' # TODO
     3.6      def get_power_state(self):
     3.7 -        return self.state
     3.8 +        return XEN_API_VM_POWER_STATE[self.state]
     3.9      def get_tpm_instance(self):
    3.10          return '' # TODO
    3.11      def get_tpm_backend(self):
    3.12 @@ -1673,7 +1673,11 @@ class XendDomainInfo:
    3.13      def get_builder(self):
    3.14          return 'Linux' # TODO
    3.15      def get_boot_method(self):
    3.16 -        return self.info['bootloader']
    3.17 +        bootloader = self.info['bootloader']
    3.18 +        if not bootloader or bootloader not in XEN_API_BOOT_TYPE:
    3.19 +            return 'kernel_external'
    3.20 +        return bootloader
    3.21 +    
    3.22      def get_kernel_image(self):
    3.23          return self.info['kernel_kernel']
    3.24      def get_kernel_initrd(self):
    3.25 @@ -1690,30 +1694,33 @@ class XendDomainInfo:
    3.26          return {} # TODO
    3.27      
    3.28      def get_on_shutdown(self):
    3.29 -        try:
    3.30 -            return XEN_API_ON_NORMAL_EXIT.index(self.info['on_poweroff'])
    3.31 -        except ValueError, e:
    3.32 -            return XEN_API_ON_NORMAL_EXIT.index('restart')
    3.33 -    
    3.34 +        after_shutdown = self.info.get('on_poweroff')
    3.35 +        if not after_shutdown or after_shutdown not in XEN_API_ON_NORMAL_EXIT:
    3.36 +            return XEN_API_ON_NORMAL_EXIT[-1]
    3.37 +        return after_shutdown
    3.38 +
    3.39      def get_on_reboot(self):
    3.40 -        try:
    3.41 -            return XEN_API_ON_NORMAL_EXIT.index(self.info['on_reboot'])
    3.42 -        except ValueError, e:
    3.43 -            return XEN_API_ON_NORMAL_EXIT.index('restart')        
    3.44 +        after_reboot = self.info.get('on_reboot')
    3.45 +        if not after_reboot or after_reboot not in XEN_API_ON_NORMAL_EXIT:
    3.46 +            return XEN_API_ON_NORMAL_EXIT[-1]
    3.47 +        return after_reboot
    3.48  
    3.49      def get_on_suspend(self):
    3.50 -        return 0 # TODO
    3.51 +        after_suspend = self.info.get('on_suspend') # TODO: not supported
    3.52 +        if not after_suspend or after_suspend not in XEN_API_ON_NORMAL_EXIT:
    3.53 +            return XEN_API_ON_NORMAL_EXIT[-1]
    3.54 +        return after_suspend        
    3.55  
    3.56      def get_on_crash(self):
    3.57 -        try:
    3.58 -            return XEN_API_ON_CRASH_BEHAVIOUR.index(self.info['on_crash'])
    3.59 -        except ValueError, e:
    3.60 -            return XEN_API_ON_CRASH_BEHAVIOUR.index('destroy')
    3.61 +        after_crash = self.info.get('on_crash')
    3.62 +        if not after_crash or after_crash not in XEN_API_ON_CRASH_BEHAVIOUR:
    3.63 +            return XEN_API_ON_CRASH_BEHAVIOUR[0]
    3.64 +        return after_crash
    3.65  
    3.66      def get_dev_config_by_uuid(self, dev_class, dev_uuid):
    3.67          """ Get's a device configuration either from XendConfig or
    3.68          from the DevController."""
    3.69 -        if self.get_power_state() in (XEN_API_VM_POWER_STATE_HALTED,):
    3.70 +        if self.state in (XEN_API_VM_POWER_STATE_HALTED,):
    3.71              dev = self.info['device'].get(dev_uuid)
    3.72              if dev:
    3.73                  return dev[1].copy()
    3.74 @@ -1768,7 +1775,11 @@ class XendDomainInfo:
    3.75              config['device'] = config.get('dev', '')
    3.76              config['driver'] = config.get('uname', '')
    3.77              config['IO_bandwidth_incoming_kbs'] = 0.0
    3.78 -            config['IO_bandwidth_outgoing_kbs'] = 0.0                        
    3.79 +            config['IO_bandwidth_outgoing_kbs'] = 0.0
    3.80 +            if config['mode'] == 'r':
    3.81 +                config['mode'] = 'RO'
    3.82 +            else:
    3.83 +                config['mode'] = 'RW'
    3.84  
    3.85          return config
    3.86  
    3.87 @@ -1821,7 +1832,7 @@ class XendDomainInfo:
    3.88          if not dev_uuid:
    3.89              raise XendError('Failed to create device')
    3.90          
    3.91 -        if self.state in (XEN_API_VM_POWER_STATE_RUNNING,):
    3.92 +        if self.state in (DOM_STATE_HALTED,):
    3.93              sxpr = self.info.device_sxpr(dev_uuid)
    3.94              devid = self.getDeviceController('vif').createDevice(sxpr)
    3.95              raise XendError("Device creation failed")