Esempio n. 1
0
    def manage_existing(self,
                        context,
                        topic,
                        volume_id,
                        request_spec,
                        filter_properties=None):
        """Ensure that the host exists and can accept the volume."""

        self._wait_for_scheduler()

        def _manage_existing_set_error(self, context, ex, request_spec):
            volume_state = {'volume_state': {'status': 'error'}}
            self._set_volume_state_and_notify('manage_existing', volume_state,
                                              context, ex, request_spec)

        volume_ref = db.volume_get(context, volume_id)
        try:
            self.driver.host_passes_filters(context, volume_ref['host'],
                                            request_spec, filter_properties)
        except exception.NoValidHost as ex:
            _manage_existing_set_error(self, context, ex, request_spec)
        except Exception as ex:
            with excutils.save_and_reraise_exception():
                _manage_existing_set_error(self, context, ex, request_spec)
        else:
            volume_rpcapi.VolumeAPI().manage_existing(context, volume_ref,
                                                      request_spec.get('ref'))
Esempio n. 2
0
    def migrate_volume_to_host(self,
                               context,
                               topic,
                               volume_id,
                               host,
                               force_host_copy,
                               request_spec,
                               filter_properties=None,
                               volume=None):
        """Ensure that the host exists and can accept the volume."""

        self._wait_for_scheduler()

        # FIXME(thangp): Remove this in v2.0 of RPC API.
        if volume is None:
            # For older clients, mimic the old behavior and look up the
            # volume by its volume_id.
            volume = objects.Volume.get_by_id(context, volume_id)

        def _migrate_volume_set_error(self, context, ex, request_spec):
            if volume.status == 'maintenance':
                previous_status = (volume.previous_status or 'maintenance')
                volume_state = {
                    'volume_state': {
                        'migration_status': 'error',
                        'status': previous_status
                    }
                }
            else:
                volume_state = {'volume_state': {'migration_status': 'error'}}
            self._set_volume_state_and_notify('migrate_volume_to_host',
                                              volume_state, context, ex,
                                              request_spec)

        try:
            tgt_host = self.driver.host_passes_filters(context, host,
                                                       request_spec,
                                                       filter_properties)
        except exception.NoValidHost as ex:
            _migrate_volume_set_error(self, context, ex, request_spec)
        except Exception as ex:
            with excutils.save_and_reraise_exception():
                _migrate_volume_set_error(self, context, ex, request_spec)
        else:
            volume_rpcapi.VolumeAPI().migrate_volume(context, volume, tgt_host,
                                                     force_host_copy)
Esempio n. 3
0
 def __init__(self):
     # FIXME(jdg):  Is it kosher that this just
     # skips the volume.api and goes straight to RPC
     # from here?
     self.volume_api = rpcapi.VolumeAPI()
     super(CapabilitiesController, self).__init__()
Esempio n. 4
0
 def reset(self):
     """Reset volume RPC API object to load new version pins."""
     self.volume_rpcapi = volume_rpcapi.VolumeAPI()
Esempio n. 5
0
 def __init__(self):
     self.host_manager = importutils.import_object(
         CONF.storage_scheduler_host_manager)
     self.volume_rpcapi = volume_rpcapi.VolumeAPI()
Esempio n. 6
0
    def retype(self,
               context,
               topic,
               volume_id,
               request_spec,
               filter_properties=None,
               volume=None):
        """Schedule the modification of a volume's type.

        :param context: the request context
        :param topic: the topic listened on
        :param volume_id: the ID of the volume to retype
        :param request_spec: parameters for this retype request
        :param filter_properties: parameters to filter by
        :param volume: the volume object to retype
        """

        self._wait_for_scheduler()

        # FIXME(thangp): Remove this in v2.0 of RPC API.
        if volume is None:
            # For older clients, mimic the old behavior and look up the
            # volume by its volume_id.
            volume = objects.Volume.get_by_id(context, volume_id)

        def _retype_volume_set_error(self, context, ex, request_spec,
                                     volume_ref, msg, reservations):
            if reservations:
                QUOTAS.rollback(context, reservations)
            previous_status = (volume_ref.previous_status or volume_ref.status)
            volume_state = {'volume_state': {'status': previous_status}}
            self._set_volume_state_and_notify('retype', volume_state, context,
                                              ex, request_spec, msg)

        reservations = request_spec.get('quota_reservations')
        old_reservations = request_spec.get('old_reservations', None)
        new_type = request_spec.get('volume_type')
        if new_type is None:
            msg = _('New volume type not specified in request_spec.')
            ex = exception.ParameterNotFound(param='volume_type')
            _retype_volume_set_error(self, context, ex, request_spec, volume,
                                     msg, reservations)

        # Default migration policy is 'never'
        migration_policy = request_spec.get('migration_policy')
        if not migration_policy:
            migration_policy = 'never'

        try:
            tgt_host = self.driver.find_retype_host(context, request_spec,
                                                    filter_properties,
                                                    migration_policy)
        except exception.NoValidHost as ex:
            msg = (_("Could not find a host for volume %(volume_id)s with "
                     "type %(type_id)s.") % {
                         'type_id': new_type['id'],
                         'volume_id': volume.id
                     })
            _retype_volume_set_error(self, context, ex, request_spec, volume,
                                     msg, reservations)
        except Exception as ex:
            with excutils.save_and_reraise_exception():
                _retype_volume_set_error(self, context, ex, request_spec,
                                         volume, None, reservations)
        else:
            volume_rpcapi.VolumeAPI().retype(context, volume, new_type['id'],
                                             tgt_host, migration_policy,
                                             reservations, old_reservations)
Esempio n. 7
0
 def request_service_capabilities(self, context):
     volume_rpcapi.VolumeAPI().publish_service_capabilities(context)