예제 #1
0
 def attach_volume(self, instance_name, device_path, mountpoint):
     """Attach volume storage to VM instance"""
     # Before we start, check that the VM exists
     vm_ref = VMHelper.lookup(self._session, instance_name)
     if vm_ref is None:
         raise exception.NotFound(_('Instance %s not found')
                                   % instance_name)
     # NOTE: No Resource Pool concept so far
     LOG.debug(_("Attach_volume: %(instance_name)s, %(device_path)s,"
             " %(mountpoint)s") % locals())
     # Create the iSCSI SR, and the PDB through which hosts access SRs.
     # But first, retrieve target info, like Host, IQN, LUN and SCSIID
     vol_rec = VolumeHelper.parse_volume_info(device_path, mountpoint)
     label = 'SR-%s' % vol_rec['volumeId']
     description = 'Disk-for:%s' % instance_name
     # Create SR
     sr_ref = VolumeHelper.create_iscsi_storage(self._session,
                                                      vol_rec,
                                                      label,
                                                      description)
     # Introduce VDI  and attach VBD to VM
     try:
         vdi_ref = VolumeHelper.introduce_vdi(self._session, sr_ref)
     except StorageError, exc:
         LOG.exception(exc)
         VolumeHelper.destroy_iscsi_storage(self._session, sr_ref)
         raise Exception(_('Unable to create VDI on SR %(sr_ref)s for'
                 ' instance %(instance_name)s') % locals())
예제 #2
0
파일: volumeops.py 프로젝트: septimius/nova
 def attach_volume(self, instance_name, device_path, mountpoint):
     """Attach volume storage to VM instance"""
     # Before we start, check that the VM exists
     vm_ref = VMHelper.lookup(self._session, instance_name)
     if vm_ref is None:
         raise exception.NotFound(
             _('Instance %s not found') % instance_name)
     # NOTE: No Resource Pool concept so far
     LOG.debug(
         _("Attach_volume: %(instance_name)s, %(device_path)s,"
           " %(mountpoint)s") % locals())
     # Create the iSCSI SR, and the PDB through which hosts access SRs.
     # But first, retrieve target info, like Host, IQN, LUN and SCSIID
     vol_rec = VolumeHelper.parse_volume_info(device_path, mountpoint)
     label = 'SR-%s' % vol_rec['volumeId']
     description = 'Disk-for:%s' % instance_name
     # Create SR
     sr_ref = VolumeHelper.create_iscsi_storage(self._session, vol_rec,
                                                label, description)
     # Introduce VDI  and attach VBD to VM
     try:
         vdi_ref = VolumeHelper.introduce_vdi(self._session, sr_ref)
     except StorageError, exc:
         LOG.exception(exc)
         VolumeHelper.destroy_iscsi_storage(self._session, sr_ref)
         raise Exception(
             _('Unable to create VDI on SR %(sr_ref)s for'
               ' instance %(instance_name)s') % locals())
예제 #3
0
파일: volumeops.py 프로젝트: xtoddx/nova
 def forget_sr(self, sr_uuid):
     sr_ref = VolumeHelper.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:
         VolumeHelper.forget_sr(self._session, sr_uuid)
     except StorageError, exc:
         LOG.exception(exc)
         raise exception.Error(_('Could not forget SR'))
예제 #4
0
 def forget_sr(self, sr_uuid):
     sr_ref = VolumeHelper.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:
         VolumeHelper.forget_sr(self._session, sr_uuid)
     except StorageError, exc:
         LOG.exception(exc)
         raise exception.Error(_('Could not forget SR'))
예제 #5
0
파일: volumeops.py 프로젝트: xtoddx/nova
 def introduce_sr(self, sr_uuid, label, params):
     LOG.debug(_("Introducing SR %s") % label)
     sr_ref = VolumeHelper.find_sr_by_uuid(self._session, sr_uuid)
     if sr_ref:
         LOG.debug(_('SR found in xapi database. No need to introduce'))
         return sr_ref
     sr_ref = VolumeHelper.introduce_sr(self._session, sr_uuid, label,
                                        params)
     if sr_ref is None:
         raise exception.Error(_('Could not introduce SR'))
     return sr_ref
예제 #6
0
 def introduce_sr(self, sr_uuid, label, params):
     LOG.debug(_("Introducing SR %s") % label)
     sr_ref = VolumeHelper.find_sr_by_uuid(self._session, sr_uuid)
     if sr_ref:
         LOG.debug(_('SR found in xapi database. No need to introduce'))
         return sr_ref
     sr_ref = VolumeHelper.introduce_sr(self._session, sr_uuid, label,
                                        params)
     if sr_ref is None:
         raise exception.Error(_('Could not introduce SR'))
     return sr_ref
예제 #7
0
파일: volumeops.py 프로젝트: xtoddx/nova
 def create_sr(self, label, params):
     LOG.debug(_("Creating SR %s") % label)
     sr_ref = VolumeHelper.create_sr(self._session, label, params)
     if sr_ref is None:
         raise exception.Error(_('Could not create SR'))
     sr_rec = self._session.call_xenapi("SR.get_record", sr_ref)
     if sr_rec is None:
         raise exception.Error(_('Could not retrieve SR record'))
     return sr_rec['uuid']
예제 #8
0
 def create_sr(self, label, params):
     LOG.debug(_("Creating SR %s") % label)
     sr_ref = VolumeHelper.create_sr(self._session, label, params)
     if sr_ref is None:
         raise exception.Error(_('Could not create SR'))
     sr_rec = self._session.call_xenapi("SR.get_record", sr_ref)
     if sr_rec is None:
         raise exception.Error(_('Could not retrieve SR record'))
     return sr_rec['uuid']
예제 #9
0
 def detach_volume(self, instance_name, mountpoint):
     """Detach volume storage to VM instance"""
     # Before we start, check that the VM exists
     vm_ref = VMHelper.lookup(self._session, instance_name)
     if vm_ref is None:
         raise exception.InstanceNotFound(instance_id=instance_name)
     # Detach VBD from VM
     LOG.debug(_("Detach_volume: %(instance_name)s, %(mountpoint)s") % locals())
     device_number = VolumeHelper.mountpoint_to_number(mountpoint)
     try:
         vbd_ref = VMHelper.find_vbd_by_number(self._session, vm_ref, device_number)
     except StorageError, exc:
         LOG.exception(exc)
         raise Exception(_("Unable to locate volume %s") % mountpoint)
예제 #10
0
파일: volumeops.py 프로젝트: xtoddx/nova
 def detach_volume(self, connection_info, instance_name, mountpoint):
     """Detach volume storage to VM instance"""
     # Before we start, check that the VM exists
     vm_ref = VMHelper.lookup(self._session, instance_name)
     if vm_ref is None:
         raise exception.InstanceNotFound(instance_id=instance_name)
     # Detach VBD from VM
     LOG.debug(
         _("Detach_volume: %(instance_name)s, %(mountpoint)s") % locals())
     device_number = VolumeHelper.mountpoint_to_number(mountpoint)
     try:
         vbd_ref = VMHelper.find_vbd_by_number(self._session, vm_ref,
                                               device_number)
     except StorageError, exc:
         LOG.exception(exc)
         raise Exception(_('Unable to locate volume %s') % mountpoint)
예제 #11
0
파일: volumeops.py 프로젝트: xtoddx/nova
    def attach_volume(self, connection_info, instance_name, mountpoint):
        """Attach volume storage to VM instance"""
        # Before we start, check that the VM exists
        vm_ref = VMHelper.lookup(self._session, instance_name)
        if vm_ref is None:
            raise exception.InstanceNotFound(instance_id=instance_name)
        # NOTE: No Resource Pool concept so far
        LOG.debug(
            _("Attach_volume: %(connection_info)s, %(instance_name)s,"
              " %(mountpoint)s") % locals())
        driver_type = connection_info['driver_volume_type']
        if driver_type not in ['iscsi', 'xensm']:
            raise exception.VolumeDriverNotFound(driver_type=driver_type)

        data = connection_info['data']
        if 'name_label' not in data:
            label = 'tempSR-%s' % data['volume_id']
        else:
            label = data['name_label']
            del data['name_label']

        if 'name_description' not in data:
            desc = 'Disk-for:%s' % instance_name
        else:
            desc = data['name_description']

        LOG.debug(connection_info)
        sr_params = {}
        if u'sr_uuid' not in data:
            sr_params = VolumeHelper.parse_volume_info(connection_info,
                                                       mountpoint)
            uuid = "FA15E-D15C-" + str(sr_params['id'])
            sr_params['sr_type'] = 'iscsi'
        else:
            uuid = data['sr_uuid']
            for k in data['introduce_sr_keys']:
                sr_params[k] = data[k]

        sr_params['name_description'] = desc

        # Introduce SR
        try:
            sr_ref = self.introduce_sr(uuid, label, sr_params)
            LOG.debug(_('Introduced %(label)s as %(sr_ref)s.') % locals())
        except self.XenAPI.Failure, exc:
            LOG.exception(exc)
            raise StorageError(_('Unable to introduce Storage Repository'))
예제 #12
0
    def attach_volume(self, connection_info, instance_name, mountpoint):
        """Attach volume storage to VM instance"""
        # Before we start, check that the VM exists
        vm_ref = VMHelper.lookup(self._session, instance_name)
        if vm_ref is None:
            raise exception.InstanceNotFound(instance_id=instance_name)
        # NOTE: No Resource Pool concept so far
        LOG.debug(_("Attach_volume: %(connection_info)s, %(instance_name)s,"
                " %(mountpoint)s") % locals())
        driver_type = connection_info['driver_volume_type']
        if driver_type not in ['iscsi', 'xensm']:
            raise exception.VolumeDriverNotFound(driver_type=driver_type)

        data = connection_info['data']
        if 'name_label' not in data:
            label = 'tempSR-%s' % data['volume_id']
        else:
            label = data['name_label']
            del data['name_label']

        if 'name_description' not in data:
            desc = 'Disk-for:%s' % instance_name
        else:
            desc = data['name_description']

        LOG.debug(connection_info)
        sr_params = {}
        if u'sr_uuid' not in data:
            sr_params = VolumeHelper.parse_volume_info(connection_info,
                                                       mountpoint)
            uuid = "FA15E-D15C-" + str(sr_params['id'])
            sr_params['sr_type'] = 'iscsi'
        else:
            uuid = data['sr_uuid']
            for k in data['introduce_sr_keys']:
                sr_params[k] = data[k]

        sr_params['name_description'] = desc

        # Introduce SR
        try:
            sr_ref = self.introduce_sr(uuid, label, sr_params)
            LOG.debug(_('Introduced %(label)s as %(sr_ref)s.') % locals())
        except self.XenAPI.Failure, exc:
            LOG.exception(exc)
            raise StorageError(_('Unable to introduce Storage Repository'))
예제 #13
0
            LOG.exception(exc)
            raise StorageError(_('Unable to introduce Storage Repository'))

        vdi_uuid = None
        target_lun = None
        if 'vdi_uuid' in data:
            vdi_uuid = data['vdi_uuid']
        elif 'target_lun' in data:
            target_lun = data['target_lun']
        else:
            vdi_uuid = None

        # Introduce VDI  and attach VBD to VM
        try:
            vdi_ref = VolumeHelper.introduce_vdi(self._session, sr_ref,
                                                 vdi_uuid,
                                                 target_lun)
        except StorageError, exc:
            LOG.exception(exc)
            self.forget_sr(uuid)
            raise Exception(_('Unable to create VDI on SR %(sr_ref)s for'
                    ' instance %(instance_name)s') % locals())

        dev_number = VolumeHelper.mountpoint_to_number(mountpoint)
        try:
            vbd_ref = VolumeHelper.create_vbd(self._session,
                                              vm_ref,
                                              vdi_ref,
                                              dev_number,
                                              False)
        except self.XenAPI.Failure, exc:
예제 #14
0
파일: volumeops.py 프로젝트: septimius/nova
 # Introduce VDI  and attach VBD to VM
 try:
     vdi_ref = VolumeHelper.introduce_vdi(self._session, sr_ref)
 except StorageError, exc:
     LOG.exception(exc)
     VolumeHelper.destroy_iscsi_storage(self._session, sr_ref)
     raise Exception(
         _('Unable to create VDI on SR %(sr_ref)s for'
           ' instance %(instance_name)s') % locals())
 else:
     try:
         vbd_ref = VMHelper.create_vbd(self._session, vm_ref, vdi_ref,
                                       vol_rec['deviceNumber'], False)
     except self.XenAPI.Failure, exc:
         LOG.exception(exc)
         VolumeHelper.destroy_iscsi_storage(self._session, sr_ref)
         raise Exception(
             _('Unable to use SR %(sr_ref)s for'
               ' instance %(instance_name)s') % locals())
     else:
         try:
             task = self._session.call_xenapi('Async.VBD.plug', vbd_ref)
             self._session.wait_for_task(task, vol_rec['deviceNumber'])
         except self.XenAPI.Failure, exc:
             LOG.exception(exc)
             VolumeHelper.destroy_iscsi_storage(self._session, sr_ref)
             raise Exception(
                 _('Unable to attach volume to instance %s') %
                 instance_name)
 LOG.info(
     _('Mountpoint %(mountpoint)s attached to'
예제 #15
0
        description = "Disk-for:%s" % instance_name
        # Create SR
        sr_ref = VolumeHelper.create_iscsi_storage(self._session, vol_rec, label, description)
        # Introduce VDI  and attach VBD to VM
        try:
            vdi_ref = VolumeHelper.introduce_vdi(self._session, sr_ref)
        except StorageError, exc:
            LOG.exception(exc)
            VolumeHelper.destroy_iscsi_storage(self._session, sr_ref)
            raise Exception(_("Unable to create VDI on SR %(sr_ref)s for" " instance %(instance_name)s") % locals())
        else:
            try:
                vbd_ref = VMHelper.create_vbd(self._session, vm_ref, vdi_ref, vol_rec["deviceNumber"], False)
            except self.XenAPI.Failure, exc:
                LOG.exception(exc)
                VolumeHelper.destroy_iscsi_storage(self._session, sr_ref)
                raise Exception(_("Unable to use SR %(sr_ref)s for" " instance %(instance_name)s") % locals())
            else:
                try:
                    task = self._session.call_xenapi("Async.VBD.plug", vbd_ref)
                    self._session.wait_for_task(task, vol_rec["deviceNumber"])
                except self.XenAPI.Failure, exc:
                    LOG.exception(exc)
                    VolumeHelper.destroy_iscsi_storage(self._session, sr_ref)
                    raise Exception(_("Unable to attach volume to instance %s") % instance_name)
        LOG.info(_("Mountpoint %(mountpoint)s attached to" " instance %(instance_name)s") % locals())

    def detach_volume(self, instance_name, mountpoint):
        """Detach volume storage to VM instance"""
        # Before we start, check that the VM exists
        vm_ref = VMHelper.lookup(self._session, instance_name)
예제 #16
0
 def is_sr_on_host(self, sr_uuid):
     LOG.debug(_('Checking for SR %s') % sr_uuid)
     sr_ref = VolumeHelper.find_sr_by_uuid(self._session, sr_uuid)
     if sr_ref:
         return True
     return False
예제 #17
0
파일: volumeops.py 프로젝트: xtoddx/nova
 def is_sr_on_host(self, sr_uuid):
     LOG.debug(_('Checking for SR %s') % sr_uuid)
     sr_ref = VolumeHelper.find_sr_by_uuid(self._session, sr_uuid)
     if sr_ref:
         return True
     return False
예제 #18
0
파일: volumeops.py 프로젝트: xtoddx/nova
        # Introduce SR
        try:
            sr_ref = self.introduce_sr(uuid, label, sr_params)
            LOG.debug(_('Introduced %(label)s as %(sr_ref)s.') % locals())
        except self.XenAPI.Failure, exc:
            LOG.exception(exc)
            raise StorageError(_('Unable to introduce Storage Repository'))

        if 'vdi_uuid' in data:
            vdi_uuid = data['vdi_uuid']
        else:
            vdi_uuid = None

        # Introduce VDI  and attach VBD to VM
        try:
            vdi_ref = VolumeHelper.introduce_vdi(self._session, sr_ref,
                                                 vdi_uuid)
        except StorageError, exc:
            LOG.exception(exc)
            self.forget_sr(uuid)
            raise Exception(
                _('Unable to create VDI on SR %(sr_ref)s for'
                  ' instance %(instance_name)s') % locals())

        dev_number = VolumeHelper.mountpoint_to_number(mountpoint)
        try:
            vbd_ref = VolumeHelper.create_vbd(self._session, vm_ref, vdi_ref,
                                              dev_number, False)
        except self.XenAPI.Failure, exc:
            LOG.exception(exc)
            self.forget_sr(uuid)
            raise Exception(