def _attach_volume(self, connection_info, vm_ref=None, instance_name=None, dev_number=None, hotplug=False): self._check_is_supported_driver_type(connection_info) connection_data = connection_info['data'] sr_ref, sr_uuid = self._connect_to_volume_provider(connection_data, instance_name) try: vdi_ref = self._connect_hypervisor_to_volume(sr_ref, connection_data) vdi_uuid = self._session.VDI.get_uuid(vdi_ref) LOG.info(_('Connected volume (vdi_uuid): %s'), vdi_uuid) if vm_ref: self._attach_volume_to_vm(vdi_ref, vm_ref, instance_name, dev_number, hotplug) return (sr_uuid, vdi_uuid) except Exception: with excutils.save_and_reraise_exception(): # NOTE(sirp): Forgetting the SR will have the effect of # cleaning up the VDI and VBD records, so no need to handle # that explicitly. volume_utils.forget_sr(self._session, sr_ref)
def _attach_volume(self, connection_info, vm_ref=None, instance_name=None, dev_number=None, hotplug=False): self._check_is_supported_driver_type(connection_info) connection_data = connection_info['data'] sr_ref, sr_uuid = self._connect_to_volume_provider(connection_data, instance_name) try: vdi_ref = self._connect_hypervisor_to_volume(sr_ref, connection_data) vdi_uuid = self._session.VDI.get_uuid(vdi_ref) LOG.info(_LI('Connected volume (vdi_uuid): %s'), vdi_uuid) if vm_ref: self._attach_volume_to_vm(vdi_ref, vm_ref, instance_name, dev_number, hotplug) return (sr_uuid, vdi_uuid) except Exception: with excutils.save_and_reraise_exception(): # NOTE(sirp): Forgetting the SR will have the effect of # cleaning up the VDI and VBD records, so no need to handle # that explicitly. volume_utils.forget_sr(self._session, sr_ref)
def _connect_volume(self, connection_data, dev_number, instance_name, vm_ref, hotplug=True): sr_uuid, sr_label, sr_params = volume_utils.parse_sr_info(connection_data, "Disk-for:%s" % instance_name) # Introduce SR if not already present sr_ref = volume_utils.find_sr_by_uuid(self._session, sr_uuid) if not sr_ref: sr_ref = volume_utils.introduce_sr(self._session, sr_uuid, sr_label, sr_params) try: # Introduce VDI if "vdi_uuid" in connection_data: vdi_ref = volume_utils.introduce_vdi(self._session, sr_ref, vdi_uuid=connection_data["vdi_uuid"]) elif "target_lun" in connection_data: vdi_ref = volume_utils.introduce_vdi(self._session, sr_ref, target_lun=connection_data["target_lun"]) else: # NOTE(sirp): This will introduce the first VDI in the SR vdi_ref = volume_utils.introduce_vdi(self._session, sr_ref) # Attach vbd_ref = vm_utils.create_vbd(self._session, vm_ref, vdi_ref, dev_number, bootable=False, osvol=True) if hotplug: self._session.call_xenapi("VBD.plug", vbd_ref) except Exception: with excutils.save_and_reraise_exception(): # NOTE(sirp): Forgetting the SR will have the effect of # cleaning up the VDI and VBD records, so no need to handle # that explicitly. volume_utils.forget_sr(self._session, sr_ref)
def _connect_volume(self, connection_info, dev_number=None, instance_name=None, vm_ref=None, hotplug=True): driver_type = connection_info['driver_volume_type'] if driver_type not in ['iscsi', 'xensm']: raise exception.VolumeDriverNotFound(driver_type=driver_type) connection_data = connection_info['data'] sr_uuid, sr_label, sr_params = volume_utils.parse_sr_info( connection_data, 'Disk-for:%s' % instance_name) # Introduce SR if not already present sr_ref = volume_utils.find_sr_by_uuid(self._session, sr_uuid) if not sr_ref: sr_ref = volume_utils.introduce_sr(self._session, sr_uuid, sr_label, sr_params) try: # Introduce VDI if 'vdi_uuid' in connection_data: vdi_ref = volume_utils.introduce_vdi( self._session, sr_ref, vdi_uuid=connection_data['vdi_uuid']) elif 'target_lun' in connection_data: vdi_ref = volume_utils.introduce_vdi( self._session, sr_ref, target_lun=connection_data['target_lun']) else: # NOTE(sirp): This will introduce the first VDI in the SR vdi_ref = volume_utils.introduce_vdi(self._session, sr_ref) # Attach if vm_ref: vbd_ref = vm_utils.create_vbd(self._session, vm_ref, vdi_ref, dev_number, bootable=False, osvol=True) running = not vm_utils.is_vm_shutdown(self._session, vm_ref) if hotplug and running: volume_utils.vbd_plug(self._session, vbd_ref, vm_ref) vdi_uuid = self._session.call_xenapi("VDI.get_uuid", vdi_ref) return (sr_uuid, vdi_uuid) except Exception: with excutils.save_and_reraise_exception(): # NOTE(sirp): Forgetting the SR will have the effect of # cleaning up the VDI and VBD records, so no need to handle # that explicitly. volume_utils.forget_sr(self._session, sr_ref)
def forget_sr(self, sr_uuid): sr_ref = volume_utils.find_sr_by_uuid(self._session, sr_uuid) if sr_ref is None: LOG.INFO(_('SR %s not found in the xapi database') % sr_uuid) return try: volume_utils.forget_sr(self._session, sr_uuid) except volume_utils.StorageError, exc: LOG.exception(exc) raise exception.NovaException(_('Could not forget SR'))
def _connect_volume(self, connection_info, dev_number=None, instance_name=None, vm_ref=None, hotplug=True): driver_type = connection_info['driver_volume_type'] if driver_type not in ['iscsi', 'xensm']: raise exception.VolumeDriverNotFound(driver_type=driver_type) connection_data = connection_info['data'] sr_uuid, sr_label, sr_params = volume_utils.parse_sr_info( connection_data, 'Disk-for:%s' % instance_name) # Introduce SR if not already present sr_ref = volume_utils.find_sr_by_uuid(self._session, sr_uuid) if not sr_ref: sr_ref = volume_utils.introduce_sr( self._session, sr_uuid, sr_label, sr_params) try: # Introduce VDI if 'vdi_uuid' in connection_data: vdi_ref = volume_utils.introduce_vdi( self._session, sr_ref, vdi_uuid=connection_data['vdi_uuid']) elif 'target_lun' in connection_data: vdi_ref = volume_utils.introduce_vdi( self._session, sr_ref, target_lun=connection_data['target_lun']) else: # NOTE(sirp): This will introduce the first VDI in the SR vdi_ref = volume_utils.introduce_vdi(self._session, sr_ref) # Attach if vm_ref: vbd_ref = vm_utils.create_vbd(self._session, vm_ref, vdi_ref, dev_number, bootable=False, osvol=True) running = not vm_utils.is_vm_shutdown(self._session, vm_ref) if hotplug and running: self._session.VBD.plug(vbd_ref, vm_ref) vdi_uuid = self._session.call_xenapi("VDI.get_uuid", vdi_ref) return (sr_uuid, vdi_uuid) except Exception: with excutils.save_and_reraise_exception(): # NOTE(sirp): Forgetting the SR will have the effect of # cleaning up the VDI and VBD records, so no need to handle # that explicitly. volume_utils.forget_sr(self._session, sr_ref)
def _connect_volume(self, connection_data, dev_number, instance_name, vm_ref, hotplug=True): sr_uuid, sr_label, sr_params = volume_utils.parse_sr_info( connection_data, 'Disk-for:%s' % instance_name) # Introduce SR if not already present sr_ref = volume_utils.find_sr_by_uuid(self._session, sr_uuid) if not sr_ref: sr_ref = volume_utils.introduce_sr(self._session, sr_uuid, sr_label, sr_params) try: # Introduce VDI if 'vdi_uuid' in connection_data: vdi_ref = volume_utils.introduce_vdi( self._session, sr_ref, vdi_uuid=connection_data['vdi_uuid']) elif 'target_lun' in connection_data: vdi_ref = volume_utils.introduce_vdi( self._session, sr_ref, target_lun=connection_data['target_lun']) else: # NOTE(sirp): This will introduce the first VDI in the SR vdi_ref = volume_utils.introduce_vdi(self._session, sr_ref) # Attach vbd_ref = vm_utils.create_vbd(self._session, vm_ref, vdi_ref, dev_number, bootable=False, osvol=True) if hotplug: self._session.call_xenapi("VBD.plug", vbd_ref) except Exception: with excutils.save_and_reraise_exception(): # NOTE(sirp): Forgetting the SR will have the effect of # cleaning up the VDI and VBD records, so no need to handle # that explicitly. volume_utils.forget_sr(self._session, sr_ref)