direct-io.hg

changeset 12786:93314655b16f

[XEND] Make SXP parsing re-use device_add in XendConfig

This will fix the IP address configuration problem for vifs.

Signed-off-by: Alastair Tse <atse@xensource.com>
author Alastair Tse <atse@xensource.com>
date Thu Dec 07 14:40:13 2006 +0000 (2006-12-07)
parents dcca88fc849c
children 1d83974d08b1 61883e3168a6
files tools/python/xen/xend/XendConfig.py
line diff
     1.1 --- a/tools/python/xen/xend/XendConfig.py	Thu Dec 07 14:38:16 2006 +0000
     1.2 +++ b/tools/python/xen/xend/XendConfig.py	Thu Dec 07 14:40:13 2006 +0000
     1.3 @@ -509,14 +509,8 @@ class XendConfig(dict):
     1.4                  
     1.5                  log.debug("XendConfig: reading device: %s" % pci_devs)
     1.6              else:
     1.7 -                for opt, val in config[1:]:
     1.8 -                    dev_info[opt] = val
     1.9 +                self.device_add(dev_type, cfg_sxp = config, target = cfg)
    1.10                  log.debug("XendConfig: reading device: %s" % scrub_password(dev_info))
    1.11 -                # create uuid if it doesn't
    1.12 -                dev_uuid = dev_info.get('uuid', uuid.createString())
    1.13 -                dev_info['uuid'] = dev_uuid
    1.14 -                cfg['devices'][dev_uuid] = (dev_type, dev_info)
    1.15 -
    1.16  
    1.17          # Extract missing data from configuration entries
    1.18          image_sxp = sxp.child_value(sxp_cfg, 'image', [])
    1.19 @@ -867,7 +861,8 @@ class XendConfig(dict):
    1.20  
    1.21          return sxpr    
    1.22      
    1.23 -    def device_add(self, dev_type, cfg_sxp = None, cfg_xenapi = None):
    1.24 +    def device_add(self, dev_type, cfg_sxp = None, cfg_xenapi = None,
    1.25 +                   target = None):
    1.26          """Add a device configuration in SXP format or XenAPI struct format.
    1.27  
    1.28          For SXP, it could be either:
    1.29 @@ -882,9 +877,14 @@ class XendConfig(dict):
    1.30          @param cfg_sxp: SXP configuration object
    1.31          @type cfg_xenapi: dict
    1.32          @param cfg_xenapi: A device configuration from Xen API (eg. vbd,vif)
    1.33 +        @param target: write device information to
    1.34 +        @type target: None or a dictionary
    1.35          @rtype: string
    1.36          @return: Assigned UUID of the device.
    1.37          """
    1.38 +        if target == None:
    1.39 +            target = self
    1.40 +        
    1.41          if dev_type not in XendDevices.valid_devices() and \
    1.42             dev_type not in XendDevices.pseudo_devices():        
    1.43              raise XendConfigError("XendConfig: %s not a valid device type" %
    1.44 @@ -914,15 +914,18 @@ class XendConfig(dict):
    1.45              except ValueError:
    1.46                  pass # SXP has no options for this device
    1.47  
    1.48 -            
    1.49 -            def _get_config_ipaddr(config):
    1.50 +
    1.51 +            # Special handling for certain device parameters.
    1.52 +
    1.53 +            def _get_config_ipaddr(cfg):
    1.54                  val = []
    1.55 -                for ipaddr in sxp.children(config, elt='ip'):
    1.56 +                for ipaddr in sxp.children(cfg, elt='ip'):
    1.57                      val.append(sxp.child0(ipaddr))
    1.58                  return val
    1.59  
    1.60              if dev_type == 'vif' and 'ip' in dev_info:
    1.61                  dev_info['ip'] = _get_config_ipaddr(config)
    1.62 +                log.debug('XendConfig: IP Address: %s' % dev_info['ip'])
    1.63  
    1.64              if dev_type == 'vbd':
    1.65                  if dev_info.get('dev', '').startswith('ioemu:'):
    1.66 @@ -936,11 +939,18 @@ class XendConfig(dict):
    1.67              dev_info['uuid'] = dev_uuid
    1.68  
    1.69              # store dev references by uuid for certain device types
    1.70 -            self['devices'][dev_uuid] = (dev_type, dev_info)
    1.71 +            target['devices'][dev_uuid] = (dev_type, dev_info)
    1.72              if dev_type in ('vif', 'vbd', 'vtpm'):
    1.73 -                self['%s_refs' % dev_type].append(dev_uuid)
    1.74 +                param = '%s_refs' % dev_type
    1.75 +                if param not in target:
    1.76 +                    target[param] = []
    1.77 +                if dev_uuid in target[param]:
    1.78 +                    target[param].append(dev_uuid)
    1.79              elif dev_type in ('tap',):
    1.80 -                self['vbd_refs'].append(dev_uuid)
    1.81 +                if 'vbd_refs' not in target:
    1.82 +                    target['vbd_refs'] = []
    1.83 +                if dev_uuid in target['vbd_refs']:
    1.84 +                    target['vbd_refs'].append(dev_uuid)
    1.85  
    1.86              return dev_uuid
    1.87