ia64/xen-unstable

changeset 13219:bfa793180cb9

Fix xmlrpclib2's stringify to cope with floats and longs, removing the need
for explicit type conversions in XendAPI.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Thu Dec 28 16:30:47 2006 +0000 (2006-12-28)
parents e2392741cb91
children c731c158f63c
files tools/python/xen/util/xmlrpclib2.py tools/python/xen/xend/XendAPI.py
line diff
     1.1 --- a/tools/python/xen/util/xmlrpclib2.py	Thu Dec 28 16:14:48 2006 +0000
     1.2 +++ b/tools/python/xen/util/xmlrpclib2.py	Thu Dec 28 16:30:47 2006 +0000
     1.3 @@ -50,13 +50,15 @@ except ImportError:
     1.4  
     1.5  
     1.6  def stringify(value):
     1.7 -    if isinstance(value, IntType) and not isinstance(value, BooleanType):
     1.8 +    if isinstance(value, float) or \
     1.9 +       isinstance(value, long) or \
    1.10 +       (isinstance(value, int) and not isinstance(value, bool)):
    1.11          return str(value)
    1.12 -    elif isinstance(value, DictType):
    1.13 +    elif isinstance(value, dict):
    1.14          for k, v in value.items():
    1.15              value[k] = stringify(v)
    1.16          return value
    1.17 -    elif isinstance(value, (TupleType, ListType)):
    1.18 +    elif isinstance(value, (tuple, list)):
    1.19          return [stringify(v) for v in value]
    1.20      else:
    1.21          return value
     2.1 --- a/tools/python/xen/xend/XendAPI.py	Thu Dec 28 16:14:48 2006 +0000
     2.2 +++ b/tools/python/xen/xend/XendAPI.py	Thu Dec 28 16:30:47 2006 +0000
     2.3 @@ -1112,7 +1112,7 @@ class XendAPI:
     2.4          return_cfg = {}
     2.5          for k in cfg.keys():
     2.6              if k in valid_vbd_keys:
     2.7 -                return_cfg[k] = str(cfg[k])
     2.8 +                return_cfg[k] = cfg[k]
     2.9                  
    2.10          return xen_api_success(return_cfg)
    2.11  
    2.12 @@ -1198,7 +1198,7 @@ class XendAPI:
    2.13          return_cfg = {}
    2.14          for k in cfg.keys():
    2.15              if k in valid_vif_keys:
    2.16 -                return_cfg[k] = str(cfg[k])
    2.17 +                return_cfg[k] = cfg[k]
    2.18              
    2.19          return xen_api_success(return_cfg)
    2.20  
    2.21 @@ -1490,27 +1490,23 @@ class XendAPI:
    2.22  
    2.23      # Attribute acceess
    2.24  
    2.25 -    def _get_SR_func(self, _, func, conv = None):
    2.26 -        result = getattr(XendNode.instance().get_sr(), func)()
    2.27 -        if conv:
    2.28 -            result = conv(result)
    2.29 -        return xen_api_success(result)
    2.30 +    def _get_SR_func(self, _, func):
    2.31 +        return xen_api_success(getattr(XendNode.instance().get_sr(), func)())
    2.32  
    2.33      def _get_SR_attr(self, _, attr):
    2.34 -        return xen_api_success(str(getattr(XendNode.instance().get_sr(),
    2.35 -                                           attr)))
    2.36 +        return xen_api_success(getattr(XendNode.instance().get_sr(), attr))
    2.37  
    2.38      def SR_get_VDIs(self, _, ref):
    2.39          return self._get_SR_func(ref, 'list_images')
    2.40  
    2.41      def SR_get_virtual_allocation(self, _, ref):
    2.42 -        return self._get_SR_func(ref, 'virtual_allocation', str)
    2.43 +        return self._get_SR_func(ref, 'virtual_allocation')
    2.44  
    2.45      def SR_get_physical_utilisation(self, _, ref):
    2.46 -        return self._get_SR_func(ref, 'used_space_bytes', str)
    2.47 +        return self._get_SR_func(ref, 'used_space_bytes')
    2.48  
    2.49      def SR_get_physical_size(self, _, ref):
    2.50 -        return self._get_SR_func(ref, 'total_space_bytes', str)
    2.51 +        return self._get_SR_func(ref, 'total_space_bytes')
    2.52      
    2.53      def SR_get_type(self, _, ref):
    2.54          return self._get_SR_attr(ref, 'type')