ia64/xen-unstable

changeset 12744:d0ade847f886

[XEND] Ensure config value types in XendConfig

Add definitions of what we expect the types to be for the values in
XendConfig and apply them when parsing SXP where all values are either
strings or list.

Also fix missing stdvga in HVM config.

Signed-off-by: Alastair Tse <atse@xensource.com>
author Alastair Tse <atse@xensource.com>
date Fri Dec 01 13:53:04 2006 +0000 (2006-12-01)
parents b334f479853e
children ef1dadde3631
files tools/python/xen/xend/XendConfig.py
line diff
     1.1 --- a/tools/python/xen/xend/XendConfig.py	Fri Dec 01 13:44:33 2006 +0000
     1.2 +++ b/tools/python/xen/xend/XendConfig.py	Fri Dec 01 13:53:04 2006 +0000
     1.3 @@ -39,6 +39,9 @@ def reverse_dict(adict):
     1.4      """Return the reverse mapping of a dictionary."""
     1.5      return dict([(v, k) for k, v in adict.items()])
     1.6  
     1.7 +def bool0(v):
     1.8 +    return v != '0' and bool(v)
     1.9 +
    1.10  # Mapping from XendConfig configuration keys to the old
    1.11  # legacy configuration keys that map directly.
    1.12  
    1.13 @@ -60,7 +63,7 @@ LEGACY_CFG_TO_XENAPI_CFG = reverse_dict(
    1.14  # legacy configuration keys that are found in the 'image'
    1.15  # SXP object.
    1.16  XENAPI_HVM_CFG = {
    1.17 -    'platform_std_vga': 'std-vga',
    1.18 +    'platform_std_vga': 'stdvga',
    1.19      'platform_serial' : 'serial',
    1.20      'platform_localtime': 'localtime',
    1.21      'platform_enable_audio': 'soundhw',
    1.22 @@ -70,33 +73,49 @@ XENAPI_HVM_CFG = {
    1.23  # List of XendConfig configuration keys that have no equivalent
    1.24  # in the old world.
    1.25  
    1.26 -XENAPI_UNSUPPORTED_BY_LEGACY_CFG = [
    1.27 -    'name_description',
    1.28 -    'user_version',
    1.29 -    'is_a_template',
    1.30 -    'memory_dynamic_min',
    1.31 -    'memory_dynamic_max',
    1.32 -    'memory_actual',
    1.33 -    'vcpus_policy',
    1.34 -    'vcpus_params',
    1.35 -    'vcpus_features_required',
    1.36 -    'vcpus_features_can_use',
    1.37 -    'vcpus_features_force_on',
    1.38 -    'vcpus_features_force_off',
    1.39 -    'actions_after_suspend',
    1.40 -    'bios_boot',
    1.41 -    'platform_std_vga',
    1.42 -    'platform_serial',
    1.43 -    'platform_localtime',
    1.44 -    'platform_clock_offset',
    1.45 -    'platform_enable_audio',
    1.46 -    'platform_keymap',
    1.47 -    'boot_method',
    1.48 -    'builder',
    1.49 -    'grub_cmdline',
    1.50 -    'pci_bus',
    1.51 -    'otherconfig'
    1.52 -]
    1.53 +XENAPI_CFG_TYPES = {
    1.54 +    'uuid': str,
    1.55 +    'power_state': int,
    1.56 +    'name_label': str,
    1.57 +    'name_description': str,
    1.58 +    'user_version': str,
    1.59 +    'is_a_template': int,
    1.60 +    'resident_on': str,
    1.61 +    'memory_static_min': int,
    1.62 +    'memory_static_max': int,
    1.63 +    'memory_dynamic_min': int,
    1.64 +    'memory_dynamic_max': int,
    1.65 +    'memory_actual': int,
    1.66 +    'vcpus_policy': str,
    1.67 +    'vcpus_params': str,
    1.68 +    'vcpus_number': int,
    1.69 +    'vcpus_features_required': list,
    1.70 +    'vcpus_features_can_use': list,
    1.71 +    'vcpus_features_force_on': list, 
    1.72 +    'vcpus_features_force_off': list,
    1.73 +    'actions_after_shutdown': str,
    1.74 +    'actions_after_reboot': str,
    1.75 +    'actions_after_suspend': str,
    1.76 +    'actions_after_crash': str,
    1.77 +    'tpm_instance': int,
    1.78 +    'tpm_backend': int,    
    1.79 +    'bios_boot': str,
    1.80 +    'platform_std_vga': bool0,
    1.81 +    'platform_serial': str,
    1.82 +    'platform_localtime': bool0,
    1.83 +    'platform_clock_offset': bool0,
    1.84 +    'platform_enable_audio': bool0,
    1.85 +    'platform_keymap': str,
    1.86 +    'boot_method': int,
    1.87 +    'builder': str,
    1.88 +    'kernel_kernel': str,
    1.89 +    'kernel_initrd': str,
    1.90 +    'kernel_args': str,
    1.91 +    'grub_cmdline': str,
    1.92 +    'pci_bus': str,
    1.93 +    'tools_version': dict,
    1.94 +    'otherconfig': dict,
    1.95 +}
    1.96  
    1.97  # List of legacy configuration keys that have no equivalent in the
    1.98  # Xen API, but are still stored in XendConfig.
    1.99 @@ -146,6 +165,7 @@ LEGACY_CFG_TYPES = {
   1.100      'on_crash':    str,
   1.101      'on_xend_stop': str,
   1.102      'on_xend_start': str,
   1.103 +    'online_vcpus': int,
   1.104  }
   1.105  
   1.106  # Values that should be stored in xenstore's /vm/<uuid> that is used
   1.107 @@ -203,23 +223,6 @@ LEGACY_IMAGE_HVM_DEVICES_CFG = [
   1.108      ('vcpus', int),
   1.109  ]
   1.110  
   1.111 -
   1.112 -
   1.113 -# configuration params that need to be converted to ints
   1.114 -# since the XMLRPC transport for Xen API does not use
   1.115 -# 32 bit ints but string representation of 64 bit ints.
   1.116 -XENAPI_INT_CFG = [
   1.117 -    'user_version',
   1.118 -    'vcpus_number',
   1.119 -    'memory_static_min',
   1.120 -    'memory_static_max',
   1.121 -    'memory_dynamic_min',
   1.122 -    'memory_dynamic_max',
   1.123 -    'memory_actual',
   1.124 -    'tpm_instance',
   1.125 -    'tpm_backend',
   1.126 -]    
   1.127 -
   1.128  ##
   1.129  ## Config Choices
   1.130  ##
   1.131 @@ -532,7 +535,12 @@ class XendConfig(dict):
   1.132          
   1.133          for apikey, cfgkey in XENAPI_CFG_TO_LEGACY_CFG.items():
   1.134              try:
   1.135 -                self[apikey] = LEGACY_CFG_TYPES[cfgkey](cfg[cfgkey])
   1.136 +                type_conv = XENAPI_CFG_TYPES.get(apikey)
   1.137 +                if callable(type_conv):
   1.138 +                    self[apikey] = type_conv(cfg[cfgkey])
   1.139 +                else:
   1.140 +                    log.warn("Unconverted key: " + apikey)
   1.141 +                    self[apikey] = cfg[cfgkey]
   1.142              except KeyError:
   1.143                  pass
   1.144  
   1.145 @@ -555,10 +563,10 @@ class XendConfig(dict):
   1.146              self['kernel_args'] = kernel_args
   1.147  
   1.148          # Convert Legacy HVM parameters to Xen API configuration
   1.149 -        self['platform_std_vga'] = cfg.get('std-vga', 0)
   1.150 -        self['platform_serial'] = cfg.get('serial', '')
   1.151 -        self['platform_localtime'] = cfg.get('localtime', 0)
   1.152 -        self['platform_enable_audio'] = cfg.get('soundhw', 0)
   1.153 +        self['platform_std_vga'] = bool0(cfg.get('stdvga', 0))
   1.154 +        self['platform_serial'] = str(cfg.get('serial', ''))
   1.155 +        self['platform_localtime'] = bool0(cfg.get('localtime', 0))
   1.156 +        self['platform_enable_audio'] = bool0(cfg.get('soundhw', 0))
   1.157  
   1.158          # Convert path to bootloader to boot_method
   1.159          if not cfg.get('bootloader'):
   1.160 @@ -733,7 +741,11 @@ class XendConfig(dict):
   1.161  
   1.162          for xenapi, legacy in XENAPI_CFG_TO_LEGACY_CFG.items():
   1.163              if self.has_key(xenapi) and self[xenapi] not in (None, []):
   1.164 -                sxpr.append([legacy, self[xenapi]])
   1.165 +                if type(self[xenapi]) == bool:
   1.166 +                    # convert booleans to ints before making an sxp item
   1.167 +                    sxpr.append([legacy, int(self[xenapi])])
   1.168 +                else:
   1.169 +                    sxpr.append([legacy, self[xenapi]])
   1.170  
   1.171          for legacy in LEGACY_UNSUPPORTED_BY_XENAPI_CFG:
   1.172              if legacy in ('domid', 'uuid'): # skip these
   1.173 @@ -1043,7 +1055,11 @@ class XendConfig(dict):
   1.174          for apikey, imgkey in XENAPI_HVM_CFG.items():
   1.175              val = sxp.child_value(image_sxp, imgkey, None)
   1.176              if val != None:
   1.177 -                self[apikey] = val        
   1.178 +                type_conv = XENAPI_CFG_TYPES[apikey]
   1.179 +                if callable(conv):
   1.180 +                    self[apikey] = type_conv(val)
   1.181 +                else:
   1.182 +                    self[apikey] = val
   1.183  
   1.184          
   1.185  #