# HG changeset patch
# User Ewan Mellor <ewan@xxxxxxxxxxxxx>
# Date 1170353736 0
# Node ID e0b7ab2a1d5677ba95a3f2c29eb083fc248357e2
# Parent b32a44bfb10ccd23cd6ac71883cea65fb4c7b1a0
Treat the empty string as an absent UUID, not an invalid one. Fix to_sxp
wrt dictionaries.
Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>
---
tools/python/xen/xend/XendConfig.py | 46 +++++++++++++++++++++++++-----------
1 files changed, 32 insertions(+), 14 deletions(-)
diff -r b32a44bfb10c -r e0b7ab2a1d56 tools/python/xen/xend/XendConfig.py
--- a/tools/python/xen/xend/XendConfig.py Thu Feb 01 18:14:40 2007 +0000
+++ b/tools/python/xen/xend/XendConfig.py Thu Feb 01 18:15:36 2007 +0000
@@ -146,7 +146,7 @@ XENAPI_CFG_TYPES = {
'memory_actual': int,
'cpus': list,
'vcpus_policy': str,
- 'vcpus_params': str,
+ 'vcpus_params': dict,
'vcpus_number': int,
'vcpus_features_required': list,
'vcpus_features_can_use': list,
@@ -349,7 +349,6 @@ class XendConfig(dict):
def _defaults(self):
defaults = {
- 'uuid': uuid.createString(),
'name_label': 'Domain-Unnamed',
'actions_after_shutdown': 'destroy',
'actions_after_reboot': 'restart',
@@ -385,7 +384,6 @@ class XendConfig(dict):
'other_config': {},
}
- defaults['name_label'] = 'Domain-' + defaults['uuid']
return defaults
def _memory_sanity_check(self):
@@ -415,13 +413,21 @@ class XendConfig(dict):
def _uuid_sanity_check(self):
"""Make sure UUID is in proper string format with hyphens."""
- self['uuid'] = uuid.toString(uuid.fromString(self['uuid']))
+ if 'uuid' not in self or not self['uuid']:
+ self['uuid'] = uuid.createString()
+ else:
+ self['uuid'] = uuid.toString(uuid.fromString(self['uuid']))
+
+ def _name_sanity_check(self):
+ if 'name_label' not in self:
+ self['name_label'] = 'Domain-' + self['uuid']
def validate(self):
+ self._uuid_sanity_check()
+ self._name_sanity_check()
self._memory_sanity_check()
self._actions_sanity_check()
self._vcpus_sanity_check()
- self._uuid_sanity_check()
def _dominfo_to_xapi(self, dominfo):
self['domid'] = dominfo['domid']
@@ -840,8 +846,6 @@ class XendConfig(dict):
else:
self[key] = val
- self.validate()
-
def to_sxp(self, domain = None, ignore_devices = False, ignore = [],
legacy_only = True):
""" Get SXP representation of this config object.
@@ -865,9 +869,13 @@ class XendConfig(dict):
sxpr.append(['domid', domain.getDomid()])
if not legacy_only:
- for name in XENAPI_CFG_TYPES.keys():
+ for name, typ in XENAPI_CFG_TYPES.items():
if name in self and self[name] not in (None, []):
- sxpr.append([name, str(self[name])])
+ if typ == dict:
+ s = self[name].items()
+ else:
+ s = str(self[name])
+ sxpr.append([name, s])
for xenapi, legacy in XENAPI_CFG_TO_LEGACY_CFG.items():
if self.has_key(xenapi) and self[xenapi] not in (None, []):
@@ -996,7 +1004,9 @@ class XendConfig(dict):
dev_info['driver'] = 'paravirtualised'
# create uuid if it doesn't exist
- dev_uuid = dev_info.get('uuid', uuid.createString())
+ dev_uuid = dev_info.get('uuid', None)
+ if not dev_uuid:
+ dev_uuid = uuid.createString()
dev_info['uuid'] = dev_uuid
# store dev references by uuid for certain device types
@@ -1066,7 +1076,9 @@ class XendConfig(dict):
if cfg_xenapi.get('name'):
dev_info['name'] = cfg_xenapi.get('name')
- dev_uuid = cfg_xenapi.get('uuid', uuid.createString())
+ dev_uuid = cfg_xenapi.get('uuid', None)
+ if not dev_uuid:
+ dev_uuid = uuid.createString()
dev_info['uuid'] = dev_uuid
target['devices'][dev_uuid] = (dev_type, dev_info)
target['vif_refs'].append(dev_uuid)
@@ -1090,7 +1102,9 @@ class XendConfig(dict):
else:
dev_info['mode'] = 'r'
- dev_uuid = cfg_xenapi.get('uuid', uuid.createString())
+ dev_uuid = cfg_xenapi.get('uuid', None)
+ if not dev_uuid:
+ dev_uuid = uuid.createString()
dev_info['uuid'] = dev_uuid
target['devices'][dev_uuid] = (dev_type, dev_info)
target['vbd_refs'].append(dev_uuid)
@@ -1099,13 +1113,17 @@ class XendConfig(dict):
if cfg_xenapi.get('type'):
dev_info['type'] = cfg_xenapi.get('type')
- dev_uuid = cfg_xenapi.get('uuid', uuid.createString())
+ dev_uuid = cfg_xenapi.get('uuid', None)
+ if not dev_uuid:
+ dev_uuid = uuid.createString()
dev_info['uuid'] = dev_uuid
target['devices'][dev_uuid] = (dev_type, dev_info)
target['vtpm_refs'].append(dev_uuid)
elif dev_type == 'console':
- dev_uuid = cfg_xenapi.get('uuid', uuid.createString())
+ dev_uuid = cfg_xenapi.get('uuid', None)
+ if not dev_uuid:
+ dev_uuid = uuid.createString()
dev_info['uuid'] = dev_uuid
dev_info['protocol'] = cfg_xenapi.get('protocol', 'rfb')
dev_info['other_config'] = cfg_xenapi.get('other_config', {})
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|