예제 #1
0
    def attach_volume(self, connection_info, instance_name, mountpoint,
                      hotplug=True):
        """
        Attach volume storage to VM instance.
        """

        # NOTE: No Resource Pool concept so far
        LOG.debug(_('Attach_volume: %(connection_info)s, %(instance_name)s,'
                    '" %(mountpoint)s'),
                  {'connection_info': connection_info,
                   'instance_name': instance_name,
                   'mountpoint': mountpoint})

        dev_number = volume_utils.get_device_number(mountpoint)
        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)

        sr_uuid, vdi_uuid = self._connect_volume(connection_info, dev_number,
                                                 instance_name, vm_ref,
                                                 hotplug=hotplug)

        LOG.info(_('Mountpoint %(mountpoint)s attached to'
                   ' instance %(instance_name)s'),
                 {'instance_name': instance_name, 'mountpoint': mountpoint})

        return (sr_uuid, vdi_uuid)
예제 #2
0
    def attach_volume(self,
                      connection_info,
                      instance_name,
                      mountpoint,
                      hotplug=True):
        """Attach volume storage to VM instance."""

        vm_ref = vm_utils.vm_ref_or_raise(self._session, 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)

        connection_data = connection_info['data']
        dev_number = volume_utils.get_device_number(mountpoint)

        self._connect_volume(connection_data,
                             dev_number,
                             instance_name,
                             vm_ref,
                             hotplug=hotplug)

        LOG.info(
            _('Mountpoint %(mountpoint)s attached to'
              ' instance %(instance_name)s') % locals())
예제 #3
0
    def detach_volume(self, connection_info, instance_name, mountpoint):
        """Detach volume storage to VM instance."""
        LOG.debug("Detach_volume: %(instance_name)s, %(mountpoint)s", {
            'instance_name': instance_name,
            'mountpoint': mountpoint
        })

        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)

        device_number = volume_utils.get_device_number(mountpoint)
        vbd_ref = volume_utils.find_vbd_by_number(self._session, vm_ref,
                                                  device_number)

        if vbd_ref is None:
            # NOTE(sirp): If we don't find the VBD then it must have been
            # detached previously.
            LOG.warning(
                _LW('Skipping detach because VBD for %s was '
                    'not found'), instance_name)
        else:
            self._detach_vbds_and_srs(vm_ref, [vbd_ref])
            LOG.info(
                _LI('Mountpoint %(mountpoint)s detached from instance'
                    ' %(instance_name)s'), {
                        'instance_name': instance_name,
                        'mountpoint': mountpoint
                    })
예제 #4
0
    def detach_volume(self, connection_info, instance_name, mountpoint):
        """Detach volume storage to VM instance."""
        LOG.debug(
            _("Detach_volume: %(instance_name)s, %(mountpoint)s") % locals())

        device_number = volume_utils.get_device_number(mountpoint)
        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)

        try:
            vbd_ref = vm_utils.find_vbd_by_number(self._session, vm_ref,
                                                  device_number)
        except volume_utils.StorageError:
            # NOTE(sirp): If we don't find the VBD then it must have been
            # detached previously.
            LOG.warn(
                _('Skipping detach because VBD for %(instance_name)s was'
                  ' not found') % locals())
            return

        # Unplug VBD if we're NOT shutdown
        unplug = not vm_utils._is_vm_shutdown(self._session, vm_ref)
        self._detach_vbd(vbd_ref, unplug=unplug)

        LOG.info(
            _('Mountpoint %(mountpoint)s detached from instance'
              ' %(instance_name)s') % locals())
예제 #5
0
    def _attach_volume_to_vm(self, vdi_ref, vm_ref, instance_name, mountpoint,
                             hotplug):
        LOG.debug('Attach_volume vdi: %(vdi_ref)s vm: %(vm_ref)s', {
            'vdi_ref': vdi_ref,
            'vm_ref': vm_ref
        })

        dev_number = volume_utils.get_device_number(mountpoint)

        # osvol is added to the vbd so we can spot which vbds are volumes
        vbd_ref = vm_utils.create_vbd(self._session,
                                      vm_ref,
                                      vdi_ref,
                                      dev_number,
                                      bootable=False,
                                      osvol=True)
        if hotplug:
            # NOTE(johngarbutt) can only call VBD.plug on a running vm
            running = not vm_utils.is_vm_shutdown(self._session, vm_ref)
            if running:
                LOG.debug("Plugging VBD: %s", vbd_ref)
                self._session.VBD.plug(vbd_ref, vm_ref)

        LOG.info(
            _LI('Dev %(dev_number)s attached to'
                ' instance %(instance_name)s'), {
                    'instance_name': instance_name,
                    'dev_number': dev_number
                })
예제 #6
0
파일: volumeops.py 프로젝트: B-Rich/nova-1
 def _find_vbd(self, vm_ref, mountpoint):
     device_number = volume_utils.get_device_number(mountpoint)
     try:
         return vm_utils.find_vbd_by_number(
                 self._session, vm_ref, device_number)
     except exception.StorageError:
         return
예제 #7
0
파일: volumeops.py 프로젝트: B-Rich/nova-1
 def _find_vbd(self, vm_ref, mountpoint):
     device_number = volume_utils.get_device_number(mountpoint)
     try:
         return vm_utils.find_vbd_by_number(self._session, vm_ref,
                                            device_number)
     except exception.StorageError:
         return
예제 #8
0
    def attach_volume(self, connection_info, instance_name, mountpoint, hotplug=True):
        """Attach volume to VM instance."""
        # TODO(johngarbutt) move this into _attach_volume_to_vm
        dev_number = volume_utils.get_device_number(mountpoint)

        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)
        return self._attach_volume(connection_info, vm_ref, instance_name, dev_number, hotplug)
예제 #9
0
    def attach_volume(self, connection_info, instance_name, mountpoint,
                      hotplug=True):
        """Attach volume to VM instance."""
        # TODO(johngarbutt) move this into _attach_volume_to_vm
        dev_number = volume_utils.get_device_number(mountpoint)

        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)
        return self._attach_volume(connection_info, vm_ref,
                                   instance_name, dev_number, hotplug)
예제 #10
0
파일: volumeops.py 프로젝트: bihicheng/nova
    def detach_volume(self, connection_info, instance_name, mountpoint):
        """Detach volume storage to VM instance."""

        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)

        # Detach VBD from VM
        LOG.debug(_("Detach_volume: %(instance_name)s, %(mountpoint)s")
                % locals())
        device_number = volume_utils.get_device_number(mountpoint)
        try:
            vbd_ref = vm_utils.find_vbd_by_number(self._session, vm_ref,
                                                  device_number)
        except volume_utils.StorageError, exc:
            LOG.exception(exc)
            raise Exception(_('Unable to locate volume %s') % mountpoint)
예제 #11
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 = vm_utils.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)

        connection_data = connection_info['data']
        dev_number = volume_utils.get_device_number(mountpoint)

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

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

        LOG.debug(connection_info)
        sr_params = {}
        if u'sr_uuid' not in connection_data:
            sr_params = volume_utils.parse_volume_info(connection_data)
            uuid = "FA15E-D15C-" + str(sr_params['id'])
            sr_params['sr_type'] = 'iscsi'
        else:
            uuid = connection_data['sr_uuid']
            for k in connection_data['introduce_sr_keys']:
                sr_params[k] = connection_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._session.XenAPI.Failure, exc:
            LOG.exception(exc)
            raise volume_utils.StorageError(
                                _('Unable to introduce Storage Repository'))
예제 #12
0
파일: volumeops.py 프로젝트: isolosun/nova
    def attach_volume(self, connection_info, instance_name, mountpoint):
        """Attach volume storage to VM instance"""

        vm_ref = vm_utils.vm_ref_or_raise(self._session, 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)

        connection_data = connection_info['data']
        dev_number = volume_utils.get_device_number(mountpoint)

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

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

        LOG.debug(connection_info)
        sr_params = {}
        if u'sr_uuid' not in connection_data:
            sr_params = volume_utils.parse_volume_info(connection_data)
            uuid = "FA15E-D15C-" + str(sr_params['id'])
            sr_params['sr_type'] = 'iscsi'
        else:
            uuid = connection_data['sr_uuid']
            for k in connection_data['introduce_sr_keys']:
                sr_params[k] = connection_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._session.XenAPI.Failure, exc:
            LOG.exception(exc)
            raise volume_utils.StorageError(
                _('Unable to introduce Storage Repository'))
예제 #13
0
    def detach_volume(self, connection_info, instance_name, mountpoint):
        """Detach volume storage to VM instance."""

        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)

        # Detach VBD from VM
        LOG.debug(
            _("Detach_volume: %(instance_name)s, %(mountpoint)s") % locals())
        device_number = volume_utils.get_device_number(mountpoint)
        try:
            vbd_ref = vm_utils.find_vbd_by_number(self._session, vm_ref,
                                                  device_number)
            sr_ref = volume_utils.find_sr_from_vbd(self._session, vbd_ref)
        except volume_utils.StorageError, exc:
            LOG.exception(exc)
            raise Exception(_('Unable to locate volume %s') % mountpoint)
예제 #14
0
파일: volumeops.py 프로젝트: dwding/nova
    def detach_volume(self, connection_info, instance_name, mountpoint):
        """Detach volume storage to VM instance."""
        LOG.debug(_("Detach_volume: %(instance_name)s, %(mountpoint)s")
                % locals())

        device_number = volume_utils.get_device_number(mountpoint)
        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)

        vbd_ref = vm_utils.find_vbd_by_number(
                self._session, vm_ref, device_number)

        # Unplug VBD if we're NOT shutdown
        unplug = not vm_utils._is_vm_shutdown(self._session, vm_ref)
        self._detach_vbd(vbd_ref, unplug=unplug)

        LOG.info(_('Mountpoint %(mountpoint)s detached from instance'
                   ' %(instance_name)s') % locals())
예제 #15
0
    def attach_volume(self, connection_info, instance_name, mountpoint, hotplug=True):
        """Attach volume storage to VM instance."""

        vm_ref = vm_utils.vm_ref_or_raise(self._session, 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)

        connection_data = connection_info["data"]
        dev_number = volume_utils.get_device_number(mountpoint)

        self._connect_volume(connection_data, dev_number, instance_name, vm_ref, hotplug=hotplug)

        LOG.info(_("Mountpoint %(mountpoint)s attached to" " instance %(instance_name)s") % locals())
예제 #16
0
    def detach_volume(self, connection_info, instance_name, mountpoint):
        """Detach volume storage to VM instance."""
        LOG.debug(_("Detach_volume: %(instance_name)s, %(mountpoint)s") % locals())

        device_number = volume_utils.get_device_number(mountpoint)
        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)

        try:
            vbd_ref = vm_utils.find_vbd_by_number(self._session, vm_ref, device_number)
        except volume_utils.StorageError:
            # NOTE(sirp): If we don't find the VBD then it must have been
            # detached previously.
            LOG.warn(_("Skipping detach because VBD for %(instance_name)s was" " not found") % locals())
            return

        # Unplug VBD if we're NOT shutdown
        unplug = not vm_utils._is_vm_shutdown(self._session, vm_ref)
        self._detach_vbd(vbd_ref, unplug=unplug)

        LOG.info(_("Mountpoint %(mountpoint)s detached from instance" " %(instance_name)s") % locals())
예제 #17
0
파일: volumeops.py 프로젝트: Juniper/nova
    def _attach_volume_to_vm(self, vdi_ref, vm_ref, instance_name, mountpoint,
                             hotplug):
        LOG.debug('Attach_volume vdi: %(vdi_ref)s vm: %(vm_ref)s',
                  {'vdi_ref': vdi_ref, 'vm_ref': vm_ref})

        dev_number = volume_utils.get_device_number(mountpoint)

        # osvol is added to the vbd so we can spot which vbds are volumes
        vbd_ref = vm_utils.create_vbd(self._session, vm_ref, vdi_ref,
                                      dev_number, bootable=False,
                                      osvol=True)
        if hotplug:
            # NOTE(johngarbutt) can only call VBD.plug on a running vm
            running = not vm_utils.is_vm_shutdown(self._session, vm_ref)
            if running:
                LOG.debug("Plugging VBD: %s", vbd_ref)
                self._session.VBD.plug(vbd_ref, vm_ref)

        LOG.info('Dev %(dev_number)s attached to'
                 ' instance %(instance_name)s',
                 {'instance_name': instance_name, 'dev_number': dev_number})
예제 #18
0
    def attach_volume(self, connection_info, instance_name, mountpoint):
        """Attach volume storage to VM instance"""

        vm_ref = vm_utils.vm_ref_or_raise(self._session, 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)

        connection_data = connection_info['data']
        dev_number = volume_utils.get_device_number(mountpoint)

        self.connect_volume(
            connection_data, dev_number, instance_name, vm_ref)

        LOG.info(_('Mountpoint %(mountpoint)s attached to'
                ' instance %(instance_name)s') % locals())
예제 #19
0
    def detach_volume(self, connection_info, instance_name, mountpoint):
        """Detach volume storage to VM instance."""
        LOG.debug("Detach_volume: %(instance_name)s, %(mountpoint)s",
                  {'instance_name': instance_name, 'mountpoint': mountpoint})

        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)

        device_number = volume_utils.get_device_number(mountpoint)
        vbd_ref = volume_utils.find_vbd_by_number(self._session, vm_ref,
                                                  device_number)

        if vbd_ref is None:
            # NOTE(sirp): If we don't find the VBD then it must have been
            # detached previously.
            LOG.warning(_LW('Skipping detach because VBD for %s was '
                            'not found'), instance_name)
        else:
            self._detach_vbds_and_srs(vm_ref, [vbd_ref])
            LOG.info(_LI('Mountpoint %(mountpoint)s detached from instance'
                         ' %(instance_name)s'),
                     {'instance_name': instance_name,
                      'mountpoint': mountpoint})