Example #1
0
    def update(self, req, type_id, id, body=None):
        context = req.environ['cinder.context']
        authorize(context, action='update')
        self._allow_update(context, type_id)

        if not body:
            expl = _('Request body empty')
            raise webob.exc.HTTPBadRequest(explanation=expl)
        self._check_type(context, type_id)
        if id not in body:
            expl = _('Request body and URI mismatch')
            raise webob.exc.HTTPBadRequest(explanation=expl)
        if len(body) > 1:
            expl = _('Request body contains too many items')
            raise webob.exc.HTTPBadRequest(explanation=expl)
        self._check_key_names(body.keys())
        utils.validate_dictionary_string_length(body)

        db.volume_type_extra_specs_update_or_create(context, type_id, body)
        # Get created_at and updated_at for notification
        volume_type = volume_types.get_volume_type(context, type_id)
        notifier_info = dict(type_id=type_id,
                             id=id,
                             created_at=volume_type['created_at'],
                             updated_at=volume_type['updated_at'])
        notifier = rpc.get_notifier('volumeTypeExtraSpecs')
        notifier.info(context, 'volume_type_extra_specs.update', notifier_info)
        return body
Example #2
0
def update(context, qos_specs_id, specs):
    """Update qos specs.

    :param specs: dictionary that contains key/value pairs for updating
                  existing specs.
          e.g. {'consumer': 'front-end',
                'total_iops_sec': 500,
                'total_bytes_sec': 512000,}
    """
    LOG.debug('qos_specs.update(): specs %s', specs)

    try:
        utils.validate_dictionary_string_length(specs)
        qos_spec = objects.QualityOfServiceSpecs.get_by_id(context,
                                                           qos_specs_id)

        if 'consumer' in specs:
            qos_spec.consumer = specs['consumer']
            # If we need to modify specs, copy so we don't cause unintended
            # consequences for the caller
            specs = specs.copy()
            del specs['consumer']

        # Update any values in specs dict
        qos_spec.specs.update(specs)

        qos_spec.save()
    except exception.InvalidInput as e:
        raise exception.InvalidQoSSpecs(reason=e)
    except db_exc.DBError:
        LOG.exception('DB error:')
        raise exception.QoSSpecsUpdateFailed(specs_id=qos_specs_id,
                                             qos_specs=specs)

    return qos_spec
Example #3
0
def update(context, qos_specs_id, specs):
    """Update qos specs.

    :param specs: dictionary that contains key/value pairs for updating
                  existing specs.
          e.g. {'consumer': 'front-end',
                'total_iops_sec': 500,
                'total_bytes_sec': 512000,}
    """
    LOG.debug('qos_specs.update(): specs %s', specs)

    try:
        utils.validate_dictionary_string_length(specs)
        qos_spec = objects.QualityOfServiceSpecs.get_by_id(
            context, qos_specs_id)

        if 'consumer' in specs:
            qos_spec.consumer = specs['consumer']
            # If we need to modify specs, copy so we don't cause unintended
            # consequences for the caller
            specs = specs.copy()
            del specs['consumer']

        # Update any values in specs dict
        qos_spec.specs.update(specs)

        qos_spec.save()
    except exception.InvalidInput as e:
        raise exception.InvalidQoSSpecs(reason=e)
    except db_exc.DBError:
        LOG.exception('DB error:')
        raise exception.QoSSpecsUpdateFailed(specs_id=qos_specs_id,
                                             qos_specs=specs)

    return qos_spec
Example #4
0
def create(context, name, specs=None):
    """Creates qos_specs.

    :param specs: Dictionary that contains specifications for QoS

    Expected format of the input parameter:

       .. code-block:: python

          {
             'consumer': 'front-end',
             'total_iops_sec': 1000,
             'total_bytes_sec': 1024000
          }

    """
    # Validate the key-value pairs in the qos spec.
    utils.validate_dictionary_string_length(specs)

    consumer = specs.get('consumer')
    if consumer:
        # If we need to modify specs, copy so we don't cause unintended
        # consequences for the caller
        specs = specs.copy()
        del specs['consumer']

    values = dict(name=name, consumer=consumer, specs=specs)

    LOG.debug("Dict for qos_specs: %s", values)
    qos_spec = objects.QualityOfServiceSpecs(context, **values)
    qos_spec.create()
    return qos_spec
    def update(self, req, group_type_id, id, body=None):
        context = req.environ['cinder.context']
        self._check_policy(context)

        if not body:
            expl = _('Request body empty')
            raise webob.exc.HTTPBadRequest(explanation=expl)
        self._check_type(context, group_type_id)
        if id not in body:
            expl = _('Request body and URI mismatch')
            raise webob.exc.HTTPBadRequest(explanation=expl)
        if len(body) > 1:
            expl = _('Request body contains too many items')
            raise webob.exc.HTTPBadRequest(explanation=expl)
        self._check_key_names(body.keys())
        utils.validate_dictionary_string_length(body)

        db.group_type_specs_update_or_create(context,
                                             group_type_id,
                                             body)
        notifier_info = dict(type_id=group_type_id, id=id)
        notifier = rpc.get_notifier('groupTypeSpecs')
        notifier.info(context,
                      'group_type_specs.update',
                      notifier_info)
        return body
Example #6
0
def create(context, name, specs=None):
    """Creates qos_specs.

    :param specs: Dictionary that contains specifications for QoS

    Expected format of the input parameter:

       .. code-block:: python

          {
             'consumer': 'front-end',
             'total_iops_sec': 1000,
             'total_bytes_sec': 1024000
          }

    """
    # Validate the key-value pairs in the qos spec.
    utils.validate_dictionary_string_length(specs)

    consumer = specs.get('consumer')
    if consumer:
        # If we need to modify specs, copy so we don't cause unintended
        # consequences for the caller
        specs = specs.copy()
        del specs['consumer']

    values = dict(name=name, consumer=consumer, specs=specs)

    LOG.debug("Dict for qos_specs: %s", values)
    qos_spec = objects.QualityOfServiceSpecs(context, **values)
    qos_spec.create()
    return qos_spec
Example #7
0
    def update(self, req, type_id, id, body=None):
        context = req.environ['cinder.context']
        authorize(context)
        if not body:
            expl = _('Request body empty')
            raise webob.exc.HTTPBadRequest(explanation=expl)
        self._check_type(context, type_id)
        if id not in body:
            expl = _('Request body and URI mismatch')
            raise webob.exc.HTTPBadRequest(explanation=expl)
        if len(body) > 1:
            expl = _('Request body contains too many items')
            raise webob.exc.HTTPBadRequest(explanation=expl)
        self._check_key_names(body.keys())
        utils.validate_dictionary_string_length(body)

        db.volume_type_extra_specs_update_or_create(context,
                                                    type_id,
                                                    body)
        notifier_info = dict(type_id=type_id, id=id)
        notifier = rpc.get_notifier('volumeTypeExtraSpecs')
        notifier.info(context,
                      'volume_type_extra_specs.update',
                      notifier_info)
        return body
Example #8
0
    def _create(self, req, body):
        """Creates a new volume type."""
        context = req.environ['cinder.context']
        authorize(context)

        self.assert_valid_body(body, 'volume_type')

        vol_type = body['volume_type']
        name = vol_type.get('name', None)
        description = vol_type.get('description')
        specs = vol_type.get('extra_specs', {})
        utils.validate_dictionary_string_length(specs)
        is_public = vol_type.get('os-volume-type-access:is_public', True)

        if name is None or len(name.strip()) == 0:
            msg = _("Volume type name can not be empty.")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        utils.check_string_length(name,
                                  'Type name',
                                  min_length=1,
                                  max_length=255)

        if description is not None:
            utils.check_string_length(description,
                                      'Type description',
                                      min_length=0,
                                      max_length=255)

        if not strutils.is_valid_boolstr(is_public):
            msg = _("Invalid value '%s' for is_public. Accepted values: "
                    "True or False.") % is_public
            raise webob.exc.HTTPBadRequest(explanation=msg)

        try:
            volume_types.create(context,
                                name,
                                specs,
                                is_public,
                                description=description)
            vol_type = volume_types.get_volume_type_by_name(context, name)
            req.cache_resource(vol_type, name='types')
            self._notify_volume_type_info(context, 'volume_type.create',
                                          vol_type)

        except exception.VolumeTypeExists as err:
            self._notify_volume_type_error(context,
                                           'volume_type.create',
                                           err,
                                           volume_type=vol_type)
            raise webob.exc.HTTPConflict(explanation=six.text_type(err))
        except exception.VolumeTypeNotFoundByName as err:
            self._notify_volume_type_error(context,
                                           'volume_type.create',
                                           err,
                                           name=name)
            # Not found exception will be handled at the wsgi level
            raise

        return self._view_builder.show(req, vol_type)
Example #9
0
    def _create(self, req, body):
        """Creates a new volume type."""
        context = req.environ['cinder.context']
        authorize(context)

        self.assert_valid_body(body, 'volume_type')

        vol_type = body['volume_type']
        name = vol_type.get('name', None)
        description = vol_type.get('description')
        specs = vol_type.get('extra_specs', {})
        utils.validate_dictionary_string_length(specs)
        is_public = vol_type.get('os-volume-type-access:is_public', True)

        if name is None or len(name.strip()) == 0:
            msg = _("Volume type name can not be empty.")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        utils.check_string_length(name, 'Type name',
                                  min_length=1, max_length=255)

        if description is not None:
            utils.check_string_length(description, 'Type description',
                                      min_length=0, max_length=255)

        if not strutils.is_valid_boolstr(is_public):
            msg = _("Invalid value '%s' for is_public. Accepted values: "
                    "True or False.") % is_public
            raise webob.exc.HTTPBadRequest(explanation=msg)

        try:
            volume_types.create(context,
                                name,
                                specs,
                                is_public,
                                description=description)
            vol_type = volume_types.get_volume_type_by_name(context, name)
            req.cache_resource(vol_type, name='types')
            self._notify_volume_type_info(
                context, 'volume_type.create', vol_type)

        except exception.VolumeTypeExists as err:
            self._notify_volume_type_error(
                context, 'volume_type.create', err, volume_type=vol_type)
            raise webob.exc.HTTPConflict(explanation=six.text_type(err))
        except exception.VolumeTypeNotFoundByName as err:
            self._notify_volume_type_error(
                context, 'volume_type.create', err, name=name)
            # Not found exception will be handled at the wsgi level
            raise

        return self._view_builder.show(req, vol_type)
Example #10
0
    def create(self, req, group_type_id, body=None):
        context = req.environ['cinder.context']
        self._check_policy(context)
        self.assert_valid_body(body, 'group_specs')

        self._check_type(context, group_type_id)
        specs = body['group_specs']
        self._check_key_names(specs.keys())
        utils.validate_dictionary_string_length(specs)

        db.group_type_specs_update_or_create(context, group_type_id, specs)
        notifier_info = dict(type_id=group_type_id, specs=specs)
        notifier = rpc.get_notifier('groupTypeSpecs')
        notifier.info(context, 'group_type_specs.create', notifier_info)
        return body
Example #11
0
    def create(self, req, body=None):
        context = req.environ['cinder.context']
        authorize(context)

        self.assert_valid_body(body, 'qos_specs')

        specs = body['qos_specs']
        name = specs.get('name', None)
        if name is None:
            msg = _("Please specify a name for QoS specs.")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        self.validate_string_length(name, 'name', min_length=1,
                                    max_length=255, remove_whitespaces=True)
        name = name.strip()
        # Remove name from 'specs' since passing it in as separate param
        del specs['name']

        # Validate the key-value pairs in the qos spec.
        utils.validate_dictionary_string_length(specs)

        try:
            spec = qos_specs.create(context, name, specs)
            notifier_info = dict(name=name, specs=specs)
            rpc.get_notifier('QoSSpecs').info(context,
                                              'qos_specs.create',
                                              notifier_info)
        except exception.InvalidQoSSpecs as err:
            notifier_err = dict(name=name, error_message=err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPBadRequest(explanation=six.text_type(err))
        except exception.QoSSpecsExists as err:
            notifier_err = dict(name=name, error_message=err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPConflict(explanation=six.text_type(err))
        except exception.QoSSpecsCreateFailed as err:
            notifier_err = dict(name=name, error_message=err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPInternalServerError(
                explanation=six.text_type(err))

        return self._view_builder.detail(req, spec)
Example #12
0
    def create(self, req, type_id, body=None):
        context = req.environ['cinder.context']
        authorize(context)
        self._allow_update(context, type_id)

        self.assert_valid_body(body, 'extra_specs')

        self._check_type(context, type_id)
        specs = body['extra_specs']
        self._check_key_names(specs.keys())
        utils.validate_dictionary_string_length(specs)

        db.volume_type_extra_specs_update_or_create(context, type_id, specs)
        notifier_info = dict(type_id=type_id, specs=specs)
        notifier = rpc.get_notifier('volumeTypeExtraSpecs')
        notifier.info(context, 'volume_type_extra_specs.create', notifier_info)
        return body
Example #13
0
    def create(self, req, group_type_id, body=None):
        context = req.environ['cinder.context']
        self._check_policy(context)
        self.assert_valid_body(body, 'group_specs')

        self._check_type(context, group_type_id)
        specs = body['group_specs']
        self._check_key_names(specs.keys())
        utils.validate_dictionary_string_length(specs)

        db.group_type_specs_update_or_create(context,
                                             group_type_id,
                                             specs)
        notifier_info = dict(type_id=group_type_id, specs=specs)
        notifier = rpc.get_notifier('groupTypeSpecs')
        notifier.info(context, 'group_type_specs.create',
                      notifier_info)
        return body
Example #14
0
    def create(self, req, type_id, body=None):
        context = req.environ['cinder.context']
        authorize(context)

        self.assert_valid_body(body, 'extra_specs')

        self._check_type(context, type_id)
        specs = body['extra_specs']
        self._check_key_names(specs.keys())
        utils.validate_dictionary_string_length(specs)

        db.volume_type_extra_specs_update_or_create(context,
                                                    type_id,
                                                    specs)
        notifier_info = dict(type_id=type_id, specs=specs)
        notifier = rpc.get_notifier('volumeTypeExtraSpecs')
        notifier.info(context, 'volume_type_extra_specs.create',
                      notifier_info)
        return body
Example #15
0
    def create(self, req, type_id, body=None):
        context = req.environ['cinder.context']
        context.authorize(policy.CREATE_POLICY)
        self._allow_update(context, type_id)

        self.assert_valid_body(body, 'extra_specs')

        self._check_type(context, type_id)
        specs = body['extra_specs']
        self._check_key_names(specs.keys())
        utils.validate_dictionary_string_length(specs)

        db.volume_type_extra_specs_update_or_create(context, type_id, specs)
        # Get created_at and updated_at for notification
        volume_type = volume_types.get_volume_type(context, type_id)
        notifier_info = dict(type_id=type_id,
                             specs=specs,
                             created_at=volume_type['created_at'],
                             updated_at=volume_type['updated_at'])
        notifier = rpc.get_notifier('volumeTypeExtraSpecs')
        notifier.info(context, 'volume_type_extra_specs.create', notifier_info)
        return body