ia64/xen-unstable

changeset 17229:c949248d590a

Convert XenAPI platform values to appropriate types.

XenAPI defines the platform attribute of a VM as a string-string map
but in various code paths in xend the platform entries are expected to be
another type, e.g. int. This patch defines the types of each platform
entry and converts the entry values to appropriate type when new domU
configuration is created via XenAPI.

Alternatively the values could be casted to appropriate type when used
but seems prudent to do the conversion when domU configuration is
created.

Signed-off-by: Jim Fehlig <jfehlig@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Mar 18 11:07:00 2008 +0000 (2008-03-18)
parents 06dbce4a60f9
children 1efc81ab19cd
files tools/python/xen/xend/XendConfig.py
line diff
     1.1 --- a/tools/python/xen/xend/XendConfig.py	Tue Mar 18 11:06:26 2008 +0000
     1.2 +++ b/tools/python/xen/xend/XendConfig.py	Tue Mar 18 11:07:00 2008 +0000
     1.3 @@ -123,14 +123,43 @@ XENAPI_CFG_TO_LEGACY_CFG = {
     1.4  
     1.5  LEGACY_CFG_TO_XENAPI_CFG = reverse_dict(XENAPI_CFG_TO_LEGACY_CFG)
     1.6  
     1.7 -# Platform configuration keys.
     1.8 -XENAPI_PLATFORM_CFG = [ 'acpi', 'apic', 'boot', 'device_model', 'loader', 'display', 
     1.9 -                        'fda', 'fdb', 'keymap', 'isa', 'localtime', 'monitor', 
    1.10 -                        'nographic', 'pae', 'rtc_timeoffset', 'serial', 'sdl',
    1.11 -                        'soundhw','stdvga', 'usb', 'usbdevice', 'hpet', 'vnc',
    1.12 -                        'vncconsole', 'vncdisplay', 'vnclisten', 'timer_mode',
    1.13 -                        'vncpasswd', 'vncunused', 'xauthority', 'pci', 'vhpt',
    1.14 -                        'guest_os_type', 'hap']
    1.15 +# Platform configuration keys and their types.
    1.16 +XENAPI_PLATFORM_CFG_TYPES = {
    1.17 +    'acpi': int,
    1.18 +    'apic': int,
    1.19 +    'boot': str,
    1.20 +    'device_model': str,
    1.21 +    'loader': str,
    1.22 +    'display' : str,
    1.23 +    'fda': str,
    1.24 +    'fdb': str,
    1.25 +    'keymap': str,
    1.26 +    'isa' : int,
    1.27 +    'localtime': int,
    1.28 +    'monitor': int,
    1.29 +    'nographic': int,
    1.30 +    'pae' : int,
    1.31 +    'rtc_timeoffset': int,
    1.32 +    'serial': str,
    1.33 +    'sdl': int,
    1.34 +    'soundhw': str,
    1.35 +    'stdvga': int,
    1.36 +    'usb': int,
    1.37 +    'usbdevice': str,
    1.38 +    'hpet': int,
    1.39 +    'vnc': int,
    1.40 +    'vncconsole': int,
    1.41 +    'vncdisplay': int,
    1.42 +    'vnclisten': str,
    1.43 +    'timer_mode': int,
    1.44 +    'vncpasswd': str,
    1.45 +    'vncunused': int,
    1.46 +    'xauthority': str,
    1.47 +    'pci': str,
    1.48 +    'vhpt': int,
    1.49 +    'guest_os_type': str,
    1.50 +    'hap': int,
    1.51 +}
    1.52  
    1.53  # Xen API console 'other_config' keys.
    1.54  XENAPI_CONSOLE_OTHER_CFG = ['vncunused', 'vncdisplay', 'vnclisten',
    1.55 @@ -540,7 +569,7 @@ class XendConfig(dict):
    1.56              cfg['platform']['localtime'] = localtime
    1.57  
    1.58          # Compatibility hack -- can go soon.
    1.59 -        for key in XENAPI_PLATFORM_CFG:
    1.60 +        for key in XENAPI_PLATFORM_CFG_TYPES.keys():
    1.61              val = sxp.child_value(sxp_cfg, "platform_" + key, None)
    1.62              if val is not None:
    1.63                  self['platform'][key] = val
    1.64 @@ -719,7 +748,7 @@ class XendConfig(dict):
    1.65              self.update_with_image_sxp(image_sxp)
    1.66  
    1.67          # Convert Legacy HVM parameters to Xen API configuration
    1.68 -        for key in XENAPI_PLATFORM_CFG:
    1.69 +        for key in XENAPI_PLATFORM_CFG_TYPES.keys():
    1.70              if key in cfg:
    1.71                  self['platform'][key] = cfg[key]
    1.72  
    1.73 @@ -769,7 +798,7 @@ class XendConfig(dict):
    1.74              if image_type != 'hvm' and image_type != 'linux':
    1.75                  self['platform']['image_type'] = image_type
    1.76              
    1.77 -            for key in XENAPI_PLATFORM_CFG:
    1.78 +            for key in XENAPI_PLATFORM_CFG_TYPES.keys():
    1.79                  val = sxp.child_value(image_sxp, key, None)
    1.80                  if val is not None and val != '':
    1.81                      self['platform'][key] = val
    1.82 @@ -853,6 +882,19 @@ class XendConfig(dict):
    1.83                  self[key] = type_conv(val)
    1.84              else:
    1.85                  self[key] = val
    1.86 +
    1.87 +        # XenAPI defines platform as a string-string map.  If platform
    1.88 +        # configuration exists, convert values to appropriate type.
    1.89 +        if 'platform' in xapi:
    1.90 +            for key, val in xapi['platform'].items():
    1.91 +                type_conv = XENAPI_PLATFORM_CFG_TYPES.get(key)
    1.92 +                if type_conv is None:
    1.93 +                    key = key.lower()
    1.94 +                    type_conv = XENAPI_PLATFORM_CFG_TYPES.get(key)
    1.95 +                    if callable(type_conv):
    1.96 +                        self['platform'][key] = type_conv(val)
    1.97 +                    else:
    1.98 +                        self['platform'][key] = val
    1.99                  
   1.100          self['vcpus_params']['weight'] = \
   1.101              int(self['vcpus_params'].get('weight', 256))
   1.102 @@ -1531,7 +1573,7 @@ class XendConfig(dict):
   1.103          if self.has_key('PV_args') and self['PV_args']:
   1.104              image.append(['args', self['PV_args']])
   1.105  
   1.106 -        for key in XENAPI_PLATFORM_CFG:
   1.107 +        for key in XENAPI_PLATFORM_CFG_TYPES.keys():
   1.108              if key in self['platform']:
   1.109                  image.append([key, self['platform'][key]])
   1.110  
   1.111 @@ -1567,7 +1609,7 @@ class XendConfig(dict):
   1.112              self['PV_ramdisk'] = sxp.child_value(image_sxp, 'ramdisk','')
   1.113              self['PV_args'] = kernel_args
   1.114  
   1.115 -        for key in XENAPI_PLATFORM_CFG:
   1.116 +        for key in XENAPI_PLATFORM_CFG_TYPES.keys():
   1.117              val = sxp.child_value(image_sxp, key, None)
   1.118              if val is not None and val != '':
   1.119                  self['platform'][key] = val