Esempio n. 1
0
    def execute(self, context, volume_ref, manage_existing_ref):
        volume_id = volume_ref.id
        if not self.driver.initialized:
            driver_name = self.driver.__class__.__name__
            LOG.error(
                _LE("Unable to manage existing volume. "
                    "Volume driver %s not initialized.") % driver_name)
            flow_common.error_out_volume(context,
                                         self.db,
                                         volume_id,
                                         reason=_("Volume driver %s "
                                                  "not initialized.") %
                                         driver_name)
            raise exception.DriverNotInitialized()

        size = self.driver.manage_existing_get_size(volume_ref,
                                                    manage_existing_ref)

        return {
            'size': size,
            'volume_type_id': volume_ref.volume_type_id,
            'volume_properties': volume_ref,
            'volume_spec': {
                'status': volume_ref.status,
                'volume_name': volume_ref.name,
                'volume_id': volume_ref.id
            }
        }
Esempio n. 2
0
    def execute(self, context, volume_ref, volume_spec):
        volume_spec = dict(volume_spec)
        volume_id = volume_spec.pop('volume_id', None)
        if not volume_id:
            volume_id = volume_ref['id']

        # we can't do anything if the driver didn't init
        if not self.driver.initialized:
            driver_name = self.driver.__class__.__name__
            LOG.exception(
                _LE("Unable to create volume. "
                    "Volume driver %s not initialized"), driver_name)
            raise exception.DriverNotInitialized()

        create_type = volume_spec.pop('type', None)
        LOG.info(
            _LI("Volume %(volume_id)s: being created as %(create_type)s "
                "with specification: %(volume_spec)s"), {
                    'volume_spec': volume_spec,
                    'volume_id': volume_id,
                    'create_type': create_type
                })
        if create_type == 'raw':
            model_update = self._create_raw_volume(volume_ref=volume_ref,
                                                   **volume_spec)
        elif create_type == 'snap':
            model_update = self._create_from_snapshot(context,
                                                      volume_ref=volume_ref,
                                                      **volume_spec)
        elif create_type == 'source_vol':
            model_update = self._create_from_source_volume(
                context, volume_ref=volume_ref, **volume_spec)
        elif create_type == 'source_replica':
            model_update = self._create_from_source_replica(
                context, volume_ref=volume_ref, **volume_spec)
        elif create_type == 'image':
            model_update = self._create_from_image(context,
                                                   volume_ref=volume_ref,
                                                   **volume_spec)
        else:
            raise exception.VolumeTypeNotFound(volume_type_id=create_type)

        # Persist any model information provided on creation.
        try:
            if model_update:
                volume_ref = self.db.volume_update(context, volume_ref['id'],
                                                   model_update)
        except exception.CinderException:
            # If somehow the update failed we want to ensure that the
            # failure is logged (but not try rescheduling since the volume at
            # this point has been created).
            LOG.exception(
                _LE("Failed updating model of volume %(volume_id)s "
                    "with creation provided model %(model)s"), {
                        'volume_id': volume_id,
                        'model': model_update
                    })
            raise

        return volume_ref
Esempio n. 3
0
    def execute(self, context, volume, manage_existing_ref):
        driver_name = self.driver.__class__.__name__
        if not self.driver.initialized:
            LOG.error(_LE("Unable to manage existing volume. "
                          "Volume driver %s not initialized.") % driver_name)
            flow_common.error_out(volume, _("Volume driver %s not "
                                            "initialized.") % driver_name,
                                  status='error_managing')
            raise exception.DriverNotInitialized()

        size = 0
        try:
            size = self.driver.manage_existing_get_size(volume,
                                                        manage_existing_ref)
        except Exception:
            with excutils.save_and_reraise_exception():
                reason = _("Volume driver %s get exception.") % driver_name
                flow_common.error_out(volume, reason,
                                      status='error_managing')

        return {'size': size,
                'volume_type_id': volume.volume_type_id,
                'volume_properties': volume,
                'volume_spec': {'status': volume.status,
                                'volume_name': volume.name,
                                'volume_id': volume.id}}
Esempio n. 4
0
    def execute(self, context, volume, volume_spec):
        volume_spec = dict(volume_spec)
        volume_id = volume_spec.pop('volume_id', None)
        if not volume_id:
            volume_id = volume.id

        # we can't do anything if the driver didn't init
        if not self.driver.initialized:
            driver_name = self.driver.__class__.__name__
            LOG.error(_LE("Unable to create volume. "
                          "Volume driver %s not initialized"), driver_name)
            raise exception.DriverNotInitialized()

        # NOTE(xyang): Populate consistencygroup_id and consistencygroup
        # fields before passing to the driver. This is to support backward
        # compatibility of consistencygroup.
        if volume.group_id:
            volume.consistencygroup_id = volume.group_id
            cg = consistencygroup.ConsistencyGroup()
            cg.from_group(volume.group)
            volume.consistencygroup = cg

        create_type = volume_spec.pop('type', None)
        LOG.info(_LI("Volume %(volume_id)s: being created as %(create_type)s "
                     "with specification: %(volume_spec)s"),
                 {'volume_spec': volume_spec, 'volume_id': volume_id,
                  'create_type': create_type})
        if create_type == 'raw':
            model_update = self._create_raw_volume(volume, **volume_spec)
        elif create_type == 'snap':
            model_update = self._create_from_snapshot(context, volume,
                                                      **volume_spec)
        elif create_type == 'source_vol':
            model_update = self._create_from_source_volume(
                context, volume, **volume_spec)
        elif create_type == 'source_replica':
            model_update = self._create_from_source_replica(
                context, volume, **volume_spec)
        elif create_type == 'image':
            model_update = self._create_from_image(context,
                                                   volume,
                                                   **volume_spec)
        else:
            raise exception.VolumeTypeNotFound(volume_type_id=create_type)

        # Persist any model information provided on creation.
        try:
            if model_update:
                with volume.obj_as_admin():
                    volume.update(model_update)
                    volume.save()
        except exception.CinderException:
            # If somehow the update failed we want to ensure that the
            # failure is logged (but not try rescheduling since the volume at
            # this point has been created).
            LOG.exception(_LE("Failed updating model of volume %(volume_id)s "
                              "with creation provided model %(model)s"),
                          {'volume_id': volume_id, 'model': model_update})
            raise
class MessageFieldTest(test.TestCase):
    @ddt.data({
        'id': '001',
        'content': 'schedule allocate volume'
    }, {
        'id': '002',
        'content': 'attach volume'
    }, {
        'id': 'invalid',
        'content': None
    })
    @ddt.unpack
    def test_translate_action(self, id, content):
        result = message_field.translate_action(id)
        if content is None:
            content = 'unknown action'
        self.assertEqual(content, result)

    @ddt.data({
        'id': '001',
        'content': 'An unknown error occurred.'
    }, {
        'id': '002',
        'content': 'Driver is not initialized at present.'
    }, {
        'id': 'invalid',
        'content': None
    })
    @ddt.unpack
    def test_translate_detail(self, id, content):
        result = message_field.translate_detail(id)
        if content is None:
            content = 'An unknown error occurred.'
        self.assertEqual(content, result)

    @ddt.data(
        {
            'exception': exception.DriverNotInitialized(),
            'detail': '',
            'expected': '002'
        }, {
            'exception': exception.CinderException(),
            'detail': '',
            'expected': '001'
        }, {
            'exception': exception.CinderException(),
            'detail': message_field.Detail.QUOTA_EXCEED,
            'expected': '007'
        }, {
            'exception': '',
            'detail': message_field.Detail.QUOTA_EXCEED,
            'expected': '007'
        })
    @ddt.unpack
    def translate_detail_id(self, exception, detail, expected):
        result = message_field.translate_detail_id(exception, detail)
        self.assertEqual(expected, result)
Esempio n. 6
0
    def execute(self, context, volume_ref, volume_spec):
        volume_spec = dict(volume_spec)
        volume_id = volume_spec.pop('volume_id', None)

        # we can't do anything if the driver didn't init
        if not self.driver.initialized:
            driver_name = self.driver.__class__.__name__
            LOG.error(
                _("Unable to create volume. "
                  "Volume driver %s not initialized") % driver_name)
            # NOTE(flaper87): Set the error status before
            # raising any exception.
            self.db.volume_update(context, volume_id, dict(status='error'))
            raise exception.DriverNotInitialized()

        create_type = volume_spec.pop('type', None)
        create_functor = self._create_func_mapping.get(create_type)
        if not create_functor:
            raise exception.VolumeTypeNotFound(volume_type_id=create_type)

        if not volume_id:
            volume_id = volume_ref['id']
        LOG.info(
            _("Volume %(volume_id)s: being created using %(functor)s "
              "with specification: %(volume_spec)s") % {
                  'volume_spec': volume_spec,
                  'volume_id': volume_id,
                  'functor': common.make_pretty_name(create_functor)
              })

        # Call the given functor to make the volume.
        model_update = create_functor(context,
                                      volume_ref=volume_ref,
                                      **volume_spec)

        # Persist any model information provided on creation.
        try:
            if model_update:
                volume_ref = self.db.volume_update(context, volume_ref['id'],
                                                   model_update)
        except exception.CinderException as ex:
            # If somehow the update failed we want to ensure that the
            # failure is logged (but not try rescheduling since the volume at
            # this point has been created).
            if model_update:
                LOG.exception(
                    _("Failed updating model of volume %(volume_id)s"
                      " with creation provided model %(model)s") % {
                          'volume_id': volume_id,
                          'model': model_update
                      })
                raise exception.ExportFailure(reason=ex)

        return volume_ref
Esempio n. 7
0
    def _login(self):
        client = self._create_client()
        try:
            if self.configuration.hpelefthand_debug:
                client.debug_rest(True)

            client.login(self.configuration.hpelefthand_username,
                         self.configuration.hpelefthand_password)

            cluster_info = client.getClusterByName(
                self.configuration.hpelefthand_clustername)
            self.cluster_id = cluster_info['id']
            virtual_ips = cluster_info['virtualIPAddresses']
            self.cluster_vip = virtual_ips[0]['ipV4Address']

            return client
        except hpeexceptions.HTTPNotFound:
            raise exception.DriverNotInitialized(
                _('LeftHand cluster not found'))
        except Exception as ex:
            raise exception.DriverNotInitialized(ex)
Esempio n. 8
0
def require_driver_initialized(driver):
    """Verifies if `driver` is initialized

    If the driver is not initialized, an exception will be raised.

    :params driver: The driver instance.
    :raises: `exception.DriverNotInitialized`
    """
    # we can't do anything if the driver didn't init
    if not driver.initialized:
        driver_name = driver.__class__.__name__
        LOG.error(_("Volume driver %s not initialized") % driver_name)
        raise exception.DriverNotInitialized()
Esempio n. 9
0
    def do_setup(self, context):
        """Set up LeftHand client."""
        try:
            self.client = client.HPLeftHandClient(
                self.configuration.hplefthand_api_url)
            self.client.login(self.configuration.hplefthand_username,
                              self.configuration.hplefthand_password)

            if self.configuration.hplefthand_debug:
                self.client.debug_rest(True)

            cluster_info = self.client.getClusterByName(
                self.configuration.hplefthand_clustername)
            self.cluster_id = cluster_info['id']
            virtual_ips = cluster_info['virtualIPAddresses']
            self.cluster_vip = virtual_ips[0]['ipV4Address']
            self._update_backend_status()
        except hpexceptions.HTTPNotFound:
            raise exception.DriverNotInitialized(
                _('LeftHand cluster not found'))
        except Exception as ex:
            raise exception.DriverNotInitialized(ex)
    def execute(self, context, snapshot_ref, manage_existing_ref):
        if not self.driver.initialized:
            driver_name = (
                self.driver.configuration.safe_get('volume_backend_name'))
            LOG.error(
                _LE("Unable to manage existing snapshot. "
                    "Volume driver %s not initialized."), driver_name)
            flow_common.error_out(snapshot_ref,
                                  reason=_("Volume driver %s "
                                           "not initialized.") % driver_name)
            raise exception.DriverNotInitialized()

        size = self.driver.manage_existing_snapshot_get_size(
            snapshot=snapshot_ref, existing_ref=manage_existing_ref)

        return {'size': size, 'snapshot_properties': snapshot_ref}
Esempio n. 11
0
 def wrapper(self, *args, **kwargs):
     # we can't do anything if the driver didn't init
     if not self.driver.initialized:
         driver_name = self.driver.__class__.__name__
         raise exception.DriverNotInitialized(driver=driver_name)
     return func(self, *args, **kwargs)