ia64/xen-unstable

changeset 19332:99771e02b38a

xend: Allow replacement of a cdrom device on a device_add

When adding a device, allow a cd to replace another if the device is a
cdrom.

Signed-off by: Ryan Scott <ryan.scott@sun.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Mar 12 11:01:25 2009 +0000 (2009-03-12)
parents db53046ca5f0
children e2de0e760a0d
files tools/python/xen/xend/XendConfig.py
line diff
     1.1 --- a/tools/python/xen/xend/XendConfig.py	Thu Mar 12 11:00:52 2009 +0000
     1.2 +++ b/tools/python/xen/xend/XendConfig.py	Thu Mar 12 11:01:25 2009 +0000
     1.3 @@ -1155,7 +1155,7 @@ class XendConfig(dict):
     1.4                      return None
     1.5          return devid
     1.6      
     1.7 -    def device_duplicate_check(self, dev_type, dev_info, defined_config):
     1.8 +    def device_duplicate_check(self, dev_type, dev_info, defined_config, config):
     1.9          defined_devices_sxpr = self.all_devices_sxpr(target = defined_config)
    1.10          
    1.11          if dev_type == 'vbd' or dev_type == 'tap':
    1.12 @@ -1174,9 +1174,34 @@ class XendConfig(dict):
    1.13                          if blkdev_file == o_blkdev_file:
    1.14                              raise XendConfigError('The file "%s" is already used' %
    1.15                                                    blkdev_file)
    1.16 +                    if dev_uname == o_dev_uname:
    1.17 +                        raise XendConfigError('The uname "%s" is already defined' %
    1.18 +                                             dev_uname)
    1.19                      o_blkdev_name = sxp.child_value(o_dev_info, 'dev')
    1.20                      o_devid = self._blkdev_name_to_number(o_blkdev_name)
    1.21                      if o_devid != None and devid == o_devid:
    1.22 +                        name_array = blkdev_name.split(':', 2)
    1.23 +                        if len(name_array) == 2 and name_array[1] == 'cdrom':
    1.24 +                            #
    1.25 +                            # Since the device is a cdrom, we are most likely
    1.26 +                            # inserting, changing, or removing a cd.  We can
    1.27 +                            # update the old device instead of creating a new
    1.28 +                            # one.
    1.29 +                            #
    1.30 +                            if o_dev_uname != None and dev_uname == None:
    1.31 +                                #
    1.32 +                                # We are removing a cd.  We can simply update
    1.33 +                                # the uname on the existing device.
    1.34 +                                #
    1.35 +                                merge_sxp = sxp.from_string("('vbd' ('uname' ''))")
    1.36 +                            else:
    1.37 +                                merge_sxp = config
    1.38 +
    1.39 +                            dev_uuid = sxp.child_value(o_dev_info, 'uuid')
    1.40 +                            if dev_uuid != None and \
    1.41 +                               self.device_update(dev_uuid, cfg_sxp = merge_sxp):
    1.42 +                                return dev_uuid
    1.43 +
    1.44                          raise XendConfigError('The device "%s" is already defined' %
    1.45                                                blkdev_name)
    1.46                      
    1.47 @@ -1188,6 +1213,7 @@ class XendConfig(dict):
    1.48                      if dev_mac.lower() == sxp.child_value(o_dev_info, 'mac').lower():
    1.49                          raise XendConfigError('The mac "%s" is already defined' %
    1.50                                                dev_mac)
    1.51 +        return None
    1.52      
    1.53      def device_add(self, dev_type, cfg_sxp = None, cfg_xenapi = None,
    1.54                     target = None):
    1.55 @@ -1326,7 +1352,9 @@ class XendConfig(dict):
    1.56                  if not dev_info.get('mac'):
    1.57                      dev_info['mac'] = randomMAC()
    1.58  
    1.59 -            self.device_duplicate_check(dev_type, dev_info, target)
    1.60 +            ret_uuid = self.device_duplicate_check(dev_type, dev_info, target, config)
    1.61 +            if ret_uuid != None:
    1.62 +                return ret_uuid
    1.63  
    1.64              if dev_type == 'vif':
    1.65                  if dev_info.get('policy') and dev_info.get('label'):