def _get_resources(self, req, is_detail):
        self._ensure_min_version(req, '3.8')

        context = req.environ['cinder.context']
        self._authorizer(context)

        params = req.params.copy()
        cluster_name, host = common.get_cluster_host(req, params, '3.17')
        marker, limit, offset = common.get_pagination_params(params)
        sort_keys, sort_dirs = common.get_sort_params(params,
                                                      default_key='reference')

        # These parameters are generally validated at the DB layer, but in this
        # case sorting is not done by the DB
        invalid_keys = set(sort_keys).difference(self.VALID_SORT_KEYS)
        if invalid_keys:
            msg = _("Invalid sort keys passed: %s") % ', '.join(invalid_keys)
            raise exception.InvalidParameterValue(err=msg)

        invalid_dirs = set(sort_dirs).difference(self.VALID_SORT_DIRS)
        if invalid_dirs:
            msg = _("Invalid sort dirs passed: %s") % ', '.join(invalid_dirs)
            raise exception.InvalidParameterValue(err=msg)

        resources = self.get_manageable(context, host, cluster_name,
                                        marker=marker, limit=limit,
                                        offset=offset, sort_keys=sort_keys,
                                        sort_dirs=sort_dirs)
        view_builder = getattr(self._list_manageable_view,
                               'detail_list' if is_detail else 'summary_list')
        return view_builder(req, resources, len(resources))
def get_manageable_resources(req, is_detail, function_get_manageable, view_builder):
    context = req.environ["cinder.context"]
    params = req.params.copy()
    cluster_name, host = common.get_cluster_host(req, params, "3.17")
    marker, limit, offset = common.get_pagination_params(params)
    sort_keys, sort_dirs = common.get_sort_params(params, default_key="reference")

    # These parameters are generally validated at the DB layer, but in this
    # case sorting is not done by the DB
    valid_sort_keys = ("reference", "size")
    invalid_keys = [key for key in sort_keys if key not in valid_sort_keys]
    if invalid_keys:
        msg = _("Invalid sort keys passed: %s") % ", ".join(invalid_keys)
        raise exception.InvalidParameterValue(err=msg)
    valid_sort_dirs = ("asc", "desc")
    invalid_dirs = [d for d in sort_dirs if d not in valid_sort_dirs]
    if invalid_dirs:
        msg = _("Invalid sort dirs passed: %s") % ", ".join(invalid_dirs)
        raise exception.InvalidParameterValue(err=msg)

    resources = function_get_manageable(
        context, host, cluster_name, marker=marker, limit=limit, offset=offset, sort_keys=sort_keys, sort_dirs=sort_dirs
    )
    resource_count = len(resources)

    if is_detail:
        resources = view_builder.detail_list(req, resources, resource_count)
    else:
        resources = view_builder.summary_list(req, resources, resource_count)
    return resources
Example #3
0
    def _get_resources(self, req, is_detail):
        self._ensure_min_version(req, '3.8')

        context = req.environ['cinder.context']
        self._authorizer(context)

        params = req.params.copy()
        cluster_name, host = common.get_cluster_host(req, params, '3.17')
        marker, limit, offset = common.get_pagination_params(params)
        sort_keys, sort_dirs = common.get_sort_params(params,
                                                      default_key='reference')

        # These parameters are generally validated at the DB layer, but in this
        # case sorting is not done by the DB
        invalid_keys = set(sort_keys).difference(self.VALID_SORT_KEYS)
        if invalid_keys:
            msg = _("Invalid sort keys passed: %s") % ', '.join(invalid_keys)
            raise exception.InvalidParameterValue(err=msg)

        invalid_dirs = set(sort_dirs).difference(self.VALID_SORT_DIRS)
        if invalid_dirs:
            msg = _("Invalid sort dirs passed: %s") % ', '.join(invalid_dirs)
            raise exception.InvalidParameterValue(err=msg)

        resources = self.get_manageable(context,
                                        host,
                                        cluster_name,
                                        marker=marker,
                                        limit=limit,
                                        offset=offset,
                                        sort_keys=sort_keys,
                                        sort_dirs=sort_dirs)
        view_builder = getattr(self._list_manageable_view,
                               'detail_list' if is_detail else 'summary_list')
        return view_builder(req, resources, len(resources))
Example #4
0
    def update(self, req, id, body):
        """Enable/Disable scheduling for a service.

        Includes Freeze/Thaw which sends call down to drivers
        and allows volume.manager for the specified host to
        disable the service rather than accessing the service
        directly in this API layer.
        """
        context = req.environ['cinder.context']
        context.authorize(policy.UPDATE_POLICY)

        support_dynamic_log = req.api_version_request.matches(mv.LOG_LEVEL)
        ext_loaded = self.ext_mgr.is_loaded('os-extended-services')
        ret_val = {}
        if id == "enable":
            disabled, status = self._enable(req, body=body)
        elif id == "disable":
            disabled, status = self._disable(req, body=body)
        elif id == "disable-log-reason" and ext_loaded:
            disabled_reason, disabled, status = (
                self._disabled_log_reason(req, body=body))
            ret_val['disabled_reason'] = disabled_reason
        elif id == "freeze":
            return self._freeze(req, context, body=body)
        elif id == "thaw":
            return self._thaw(req, context, body=body)
        elif id == "failover_host":
            return self._failover(req, context, False, body=body)
        elif (req.api_version_request.matches(mv.REPLICATION_CLUSTER) and
              id == 'failover'):
            return self._failover(req, context, True, body=body)
        elif support_dynamic_log and id == 'set-log':
            return self._set_log(req, context, body=body)
        elif support_dynamic_log and id == 'get-log':
            return self._get_log(req, context, body=body)
        else:
            raise exception.InvalidInput(reason=_("Unknown action"))

        host = common.get_cluster_host(req, body, False)[1]
        ret_val['disabled'] = disabled

        # NOTE(uni): deprecating service request key, binary takes precedence
        # Still keeping service key here for API compatibility sake.
        service = body.get('service', '')
        binary = body.get('binary', '')
        binary_key = binary or service

        # Not found exception will be handled at the wsgi level
        svc = objects.Service.get_by_args(context, host, binary_key)

        svc.disabled = ret_val['disabled']
        if 'disabled_reason' in ret_val:
            svc.disabled_reason = ret_val['disabled_reason']
        svc.save()

        ret_val.update({'host': host, 'service': service,
                        'binary': binary, 'status': status})
        return ret_val
Example #5
0
    def update(self, req, id, body):
        """Enable/Disable scheduling for a service.

        Includes Freeze/Thaw which sends call down to drivers
        and allows volume.manager for the specified host to
        disable the service rather than accessing the service
        directly in this API layer.
        """
        context = req.environ['cinder.context']
        context.authorize(policy.UPDATE_POLICY)

        support_dynamic_log = req.api_version_request.matches(mv.LOG_LEVEL)
        ext_loaded = self.ext_mgr.is_loaded('os-extended-services')
        ret_val = {}
        if id == "enable":
            disabled, status = self._enable(req, body=body)
        elif id == "disable":
            disabled, status = self._disable(req, body=body)
        elif id == "disable-log-reason" and ext_loaded:
            disabled_reason, disabled, status = (
                self._disabled_log_reason(req, body=body))
            ret_val['disabled_reason'] = disabled_reason
        elif id == "freeze":
            return self._freeze(req, context, body=body)
        elif id == "thaw":
            return self._thaw(req, context, body=body)
        elif id == "failover_host":
            return self._failover(req, context, False, body=body)
        elif (req.api_version_request.matches(mv.REPLICATION_CLUSTER) and
              id == 'failover'):
            return self._failover(req, context, True, body=body)
        elif support_dynamic_log and id == 'set-log':
            return self._set_log(req, context, body=body)
        elif support_dynamic_log and id == 'get-log':
            return self._get_log(req, context, body=body)
        else:
            raise exception.InvalidInput(reason=_("Unknown action"))

        host = common.get_cluster_host(req, body, False)[1]
        ret_val['disabled'] = disabled

        # NOTE(uni): deprecating service request key, binary takes precedence
        # Still keeping service key here for API compatibility sake.
        service = body.get('service', '')
        binary = body.get('binary', '')
        binary_key = binary or service

        # Not found exception will be handled at the wsgi level
        svc = objects.Service.get_by_args(context, host, binary_key)

        svc.disabled = ret_val['disabled']
        if 'disabled_reason' in ret_val:
            svc.disabled_reason = ret_val['disabled_reason']
        svc.save()

        ret_val.update({'host': host, 'service': service,
                        'binary': binary, 'status': status})
        return ret_val
 def _failover(self, context, req, body, clustered):
     # We set version to None to always get the cluster name from the body,
     # to False when we don't want to get it, and '3.26' when we only want
     # it if the requested version is 3.26 or higher.
     version = '3.26' if clustered else False
     cluster_name, host = common.get_cluster_host(req, body, version)
     self._volume_api_proxy(self.volume_api.failover, context, host,
                            cluster_name, body.get('backend_id'))
     return webob.Response(status_int=http_client.ACCEPTED)
Example #7
0
 def _failover(self, context, req, body, clustered):
     # We set version to None to always get the cluster name from the body,
     # to False when we don't want to get it, and '3.26' when we only want
     # it if the requested version is 3.26 or higher.
     version = '3.26' if clustered else False
     cluster_name, host = common.get_cluster_host(req, body, version)
     self._volume_api_proxy(self.volume_api.failover, context, host,
                            cluster_name, body.get('backend_id'))
     return webob.Response(status_int=http_client.ACCEPTED)
Example #8
0
 def _failover(self, req, context, clustered, body):
     # We set version to None to always get the cluster name from the body,
     # to False when we don't want to get it, and REPLICATION_CLUSTER  when
     # we only want it if the requested version is REPLICATION_CLUSTER  or
     # higher.
     version = mv.REPLICATION_CLUSTER if clustered else False
     cluster_name, host = common.get_cluster_host(req, body, version)
     self._volume_api_proxy(self.volume_api.failover, context, host,
                            cluster_name, body.get('backend_id'))
     return webob.Response(status_int=http_client.ACCEPTED)
Example #9
0
 def _failover(self, req, context, clustered, body):
     # We set version to None to always get the cluster name from the body,
     # to False when we don't want to get it, and REPLICATION_CLUSTER  when
     # we only want it if the requested version is REPLICATION_CLUSTER  or
     # higher.
     version = mv.REPLICATION_CLUSTER if clustered else False
     cluster_name, host = common.get_cluster_host(req, body, version)
     self._volume_api_proxy(self.volume_api.failover, context, host,
                            cluster_name, body.get('backend_id'))
     return webob.Response(status_int=http_client.ACCEPTED)
    def _migrate_volume(self, req, id, body):
        """Migrate a volume to the specified host."""
        context = req.environ['cinder.context']
        self.authorize(context, 'migrate_volume')
        # Not found exception will be handled at the wsgi level
        volume = self._get(context, id)
        params = body['os-migrate_volume']

        cluster_name, host = common.get_cluster_host(req, params, '3.16')
        force_host_copy = utils.get_bool_param('force_host_copy', params)
        lock_volume = utils.get_bool_param('lock_volume', params)
        self.volume_api.migrate_volume(context, volume, host, cluster_name,
                                       force_host_copy, lock_volume)
        return webob.Response(status_int=http_client.ACCEPTED)
Example #11
0
    def _migrate_volume(self, req, id, body):
        """Migrate a volume to the specified host."""
        context = req.environ['cinder.context']
        self.authorize(context, 'migrate_volume')
        # Not found exception will be handled at the wsgi level
        volume = self._get(context, id)
        params = body['os-migrate_volume']

        cluster_name, host = common.get_cluster_host(req, params, '3.16')
        force_host_copy = utils.get_bool_param('force_host_copy', params)
        lock_volume = utils.get_bool_param('lock_volume', params)
        self.volume_api.migrate_volume(context, volume, host, cluster_name,
                                       force_host_copy, lock_volume)
        return webob.Response(status_int=202)
Example #12
0
    def _migrate_volume(self, req, id, body):
        """Migrate a volume to the specified host."""
        context = req.environ['cinder.context']
        # Not found exception will be handled at the wsgi level
        volume = self._get(context, id)
        self.authorize(context, 'migrate_volume', target_obj=volume)
        params = body['os-migrate_volume']

        cluster_name, host = common.get_cluster_host(req, params,
                                                     mv.VOLUME_MIGRATE_CLUSTER)
        force_host_copy = utils.get_bool_param('force_host_copy', params)
        lock_volume = utils.get_bool_param('lock_volume', params)
        self.volume_api.migrate_volume(context, volume, host, cluster_name,
                                       force_host_copy, lock_volume)
Example #13
0
    def _migrate_volume(self, req, id, body):
        """Migrate a volume to the specified host."""
        context = req.environ['cinder.context']
        self.authorize(context, 'migrate_volume')
        # Not found exception will be handled at the wsgi level
        volume = self._get(context, id)
        params = body['os-migrate_volume']

        cluster_name, host = common.get_cluster_host(req, params,
                                                     mv.VOLUME_MIGRATE_CLUSTER)
        force_host_copy = utils.get_bool_param('force_host_copy', params)
        lock_volume = utils.get_bool_param('lock_volume', params)
        self.volume_api.migrate_volume(context, volume, host, cluster_name,
                                       force_host_copy, lock_volume)
Example #14
0
    def _migrate_volume(self, req, id, body):
        """Migrate a volume to the specified host."""
        context = req.environ['cinder.context']
        # Not found exception will be handled at the wsgi level
        volume = self._get(context, id)
        self.authorize(context, 'migrate_volume', target_obj=volume)
        params = body['os-migrate_volume']

        cluster_name, host = common.get_cluster_host(req, params,
                                                     mv.VOLUME_MIGRATE_CLUSTER)
        force_host_copy = strutils.bool_from_string(params.get(
            'force_host_copy', False), strict=True)
        lock_volume = strutils.bool_from_string(params.get(
            'lock_volume', False), strict=True)
        self.volume_api.migrate_volume(context, volume, host, cluster_name,
                                       force_host_copy, lock_volume)
def get_manageable_resources(req, is_detail, function_get_manageable,
                             view_builder):
    context = req.environ['cinder.context']
    params = req.params.copy()
    cluster_name, host = common.get_cluster_host(req, params, '3.17')
    marker, limit, offset = common.get_pagination_params(params)
    sort_keys, sort_dirs = common.get_sort_params(params,
                                                  default_key='reference')

    # These parameters are generally validated at the DB layer, but in this
    # case sorting is not done by the DB
    valid_sort_keys = ('reference', 'size')
    invalid_keys = [key for key in sort_keys if key not in valid_sort_keys]
    if invalid_keys:
        msg = _("Invalid sort keys passed: %s") % ', '.join(invalid_keys)
        raise exception.InvalidParameterValue(err=msg)
    valid_sort_dirs = ('asc', 'desc')
    invalid_dirs = [d for d in sort_dirs if d not in valid_sort_dirs]
    if invalid_dirs:
        msg = _("Invalid sort dirs passed: %s") % ', '.join(invalid_dirs)
        raise exception.InvalidParameterValue(err=msg)

    try:
        resources = function_get_manageable(context,
                                            host,
                                            cluster_name,
                                            marker=marker,
                                            limit=limit,
                                            offset=offset,
                                            sort_keys=sort_keys,
                                            sort_dirs=sort_dirs)
    except messaging.RemoteError as err:
        if err.exc_type == "InvalidInput":
            raise exception.InvalidInput(err.value)
        raise

    resource_count = len(resources)

    if is_detail:
        resources = view_builder.detail_list(req, resources, resource_count)
    else:
        resources = view_builder.summary_list(req, resources, resource_count)
    return resources
def get_manageable_resources(req, is_detail, function_get_manageable,
                             view_builder):
    context = req.environ['cinder.context']
    params = req.params.copy()
    cluster_name, host = common.get_cluster_host(
        req, params, mv.MANAGE_EXISTING_CLUSTER)
    marker, limit, offset = common.get_pagination_params(params)
    sort_keys, sort_dirs = common.get_sort_params(params,
                                                  default_key='reference')

    # These parameters are generally validated at the DB layer, but in this
    # case sorting is not done by the DB
    valid_sort_keys = ('reference', 'size')
    invalid_keys = [key for key in sort_keys if key not in valid_sort_keys]
    if invalid_keys:
        msg = _("Invalid sort keys passed: %s") % ', '.join(invalid_keys)
        raise exception.InvalidParameterValue(err=msg)
    valid_sort_dirs = ('asc', 'desc')
    invalid_dirs = [d for d in sort_dirs if d not in valid_sort_dirs]
    if invalid_dirs:
        msg = _("Invalid sort dirs passed: %s") % ', '.join(invalid_dirs)
        raise exception.InvalidParameterValue(err=msg)

    try:
        resources = function_get_manageable(context, host, cluster_name,
                                            marker=marker, limit=limit,
                                            offset=offset, sort_keys=sort_keys,
                                            sort_dirs=sort_dirs)
    except messaging.RemoteError as err:
        if err.exc_type == "InvalidInput":
            raise exception.InvalidInput(err.value)
        raise

    resource_count = len(resources)

    if is_detail:
        resources = view_builder.detail_list(req, resources, resource_count)
    else:
        resources = view_builder.summary_list(req, resources, resource_count)
    return resources
Example #17
0
    def update(self, req, id, body):
        """Enable/Disable scheduling for a service.

        Includes Freeze/Thaw which sends call down to drivers
        and allows volume.manager for the specified host to
        disable the service rather than accessing the service
        directly in this API layer.
        """
        context = req.environ['cinder.context']
        authorize(context, action='update')

        support_dynamic_log = req.api_version_request.matches(mv.LOG_LEVEL)

        ext_loaded = self.ext_mgr.is_loaded('os-extended-services')
        ret_val = {}
        if id == "enable":
            disabled = False
            status = "enabled"
            if ext_loaded:
                ret_val['disabled_reason'] = None
        elif (id == "disable" or (id == "disable-log-reason" and ext_loaded)):
            disabled = True
            status = "disabled"
        elif id == "freeze":
            return self._freeze(context, req, body)
        elif id == "thaw":
            return self._thaw(context, req, body)
        elif id == "failover_host":
            return self._failover(context, req, body, False)
        elif (req.api_version_request.matches(mv.REPLICATION_CLUSTER)
              and id == 'failover'):
            return self._failover(context, req, body, True)
        elif support_dynamic_log and id == 'set-log':
            return self._set_log(context, body)
        elif support_dynamic_log and id == 'get-log':
            return self._get_log(context, body)
        else:
            raise exception.InvalidInput(reason=_("Unknown action"))

        host = common.get_cluster_host(req, body, False)[1]

        ret_val['disabled'] = disabled
        if id == "disable-log-reason" and ext_loaded:
            reason = body.get('disabled_reason')
            if not self._is_valid_as_reason(reason):
                msg = _('Disabled reason contains invalid characters '
                        'or is too long')
                raise webob.exc.HTTPBadRequest(explanation=msg)
            ret_val['disabled_reason'] = reason

        # NOTE(uni): deprecating service request key, binary takes precedence
        # Still keeping service key here for API compatibility sake.
        service = body.get('service', '')
        binary = body.get('binary', '')
        binary_key = binary or service
        if not binary_key:
            raise webob.exc.HTTPBadRequest()

        # Not found exception will be handled at the wsgi level
        svc = objects.Service.get_by_args(context, host, binary_key)

        svc.disabled = ret_val['disabled']
        if 'disabled_reason' in ret_val:
            svc.disabled_reason = ret_val['disabled_reason']
        svc.save()

        ret_val.update({
            'host': host,
            'service': service,
            'binary': binary,
            'status': status
        })
        return ret_val
Example #18
0
    def create(self, req, body):
        """Instruct Cinder to manage a storage object.

        Manages an existing backend storage object (e.g. a Linux logical
        volume or a SAN disk) by creating the Cinder objects required to manage
        it, and possibly renaming the backend storage object
        (driver dependent)

        From an API perspective, this operation behaves very much like a
        volume creation operation, except that properties such as image,
        snapshot and volume references don't make sense, because we are taking
        an existing storage object into Cinder management.

        Required HTTP Body:

        .. code-block:: json

         {
           'volume':
           {
             'host': <Cinder host on which the existing storage resides>,
             'cluster': <Cinder cluster on which the storage resides>,
             'ref':  <Driver-specific reference to existing storage object>,
           }
         }

        See the appropriate Cinder drivers' implementations of the
        manage_volume method to find out the accepted format of 'ref'.

        This API call will return with an error if any of the above elements
        are missing from the request, or if the 'host' element refers to a
        cinder host that is not registered.

        The volume will later enter the error state if it is discovered that
        'ref' is bad.

        Optional elements to 'volume' are::

         name               A name for the new volume.
         description        A description for the new volume.
         volume_type        ID or name of a volume type to associate with
                            the new Cinder volume. Does not necessarily
                            guarantee that the managed volume will have the
                            properties described in the volume_type. The
                            driver may choose to fail if it identifies that
                            the specified volume_type is not compatible with
                            the backend storage object.
         metadata           Key/value pairs to be associated with the new
                            volume.
         availability_zone  The availability zone to associate with the new
                            volume.
         bootable           If set to True, marks the volume as bootable.

        """
        context = req.environ['cinder.context']
        authorize_manage(context)

        self.assert_valid_body(body, 'volume')

        volume = body['volume']
        self.validate_name_and_description(volume)

        # Check that the required keys are present, return an error if they
        # are not.
        if 'ref' not in volume:
            raise exception.MissingRequired(element='ref')

        cluster_name, host = common.get_cluster_host(req, volume, '3.16')

        LOG.debug('Manage volume request body: %s', body)

        kwargs = {}
        req_volume_type = volume.get('volume_type', None)
        if req_volume_type:
            try:
                kwargs['volume_type'] = volume_types.get_by_name_or_id(
                    context, req_volume_type)
            except exception.VolumeTypeNotFound:
                msg = _("Cannot find requested '%s' "
                        "volume type") % req_volume_type
                raise exception.InvalidVolumeType(reason=msg)
        else:
            kwargs['volume_type'] = {}

        kwargs['name'] = volume.get('name', None)
        kwargs['description'] = volume.get('description', None)
        kwargs['metadata'] = volume.get('metadata', None)
        kwargs['availability_zone'] = volume.get('availability_zone', None)
        kwargs['bootable'] = utils.get_bool_param('bootable', volume)

        utils.check_metadata_properties(kwargs['metadata'])

        try:
            new_volume = self.volume_api.manage_existing(context,
                                                         host,
                                                         cluster_name,
                                                         volume['ref'],
                                                         **kwargs)
        except exception.ServiceNotFound:
            msg = _("Host '%s' not found") % volume['host']
            raise exception.ServiceUnavailable(message=msg)

        utils.add_visible_admin_metadata(new_volume)

        return self._view_builder.detail(req, new_volume)
Example #19
0
 def _thaw(self, context, req, body):
     cluster_name, host = common.get_cluster_host(req, body,
                                                  mv.REPLICATION_CLUSTER)
     return self._volume_api_proxy(self.volume_api.thaw_host, context, host,
                                   cluster_name)
Example #20
0
 def _thaw(self, context, req, body):
     cluster_name, host = common.get_cluster_host(
         req, body, mv.REPLICATION_CLUSTER)
     return self._volume_api_proxy(self.volume_api.thaw_host, context,
                                   host, cluster_name)
Example #21
0
    def update(self, req, id, body):
        """Enable/Disable scheduling for a service.

        Includes Freeze/Thaw which sends call down to drivers
        and allows volume.manager for the specified host to
        disable the service rather than accessing the service
        directly in this API layer.
        """
        context = req.environ['cinder.context']
        authorize(context, action='update')

        support_dynamic_log = req.api_version_request.matches('3.32')

        ext_loaded = self.ext_mgr.is_loaded('os-extended-services')
        ret_val = {}
        if id == "enable":
            disabled = False
            status = "enabled"
            if ext_loaded:
                ret_val['disabled_reason'] = None
        elif (id == "disable" or
                (id == "disable-log-reason" and ext_loaded)):
            disabled = True
            status = "disabled"
        elif id == "freeze":
            return self._freeze(context, req, body)
        elif id == "thaw":
            return self._thaw(context, req, body)
        elif id == "failover_host":
            return self._failover(context, req, body, False)
        elif req.api_version_request.matches('3.26') and id == 'failover':
            return self._failover(context, req, body, True)
        elif support_dynamic_log and id == 'set-log':
            return self._set_log(context, body)
        elif support_dynamic_log and id == 'get-log':
            return self._get_log(context, body)
        else:
            raise exception.InvalidInput(reason=_("Unknown action"))

        host = common.get_cluster_host(req, body, False)[1]

        ret_val['disabled'] = disabled
        if id == "disable-log-reason" and ext_loaded:
            reason = body.get('disabled_reason')
            if not self._is_valid_as_reason(reason):
                msg = _('Disabled reason contains invalid characters '
                        'or is too long')
                raise webob.exc.HTTPBadRequest(explanation=msg)
            ret_val['disabled_reason'] = reason

        # NOTE(uni): deprecating service request key, binary takes precedence
        # Still keeping service key here for API compatibility sake.
        service = body.get('service', '')
        binary = body.get('binary', '')
        binary_key = binary or service
        if not binary_key:
            raise webob.exc.HTTPBadRequest()

        # Not found exception will be handled at the wsgi level
        svc = objects.Service.get_by_args(context, host, binary_key)

        svc.disabled = ret_val['disabled']
        if 'disabled_reason' in ret_val:
            svc.disabled_reason = ret_val['disabled_reason']
        svc.save()

        ret_val.update({'host': host, 'service': service,
                        'binary': binary, 'status': status})
        return ret_val
Example #22
0
 def _thaw(self, context, req, body):
     cluster_name, host = common.get_cluster_host(req, body, '3.26')
     return self._volume_api_proxy(self.volume_api.thaw_host, context,
                                   host, cluster_name)
Example #23
0
    def create(self, req, body):
        """Instruct Cinder to manage a storage object.

        Manages an existing backend storage object (e.g. a Linux logical
        volume or a SAN disk) by creating the Cinder objects required to manage
        it, and possibly renaming the backend storage object
        (driver dependent)

        From an API perspective, this operation behaves very much like a
        volume creation operation, except that properties such as image,
        snapshot and volume references don't make sense, because we are taking
        an existing storage object into Cinder management.

        Required HTTP Body:

        .. code-block:: json

         {
           "volume": {
             "host": "<Cinder host on which the existing storage resides>",
             "cluster": "<Cinder cluster on which the storage resides>",
             "ref": "<Driver-specific reference to existing storage object>"
           }
         }

        See the appropriate Cinder drivers' implementations of the
        manage_volume method to find out the accepted format of 'ref'.

        This API call will return with an error if any of the above elements
        are missing from the request, or if the 'host' element refers to a
        cinder host that is not registered.

        The volume will later enter the error state if it is discovered that
        'ref' is bad.

        Optional elements to 'volume' are::

         name               A name for the new volume.
         description        A description for the new volume.
         volume_type        ID or name of a volume type to associate with
                            the new Cinder volume. Does not necessarily
                            guarantee that the managed volume will have the
                            properties described in the volume_type. The
                            driver may choose to fail if it identifies that
                            the specified volume_type is not compatible with
                            the backend storage object.
         metadata           Key/value pairs to be associated with the new
                            volume.
         availability_zone  The availability zone to associate with the new
                            volume.
         bootable           If set to True, marks the volume as bootable.

        """
        context = req.environ['cinder.context']
        context.authorize(policy.MANAGE_POLICY)
        volume = body['volume']

        cluster_name, host = common.get_cluster_host(
            req, volume, mv.VOLUME_MIGRATE_CLUSTER)

        LOG.debug('Manage volume request body: %s', body)

        kwargs = {}
        req_volume_type = volume.get('volume_type', None)
        if req_volume_type:
            try:
                kwargs['volume_type'] = volume_types.get_by_name_or_id(
                    context, req_volume_type)
            except exception.VolumeTypeNotFound:
                msg = _("Cannot find requested '%s' "
                        "volume type") % req_volume_type
                raise exception.InvalidVolumeType(reason=msg)
        else:
            kwargs['volume_type'] = {}

        if volume.get('name'):
            kwargs['name'] = volume.get('name').strip()
        if volume.get('description'):
            kwargs['description'] = volume.get('description').strip()

        kwargs['metadata'] = volume.get('metadata', None)
        kwargs['availability_zone'] = volume.get('availability_zone', None)
        bootable = volume.get('bootable', False)
        kwargs['bootable'] = strutils.bool_from_string(bootable, strict=True)

        try:
            new_volume = self.volume_api.manage_existing(context,
                                                         host,
                                                         cluster_name,
                                                         volume['ref'],
                                                         **kwargs)
        except exception.ServiceNotFound:
            msg = _("%(name)s '%(value)s' not found") % {
                'name': 'Host' if host else 'Cluster',
                'value': host or cluster_name}
            raise exception.ServiceUnavailable(message=msg)

        utils.add_visible_admin_metadata(new_volume)

        return self._view_builder.detail(req, new_volume)
 def _thaw(self, context, req, body):
     cluster_name, host = common.get_cluster_host(req, body, '3.26')
     return self._volume_api_proxy(self.volume_api.thaw_host, context, host,
                                   cluster_name)
    def create(self, req, body):
        """Instruct Cinder to manage a storage object.

        Manages an existing backend storage object (e.g. a Linux logical
        volume or a SAN disk) by creating the Cinder objects required to manage
        it, and possibly renaming the backend storage object
        (driver dependent)

        From an API perspective, this operation behaves very much like a
        volume creation operation, except that properties such as image,
        snapshot and volume references don't make sense, because we are taking
        an existing storage object into Cinder management.

        Required HTTP Body:

        .. code-block:: json

         {
           "volume": {
             "host": "<Cinder host on which the existing storage resides>",
             "cluster": "<Cinder cluster on which the storage resides>",
             "ref": "<Driver-specific reference to existing storage object>"
           }
         }

        See the appropriate Cinder drivers' implementations of the
        manage_volume method to find out the accepted format of 'ref'.

        This API call will return with an error if any of the above elements
        are missing from the request, or if the 'host' element refers to a
        cinder host that is not registered.

        The volume will later enter the error state if it is discovered that
        'ref' is bad.

        Optional elements to 'volume' are::

         name               A name for the new volume.
         description        A description for the new volume.
         volume_type        ID or name of a volume type to associate with
                            the new Cinder volume. Does not necessarily
                            guarantee that the managed volume will have the
                            properties described in the volume_type. The
                            driver may choose to fail if it identifies that
                            the specified volume_type is not compatible with
                            the backend storage object.
         metadata           Key/value pairs to be associated with the new
                            volume.
         availability_zone  The availability zone to associate with the new
                            volume.
         bootable           If set to True, marks the volume as bootable.

        """
        context = req.environ['cinder.context']
        context.authorize(policy.MANAGE_POLICY)

        self.assert_valid_body(body, 'volume')

        volume = body['volume']
        self.validate_name_and_description(volume)

        # Check that the required keys are present, return an error if they
        # are not.
        if 'ref' not in volume:
            raise exception.MissingRequired(element='ref')

        cluster_name, host = common.get_cluster_host(req, volume,
                                                     mv.VOLUME_MIGRATE_CLUSTER)

        LOG.debug('Manage volume request body: %s', body)

        kwargs = {}
        req_volume_type = volume.get('volume_type', None)
        if req_volume_type:
            try:
                kwargs['volume_type'] = volume_types.get_by_name_or_id(
                    context, req_volume_type)
            except exception.VolumeTypeNotFound:
                msg = _("Cannot find requested '%s' "
                        "volume type") % req_volume_type
                raise exception.InvalidVolumeType(reason=msg)
        else:
            kwargs['volume_type'] = {}

        kwargs['name'] = volume.get('name', None)
        kwargs['description'] = volume.get('description', None)
        kwargs['metadata'] = volume.get('metadata', None)
        kwargs['availability_zone'] = volume.get('availability_zone', None)
        kwargs['bootable'] = utils.get_bool_param('bootable', volume)

        utils.check_metadata_properties(kwargs['metadata'])

        try:
            new_volume = self.volume_api.manage_existing(
                context, host, cluster_name, volume['ref'], **kwargs)
        except exception.ServiceNotFound:
            msg = _("%(name)s '%(value)s' not found") % {
                'name': 'Host' if host else 'Cluster',
                'value': host or cluster_name
            }
            raise exception.ServiceUnavailable(message=msg)

        utils.add_visible_admin_metadata(new_volume)

        return self._view_builder.detail(req, new_volume)
Example #26
0
 def _freeze(self, context, req, body):
     cluster_name, host = common.get_cluster_host(req, body, '3.26')
     return self.volume_api.freeze_host(context, host, cluster_name)