debuggers.hg
changeset 13653:3bb7136c8fb4
[XEND] Fix HVM guest creation via Xen API
Fixed some of the type declarations for HVM devices, add better
handling for type mismatch errors.
Signed-off-by: Alastair Tse <atse@xensource.com>
Fixed some of the type declarations for HVM devices, add better
handling for type mismatch errors.
Signed-off-by: Alastair Tse <atse@xensource.com>
author | Alastair Tse <atse@xensource.com> |
---|---|
date | Thu Jan 25 18:50:08 2007 +0000 (2007-01-25) |
parents | 1abb694a52df |
children | b111908dd70b |
files | tools/python/xen/xend/XendConfig.py tools/python/xen/xend/image.py |
line diff
1.1 --- a/tools/python/xen/xend/XendConfig.py Thu Jan 25 18:23:48 2007 +0000 1.2 +++ b/tools/python/xen/xend/XendConfig.py Thu Jan 25 18:50:08 2007 +0000 1.3 @@ -125,7 +125,6 @@ XENAPI_HVM_CFG = { 1.4 'platform_std_vga': 'stdvga', 1.5 'platform_serial' : 'serial', 1.6 'platform_localtime': 'localtime', 1.7 - 'platform_enable_audio': 'soundhw', 1.8 'platform_keymap' : 'keymap', 1.9 } 1.10 1.11 @@ -268,17 +267,19 @@ LEGACY_IMAGE_HVM_DEVICES_CFG = [ 1.12 ('boot', str), 1.13 ('fda', str), 1.14 ('fdb', str), 1.15 - ('isa', str), 1.16 + ('isa', int), 1.17 ('keymap', str), 1.18 - ('localtime', str), 1.19 + ('localtime', int), 1.20 ('serial', str), 1.21 ('stdvga', int), 1.22 ('soundhw', str), 1.23 - ('usb', str), 1.24 + ('usb', int), 1.25 ('usbdevice', str), 1.26 ('vcpus', int), 1.27 ] 1.28 1.29 +LEGACY_DM = '/usr/lib/xen/bin/qemu-dm' 1.30 + 1.31 ## 1.32 ## Config Choices 1.33 ## 1.34 @@ -748,10 +749,19 @@ class XendConfig(dict): 1.35 hvm = self['HVM_boot'] != '' 1.36 self['image']['type'] = hvm and 'hvm' or 'linux' 1.37 if hvm: 1.38 - self['image']['hvm'] = {} 1.39 + self['image']['hvm'] = {'devices': {}} 1.40 for xapi, cfgapi in XENAPI_HVM_CFG.items(): 1.41 - self['image']['hvm'][cfgapi] = self[xapi] 1.42 - 1.43 + if xapi in self: 1.44 + self['image']['hvm']['devices'][cfgapi] = self[xapi] 1.45 + 1.46 + # currently unsupported options 1.47 + self['image']['hvm']['device_model'] = LEGACY_DM 1.48 + self['image']['vnc'] = 1 1.49 + self['image']['hvm']['pae'] = 1 1.50 + 1.51 + if self['platform_enable_audio']: 1.52 + self['image']['hvm']['devices']['soundhw'] = 'sb16' 1.53 + 1.54 1.55 def _get_old_state_string(self): 1.56 """Returns the old xm state string. 1.57 @@ -965,7 +975,8 @@ class XendConfig(dict): 1.58 return dev_uuid 1.59 1.60 if cfg_xenapi: 1.61 - dev_info = {} 1.62 + dev_info = {} 1.63 + dev_uuid = '' 1.64 if dev_type == 'vif': 1.65 if cfg_xenapi.get('MAC'): # don't add if blank 1.66 dev_info['mac'] = cfg_xenapi.get('MAC') 1.67 @@ -983,7 +994,6 @@ class XendConfig(dict): 1.68 dev_info['uuid'] = dev_uuid 1.69 target['devices'][dev_uuid] = (dev_type, dev_info) 1.70 target['vif_refs'].append(dev_uuid) 1.71 - return dev_uuid 1.72 1.73 elif dev_type in ('vbd', 'tap'): 1.74 dev_info['type'] = cfg_xenapi.get('type', 'Disk') 1.75 @@ -1007,7 +1017,6 @@ class XendConfig(dict): 1.76 dev_info['uuid'] = dev_uuid 1.77 target['devices'][dev_uuid] = (dev_type, dev_info) 1.78 target['vbd_refs'].append(dev_uuid) 1.79 - return dev_uuid 1.80 1.81 elif dev_type == 'vtpm': 1.82 if cfg_xenapi.get('type'): 1.83 @@ -1017,9 +1026,12 @@ class XendConfig(dict): 1.84 dev_info['uuid'] = dev_uuid 1.85 target['devices'][dev_uuid] = (dev_type, dev_info) 1.86 target['vtpm_refs'].append(dev_uuid) 1.87 - return dev_uuid 1.88 + 1.89 + return dev_uuid 1.90 1.91 + # no valid device to add 1.92 return '' 1.93 + 1.94 1.95 def device_update(self, dev_uuid, cfg_sxp): 1.96 """Update an existing device with the new configuration. 1.97 @@ -1117,13 +1129,18 @@ class XendConfig(dict): 1.98 if 'hvm' in self['image']: 1.99 for arg, conv in LEGACY_IMAGE_HVM_CFG: 1.100 if self['image']['hvm'].get(arg): 1.101 - image.append([arg, self['image']['hvm'][arg]]) 1.102 + image.append([arg, conv(self['image']['hvm'][arg])]) 1.103 1.104 if 'hvm' in self['image'] and 'devices' in self['image']['hvm']: 1.105 for arg, conv in LEGACY_IMAGE_HVM_DEVICES_CFG: 1.106 - if self['image']['hvm']['devices'].get(arg): 1.107 - image.append([arg, 1.108 - self['image']['hvm']['devices'][arg]]) 1.109 + val = self['image']['hvm']['devices'].get(arg) 1.110 + if val != None: 1.111 + try: 1.112 + if conv: val = conv(val) 1.113 + except (ValueError, TypeError): 1.114 + if type(val) == bool: val = int(val) 1.115 + 1.116 + image.append([arg, val]) 1.117 1.118 return image 1.119 1.120 @@ -1172,7 +1189,11 @@ class XendConfig(dict): 1.121 for arg, conv in LEGACY_IMAGE_HVM_DEVICES_CFG: 1.122 val = sxp.child_value(image_sxp, arg, None) 1.123 if val != None: 1.124 - image_hvm_devices[arg] = conv(val) 1.125 + try: 1.126 + image_hvm_devices[arg] = conv(val) 1.127 + except (ValueError, TypeError): 1.128 + image_hvm_devices[arg] = val 1.129 + 1.130 1.131 if image_hvm or image_hvm_devices: 1.132 image['hvm'] = image_hvm 1.133 @@ -1189,6 +1210,7 @@ class XendConfig(dict): 1.134 else: 1.135 self[apikey] = val 1.136 1.137 + 1.138 1.139 # 1.140 # debugging
2.1 --- a/tools/python/xen/xend/image.py Thu Jan 25 18:23:48 2007 +0000 2.2 +++ b/tools/python/xen/xend/image.py Thu Jan 25 18:50:08 2007 +0000 2.3 @@ -392,8 +392,11 @@ class HVMImageHandler(ImageHandler): 2.4 2.5 # Handle booleans gracefully 2.6 if a in ['localtime', 'std-vga', 'isa', 'usb', 'acpi']: 2.7 - if v != None: v = int(v) 2.8 - if v: ret.append("-%s" % a) 2.9 + try: 2.10 + if v != None: v = int(v) 2.11 + if v: ret.append("-%s" % a) 2.12 + except (ValueError, TypeError): 2.13 + pass # if we can't convert it to a sane type, ignore it 2.14 else: 2.15 if v: 2.16 ret.append("-%s" % a)