ia64/xen-unstable

changeset 13820:e0b7ab2a1d56

Treat the empty string as an absent UUID, not an invalid one. Fix to_sxp
wrt dictionaries.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Thu Feb 01 18:15:36 2007 +0000 (2007-02-01)
parents b32a44bfb10c
children 23bf61e72279
files tools/python/xen/xend/XendConfig.py
line diff
     1.1 --- a/tools/python/xen/xend/XendConfig.py	Thu Feb 01 18:14:40 2007 +0000
     1.2 +++ b/tools/python/xen/xend/XendConfig.py	Thu Feb 01 18:15:36 2007 +0000
     1.3 @@ -146,7 +146,7 @@ XENAPI_CFG_TYPES = {
     1.4      'memory_actual': int,
     1.5      'cpus': list,
     1.6      'vcpus_policy': str,
     1.7 -    'vcpus_params': str,
     1.8 +    'vcpus_params': dict,
     1.9      'vcpus_number': int,
    1.10      'vcpus_features_required': list,
    1.11      'vcpus_features_can_use': list,
    1.12 @@ -349,7 +349,6 @@ class XendConfig(dict):
    1.13  
    1.14      def _defaults(self):
    1.15          defaults = {
    1.16 -            'uuid': uuid.createString(),
    1.17              'name_label': 'Domain-Unnamed',
    1.18              'actions_after_shutdown': 'destroy',
    1.19              'actions_after_reboot': 'restart',
    1.20 @@ -385,7 +384,6 @@ class XendConfig(dict):
    1.21              'other_config': {},
    1.22          }
    1.23          
    1.24 -        defaults['name_label'] = 'Domain-' + defaults['uuid']
    1.25          return defaults
    1.26  
    1.27      def _memory_sanity_check(self):
    1.28 @@ -415,13 +413,21 @@ class XendConfig(dict):
    1.29  
    1.30      def _uuid_sanity_check(self):
    1.31          """Make sure UUID is in proper string format with hyphens."""
    1.32 -        self['uuid'] = uuid.toString(uuid.fromString(self['uuid']))
    1.33 +        if 'uuid' not in self or not self['uuid']:
    1.34 +            self['uuid'] = uuid.createString()
    1.35 +        else:
    1.36 +            self['uuid'] = uuid.toString(uuid.fromString(self['uuid']))
    1.37 +
    1.38 +    def _name_sanity_check(self):
    1.39 +        if 'name_label' not in self:
    1.40 +            self['name_label'] = 'Domain-' + self['uuid']
    1.41  
    1.42      def validate(self):
    1.43 +        self._uuid_sanity_check()
    1.44 +        self._name_sanity_check()
    1.45          self._memory_sanity_check()
    1.46          self._actions_sanity_check()
    1.47          self._vcpus_sanity_check()
    1.48 -        self._uuid_sanity_check()
    1.49  
    1.50      def _dominfo_to_xapi(self, dominfo):
    1.51          self['domid'] = dominfo['domid']
    1.52 @@ -840,8 +846,6 @@ class XendConfig(dict):
    1.53              else:
    1.54                  self[key] = val
    1.55  
    1.56 -        self.validate()
    1.57 -
    1.58      def to_sxp(self, domain = None, ignore_devices = False, ignore = [],
    1.59                 legacy_only = True):
    1.60          """ Get SXP representation of this config object.
    1.61 @@ -865,9 +869,13 @@ class XendConfig(dict):
    1.62              sxpr.append(['domid', domain.getDomid()])
    1.63  
    1.64          if not legacy_only:
    1.65 -            for name in XENAPI_CFG_TYPES.keys():
    1.66 +            for name, typ in XENAPI_CFG_TYPES.items():
    1.67                  if name in self and self[name] not in (None, []):
    1.68 -                    sxpr.append([name, str(self[name])])
    1.69 +                    if typ == dict:
    1.70 +                        s = self[name].items()
    1.71 +                    else:
    1.72 +                        s = str(self[name])
    1.73 +                    sxpr.append([name, s])
    1.74  
    1.75          for xenapi, legacy in XENAPI_CFG_TO_LEGACY_CFG.items():
    1.76              if self.has_key(xenapi) and self[xenapi] not in (None, []):
    1.77 @@ -996,7 +1004,9 @@ class XendConfig(dict):
    1.78                      dev_info['driver'] = 'paravirtualised'
    1.79  
    1.80              # create uuid if it doesn't exist
    1.81 -            dev_uuid = dev_info.get('uuid', uuid.createString())
    1.82 +            dev_uuid = dev_info.get('uuid', None)
    1.83 +            if not dev_uuid:
    1.84 +                dev_uuid = uuid.createString()
    1.85              dev_info['uuid'] = dev_uuid
    1.86  
    1.87              # store dev references by uuid for certain device types
    1.88 @@ -1066,7 +1076,9 @@ class XendConfig(dict):
    1.89                  if cfg_xenapi.get('name'):
    1.90                      dev_info['name'] = cfg_xenapi.get('name')
    1.91                  
    1.92 -                dev_uuid = cfg_xenapi.get('uuid', uuid.createString())
    1.93 +                dev_uuid = cfg_xenapi.get('uuid', None)
    1.94 +                if not dev_uuid:
    1.95 +                    dev_uuid = uuid.createString()
    1.96                  dev_info['uuid'] = dev_uuid
    1.97                  target['devices'][dev_uuid] = (dev_type, dev_info)
    1.98                  target['vif_refs'].append(dev_uuid)
    1.99 @@ -1090,7 +1102,9 @@ class XendConfig(dict):
   1.100                  else:
   1.101                      dev_info['mode'] = 'r'
   1.102  
   1.103 -                dev_uuid = cfg_xenapi.get('uuid', uuid.createString())
   1.104 +                dev_uuid = cfg_xenapi.get('uuid', None)
   1.105 +                if not dev_uuid:
   1.106 +                    dev_uuid = uuid.createString()
   1.107                  dev_info['uuid'] = dev_uuid
   1.108                  target['devices'][dev_uuid] = (dev_type, dev_info)
   1.109                  target['vbd_refs'].append(dev_uuid)                
   1.110 @@ -1099,13 +1113,17 @@ class XendConfig(dict):
   1.111                  if cfg_xenapi.get('type'):
   1.112                      dev_info['type'] = cfg_xenapi.get('type')
   1.113  
   1.114 -                dev_uuid = cfg_xenapi.get('uuid', uuid.createString())
   1.115 +                dev_uuid = cfg_xenapi.get('uuid', None)
   1.116 +                if not dev_uuid:
   1.117 +                    dev_uuid = uuid.createString()
   1.118                  dev_info['uuid'] = dev_uuid
   1.119                  target['devices'][dev_uuid] = (dev_type, dev_info)
   1.120                  target['vtpm_refs'].append(dev_uuid)
   1.121  
   1.122              elif dev_type == 'console':
   1.123 -                dev_uuid = cfg_xenapi.get('uuid', uuid.createString())
   1.124 +                dev_uuid = cfg_xenapi.get('uuid', None)
   1.125 +                if not dev_uuid:
   1.126 +                    dev_uuid = uuid.createString()
   1.127                  dev_info['uuid'] = dev_uuid
   1.128                  dev_info['protocol'] = cfg_xenapi.get('protocol', 'rfb')
   1.129                  dev_info['other_config'] = cfg_xenapi.get('other_config', {})