ia64/xen-unstable
changeset 12757:e3d62983bc2f
[XEND] Proper importing of Xen API VM Struct into new XendConfig
Use a smarter method of importing the Xen API VM struct when adding to
XendConfig.
Also add a commented __setitem__ override for XendConfig to type check
certain configuration values.
Signed-off-by: Alastair Tse <atse@xensource.com>
Use a smarter method of importing the Xen API VM struct when adding to
XendConfig.
Also add a commented __setitem__ override for XendConfig to type check
certain configuration values.
Signed-off-by: Alastair Tse <atse@xensource.com>
author | Alastair Tse <atse@xensource.com> |
---|---|
date | Fri Dec 01 17:30:39 2006 +0000 (2006-12-01) |
parents | dc9a47212ac4 |
children | 5d0efb6f3983 |
files | tools/python/xen/xend/XendConfig.py |
line diff
1.1 --- a/tools/python/xen/xend/XendConfig.py Fri Dec 01 17:21:19 2006 +0000 1.2 +++ b/tools/python/xen/xend/XendConfig.py Fri Dec 01 17:30:39 2006 +0000 1.3 @@ -106,7 +106,7 @@ XENAPI_CFG_TYPES = { 1.4 'platform_clock_offset': bool0, 1.5 'platform_enable_audio': bool0, 1.6 'platform_keymap': str, 1.7 - 'boot_method': int, 1.8 + 'boot_method': str, 1.9 'builder': str, 1.10 'kernel_kernel': str, 1.11 'kernel_initrd': str, 1.12 @@ -263,7 +263,7 @@ class XendConfig(dict): 1.13 self._sxp_to_xapi(sxp_obj) 1.14 self._sxp_to_xapi_unsupported(sxp_obj) 1.15 elif xapi: 1.16 - self.update(xapi) 1.17 + self.update_with_xenapi_config(xapi) 1.18 self._add_xapi_unsupported() 1.19 elif dominfo: 1.20 # output from xc.domain_getinfo 1.21 @@ -274,6 +274,21 @@ class XendConfig(dict): 1.22 # validators go here 1.23 self.validate() 1.24 1.25 + """ In time, we should enable this type checking addition. It is great 1.26 + also for tracking bugs and unintended writes to XendDomainInfo.info 1.27 + def __setitem__(self, key, value): 1.28 + type_conv = XENAPI_CFG_TYPES.get(key) 1.29 + if callable(type_conv): 1.30 + try: 1.31 + dict.__setitem__(self, key, type_conv(value)) 1.32 + except (ValueError, TypeError): 1.33 + raise XendConfigError("Wrong type for configuration value " + 1.34 + "%s. Expected %s" % 1.35 + (key, type_conv.__name__)) 1.36 + else: 1.37 + dict.__setitem__(self, key, value) 1.38 + """ 1.39 + 1.40 def _defaults(self): 1.41 defaults = { 1.42 'uuid': uuid.createString(), 1.43 @@ -715,6 +730,22 @@ class XendConfig(dict): 1.44 self._dominfo_to_xapi(dominfo) 1.45 self.validate() 1.46 1.47 + def update_with_xenapi_config(self, xapi): 1.48 + """Update configuration with a Xen API VM struct 1.49 + 1.50 + @param xapi: Xen API VM Struct 1.51 + @type xapi: dict 1.52 + """ 1.53 + for key, val in xapi.items(): 1.54 + key = key.lower() 1.55 + type_conv = XENAPI_CFG_TYPES.get(key) 1.56 + if callable(type_conv): 1.57 + self[key] = type_conv(val) 1.58 + else: 1.59 + self[key] = val 1.60 + 1.61 + self.validate() 1.62 + 1.63 def to_xml(self): 1.64 """Return an XML string representing the configuration.""" 1.65 pass