[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] [XEND] Conform to Xen API XMLRPC Wire Protocol Customisation



# HG changeset patch
# User Alastair Tse <atse@xxxxxxxxxxxxx>
# Node ID 9e0b024a169624507452130244e940fa3fd6000d
# Parent  53b8f2b74ab27fdb4c4f19915247b67626699978
[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@xxxxxxxxxxxxx>
---
 tools/python/scripts/xapi.py            |    4 +-
 tools/python/xen/xend/XendAPI.py        |   17 ++++++++++-
 tools/python/xen/xend/XendDomainInfo.py |   49 +++++++++++++++++++-------------
 3 files changed, 48 insertions(+), 22 deletions(-)

diff -r 53b8f2b74ab2 -r 9e0b024a1696 tools/python/scripts/xapi.py
--- a/tools/python/scripts/xapi.py      Fri Oct 06 18:01:08 2006 +0100
+++ b/tools/python/scripts/xapi.py      Fri Oct 06 22:50:29 2006 +0100
@@ -22,8 +22,8 @@ from types import DictType
 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')
 
diff -r 53b8f2b74ab2 -r 9e0b024a1696 tools/python/xen/xend/XendAPI.py
--- a/tools/python/xen/xend/XendAPI.py  Fri Oct 06 18:01:08 2006 +0100
+++ b/tools/python/xen/xend/XendAPI.py  Fri Oct 06 22:50:29 2006 +0100
@@ -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]
+    else:
+        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("")
diff -r 53b8f2b74ab2 -r 9e0b024a1696 tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py   Fri Oct 06 18:01:08 2006 +0100
+++ b/tools/python/xen/xend/XendDomainInfo.py   Fri Oct 06 22:50:29 2006 +0100
@@ -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):
-        return self.info['bootloader']
+        bootloader = self.info['bootloader']
+        if not bootloader or bootloader not in XEN_API_BOOT_TYPE:
+            return 'kernel_external'
+        return bootloader
+    
     def get_kernel_image(self):
         return self.info['kernel_kernel']
     def get_kernel_initrd(self):
@@ -1690,30 +1694,33 @@ class XendDomainInfo:
         return {} # TODO
     
     def get_on_shutdown(self):
-        try:
-            return XEN_API_ON_NORMAL_EXIT.index(self.info['on_poweroff'])
-        except ValueError, e:
-            return XEN_API_ON_NORMAL_EXIT.index('restart')
-    
+        after_shutdown = self.info.get('on_poweroff')
+        if not after_shutdown or after_shutdown not in XEN_API_ON_NORMAL_EXIT:
+            return XEN_API_ON_NORMAL_EXIT[-1]
+        return after_shutdown
+
     def get_on_reboot(self):
-        try:
-            return XEN_API_ON_NORMAL_EXIT.index(self.info['on_reboot'])
-        except ValueError, e:
-            return XEN_API_ON_NORMAL_EXIT.index('restart')        
+        after_reboot = self.info.get('on_reboot')
+        if not after_reboot or after_reboot not in XEN_API_ON_NORMAL_EXIT:
+            return XEN_API_ON_NORMAL_EXIT[-1]
+        return after_reboot
 
     def get_on_suspend(self):
-        return 0 # TODO
+        after_suspend = self.info.get('on_suspend') # TODO: not supported
+        if not after_suspend or after_suspend not in XEN_API_ON_NORMAL_EXIT:
+            return XEN_API_ON_NORMAL_EXIT[-1]
+        return after_suspend        
 
     def get_on_crash(self):
-        try:
-            return XEN_API_ON_CRASH_BEHAVIOUR.index(self.info['on_crash'])
-        except ValueError, e:
-            return XEN_API_ON_CRASH_BEHAVIOUR.index('destroy')
+        after_crash = self.info.get('on_crash')
+        if not after_crash or after_crash not in XEN_API_ON_CRASH_BEHAVIOUR:
+            return XEN_API_ON_CRASH_BEHAVIOUR[0]
+        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 = self.info['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'
+            else:
+                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 = self.info.device_sxpr(dev_uuid)
             devid = self.getDeviceController('vif').createDevice(sxpr)
             raise XendError("Device creation failed")

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.