All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jim Fehlig <jfehlig@novell.com>
To: xen-devel <xen-devel@lists.xensource.com>
Subject: [PATCH] Convert XenAPI platform values to appropriate type
Date: Thu, 13 Mar 2008 15:28:21 -0600	[thread overview]
Message-ID: <47D99C75.8040005@novell.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 521 bytes --]

XenAPI defines the platform attribute of a VM as a string-string map but
in various code paths in xend the platform entries are expected to be
another type, e.g. int.  This patch defines the types of each platform
entry and converts the entry values to appropriate type when new domU
configuration is created via XenAPI.

Alternatively the values could be casted to appropriate type when used
but seems prudent to do the conversion when domU configuration is created.

    Signed-off-by: Jim Fehlig <jfehlig@novell.com>


[-- Attachment #2: xenapi-platform-types.diff --]
[-- Type: text/x-patch, Size: 4619 bytes --]

diff -r 9de888d39804 tools/python/xen/xend/XendConfig.py
--- a/tools/python/xen/xend/XendConfig.py	Thu Mar 13 15:09:50 2008 -0600
+++ b/tools/python/xen/xend/XendConfig.py	Thu Mar 13 15:17:51 2008 -0600
@@ -123,14 +123,43 @@ XENAPI_CFG_TO_LEGACY_CFG = {
 
 LEGACY_CFG_TO_XENAPI_CFG = reverse_dict(XENAPI_CFG_TO_LEGACY_CFG)
 
-# Platform configuration keys.
-XENAPI_PLATFORM_CFG = [ 'acpi', 'apic', 'boot', 'device_model', 'loader', 'display', 
-                        'fda', 'fdb', 'keymap', 'isa', 'localtime', 'monitor', 
-                        'nographic', 'pae', 'rtc_timeoffset', 'serial', 'sdl',
-                        'soundhw','stdvga', 'usb', 'usbdevice', 'hpet', 'vnc',
-                        'vncconsole', 'vncdisplay', 'vnclisten', 'timer_mode',
-                        'vncpasswd', 'vncunused', 'xauthority', 'pci', 'vhpt',
-                        'guest_os_type', 'hap']
+# Platform configuration keys and their types.
+XENAPI_PLATFORM_CFG_TYPES = {
+    'acpi': int,
+    'apic': int,
+    'boot': str,
+    'device_model': str,
+    'loader': str,
+    'display' : str,
+    'fda': str,
+    'fdb': str,
+    'keymap': str,
+    'isa' : int,
+    'localtime': int,
+    'monitor': int,
+    'nographic': int,
+    'pae' : int,
+    'rtc_timeoffset': int,
+    'serial': str,
+    'sdl': int,
+    'soundhw': str,
+    'stdvga': int,
+    'usb': int,
+    'usbdevice': str,
+    'hpet': int,
+    'vnc': int,
+    'vncconsole': int,
+    'vncdisplay': int,
+    'vnclisten': str,
+    'timer_mode': int,
+    'vncpasswd': str,
+    'vncunused': int,
+    'xauthority': str,
+    'pci': str,
+    'vhpt': int,
+    'guest_os_type': str,
+    'hap': int,
+}
 
 # Xen API console 'other_config' keys.
 XENAPI_CONSOLE_OTHER_CFG = ['vncunused', 'vncdisplay', 'vnclisten',
@@ -540,7 +569,7 @@ class XendConfig(dict):
             cfg['platform']['localtime'] = localtime
 
         # Compatibility hack -- can go soon.
-        for key in XENAPI_PLATFORM_CFG:
+        for key in XENAPI_PLATFORM_CFG_TYPES.keys():
             val = sxp.child_value(sxp_cfg, "platform_" + key, None)
             if val is not None:
                 self['platform'][key] = val
@@ -719,7 +748,7 @@ class XendConfig(dict):
             self.update_with_image_sxp(image_sxp)
 
         # Convert Legacy HVM parameters to Xen API configuration
-        for key in XENAPI_PLATFORM_CFG:
+        for key in XENAPI_PLATFORM_CFG_TYPES.keys():
             if key in cfg:
                 self['platform'][key] = cfg[key]
 
@@ -769,7 +798,7 @@ class XendConfig(dict):
             if image_type != 'hvm' and image_type != 'linux':
                 self['platform']['image_type'] = image_type
             
-            for key in XENAPI_PLATFORM_CFG:
+            for key in XENAPI_PLATFORM_CFG_TYPES.keys():
                 val = sxp.child_value(image_sxp, key, None)
                 if val is not None and val != '':
                     self['platform'][key] = val
@@ -853,6 +882,19 @@ class XendConfig(dict):
                 self[key] = type_conv(val)
             else:
                 self[key] = val
+
+        # XenAPI defines platform as a string-string map.  If platform
+        # configuration exists, convert values to appropriate type.
+        if 'platform' in xapi:
+            for key, val in xapi['platform'].items():
+                type_conv = XENAPI_PLATFORM_CFG_TYPES.get(key)
+                if type_conv is None:
+                    key = key.lower()
+                    type_conv = XENAPI_PLATFORM_CFG_TYPES.get(key)
+                    if callable(type_conv):
+                        self['platform'][key] = type_conv(val)
+                    else:
+                        self['platform'][key] = val
                 
         self['vcpus_params']['weight'] = \
             int(self['vcpus_params'].get('weight', 256))
@@ -1531,7 +1573,7 @@ class XendConfig(dict):
         if self.has_key('PV_args') and self['PV_args']:
             image.append(['args', self['PV_args']])
 
-        for key in XENAPI_PLATFORM_CFG:
+        for key in XENAPI_PLATFORM_CFG_TYPES.keys():
             if key in self['platform']:
                 image.append([key, self['platform'][key]])
 
@@ -1567,7 +1609,7 @@ class XendConfig(dict):
             self['PV_ramdisk'] = sxp.child_value(image_sxp, 'ramdisk','')
             self['PV_args'] = kernel_args
 
-        for key in XENAPI_PLATFORM_CFG:
+        for key in XENAPI_PLATFORM_CFG_TYPES.keys():
             val = sxp.child_value(image_sxp, key, None)
             if val is not None and val != '':
                 self['platform'][key] = val

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

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

                 reply	other threads:[~2008-03-13 21:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47D99C75.8040005@novell.com \
    --to=jfehlig@novell.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.