WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] [XEND] Proper importing of Xen API VM Str

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] [XEND] Proper importing of Xen API VM Struct into new XendConfig
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Sun, 03 Dec 2006 15:10:36 +0000
Delivery-date: Sun, 03 Dec 2006 07:12:14 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Alastair Tse <atse@xxxxxxxxxxxxx>
# Node ID e3d62983bc2fa15131143f019a8eaa06b3f3b0fc
# Parent  dc9a47212ac4bb6fd98715ceca51122edf7511ac
[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@xxxxxxxxxxxxx>
---
 tools/python/xen/xend/XendConfig.py |   35 +++++++++++++++++++++++++++++++++--
 1 files changed, 33 insertions(+), 2 deletions(-)

diff -r dc9a47212ac4 -r e3d62983bc2f tools/python/xen/xend/XendConfig.py
--- a/tools/python/xen/xend/XendConfig.py       Fri Dec 01 17:21:19 2006 +0000
+++ b/tools/python/xen/xend/XendConfig.py       Fri Dec 01 17:30:39 2006 +0000
@@ -106,7 +106,7 @@ XENAPI_CFG_TYPES = {
     'platform_clock_offset': bool0,
     'platform_enable_audio': bool0,
     'platform_keymap': str,
-    'boot_method': int,
+    'boot_method': str,
     'builder': str,
     'kernel_kernel': str,
     'kernel_initrd': str,
@@ -263,7 +263,7 @@ class XendConfig(dict):
             self._sxp_to_xapi(sxp_obj)
             self._sxp_to_xapi_unsupported(sxp_obj)
         elif xapi:
-            self.update(xapi)
+            self.update_with_xenapi_config(xapi)
             self._add_xapi_unsupported()
         elif dominfo:
             # output from xc.domain_getinfo
@@ -273,6 +273,21 @@ class XendConfig(dict):
 
         # validators go here
         self.validate()
+
+    """ In time, we should enable this type checking addition. It is great
+        also for tracking bugs and unintended writes to XendDomainInfo.info
+    def __setitem__(self, key, value):
+        type_conv = XENAPI_CFG_TYPES.get(key)
+        if callable(type_conv):
+            try:
+                dict.__setitem__(self, key, type_conv(value))
+            except (ValueError, TypeError):
+                raise XendConfigError("Wrong type for configuration value " +
+                                      "%s. Expected %s" %
+                                      (key, type_conv.__name__))
+        else:
+            dict.__setitem__(self, key, value)
+    """
 
     def _defaults(self):
         defaults = {
@@ -715,6 +730,22 @@ class XendConfig(dict):
         self._dominfo_to_xapi(dominfo)
         self.validate()
 
+    def update_with_xenapi_config(self, xapi):
+        """Update configuration with a Xen API VM struct
+
+        @param xapi: Xen API VM Struct
+        @type xapi: dict
+        """
+        for key, val in xapi.items():
+            key = key.lower()
+            type_conv = XENAPI_CFG_TYPES.get(key)
+            if callable(type_conv):
+                self[key] = type_conv(val)
+            else:
+                self[key] = val
+
+        self.validate()
+
     def to_xml(self):
         """Return an XML string representing the configuration."""
         pass

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] [XEND] Proper importing of Xen API VM Struct into new XendConfig, Xen patchbot-unstable <=