Exemplo n.º 1
0
    def update(self, req, type_id, id, body=None):
        """Update encryption specs for a given volume type."""
        context = req.environ['cinder.context']
        authorize(context)

        if not body:
            expl = _('Request body empty.')
            raise webob.exc.HTTPBadRequest(explanation=expl)
        if not self.is_valid_body(body, 'encryption'):
            expl = _('Update body is not valid. It must contain "encryption."')
            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_type(context, type_id)

        if self._encrypted_type_in_use(context, type_id):
            expl = _('Cannot update encryption specs. Volume type in use.')
            raise webob.exc.HTTPBadRequest(explanation=expl)

        encryption_specs = body['encryption']
        self._check_encryption_input(encryption_specs, create=False)

        db.volume_type_encryption_update(context, type_id, encryption_specs)
        notifier_info = dict(type_id=type_id, id=id)
        notifier_api.notify(context, 'volumeTypeEncryption',
                            'volume_type_encryption.update', notifier_api.INFO,
                            notifier_info)

        return body
Exemplo n.º 2
0
    def _create(self, req, body):
        """Creates a new volume type."""
        context = req.environ['cinder.context']
        authorize(context)

        if not self.is_valid_body(body, 'volume_type'):
            raise webob.exc.HTTPBadRequest()

        vol_type = body['volume_type']
        name = vol_type.get('name', None)
        specs = vol_type.get('extra_specs', {})

        if name is None or name == "":
            raise webob.exc.HTTPBadRequest()

        try:
            volume_types.create(context, name, specs)
            vol_type = volume_types.get_volume_type_by_name(context, name)
            notifier_info = dict(volume_types=vol_type)
            notifier_api.notify(context, 'volumeType', 'volume_type.create',
                                notifier_api.INFO, notifier_info)

        except exception.VolumeTypeExists as err:
            notifier_err = dict(volume_types=vol_type, error_message=str(err))
            self._notify_voloume_type_error(context, 'volume_type.create',
                                            notifier_err)

            raise webob.exc.HTTPConflict(explanation=str(err))
        except exception.NotFound as err:
            notifier_err = dict(volume_types=vol_type, error_message=str(err))
            self._notify_voloume_type_error(context, 'volume_type.create',
                                            notifier_err)
            raise webob.exc.HTTPNotFound()

        return self._view_builder.show(req, vol_type)
Exemplo n.º 3
0
    def _set_volume_state_and_notify(self, method, updates, context, ex,
                                     request_spec, msg=None):
        # TODO(harlowja): move into a task that just does this later.
        if not msg:
            msg = (_("Failed to schedule_%(method)s: %(ex)s") %
                   {'method': method, 'ex': ex})
        LOG.error(msg)

        volume_state = updates['volume_state']
        properties = request_spec.get('volume_properties', {})

        volume_id = request_spec.get('volume_id', None)

        if volume_id:
            db.volume_update(context, volume_id, volume_state)

        payload = dict(request_spec=request_spec,
                       volume_properties=properties,
                       volume_id=volume_id,
                       state=volume_state,
                       method=method,
                       reason=ex)

        notifier.notify(context, notifier.publisher_id("scheduler"),
                        'scheduler.' + method, notifier.ERROR, payload)
Exemplo n.º 4
0
    def _set_volume_state_and_notify(self, method, updates, context, ex,
                                     request_spec):
        # TODO(harlowja): move into a task that just does this later.

        LOG.error(
            _("Failed to schedule_%(method)s: %(ex)s") % {
                'method': method,
                'ex': ex
            })

        volume_state = updates['volume_state']
        properties = request_spec.get('volume_properties', {})

        volume_id = request_spec.get('volume_id', None)

        if volume_id:
            db.volume_update(context, volume_id, volume_state)

        payload = dict(request_spec=request_spec,
                       volume_properties=properties,
                       volume_id=volume_id,
                       state=volume_state,
                       method=method,
                       reason=ex)

        notifier.notify(context, notifier.publisher_id("scheduler"),
                        'scheduler.' + method, notifier.ERROR, payload)
Exemplo n.º 5
0
    def _create(self, req, body):
        """Creates a new volume type."""
        context = req.environ["cinder.context"]
        authorize(context)

        if not self.is_valid_body(body, "volume_type"):
            raise webob.exc.HTTPBadRequest()

        vol_type = body["volume_type"]
        name = vol_type.get("name", None)
        specs = vol_type.get("extra_specs", {})

        if name is None or name == "":
            raise webob.exc.HTTPBadRequest()

        try:
            volume_types.create(context, name, specs)
            vol_type = volume_types.get_volume_type_by_name(context, name)
            notifier_info = dict(volume_types=vol_type)
            notifier_api.notify(context, "volumeType", "volume_type.create", notifier_api.INFO, notifier_info)

        except exception.VolumeTypeExists as err:
            notifier_err = dict(volume_types=vol_type, error_message=str(err))
            self._notify_volume_type_error(context, "volume_type.create", notifier_err)

            raise webob.exc.HTTPConflict(explanation=str(err))
        except exception.NotFound as err:
            notifier_err = dict(volume_types=vol_type, error_message=str(err))
            self._notify_volume_type_error(context, "volume_type.create", notifier_err)
            raise webob.exc.HTTPNotFound()

        return self._view_builder.show(req, vol_type)
Exemplo n.º 6
0
    def _delete(self, req, id):
        """Deletes an existing volume type."""
        context = req.environ['cinder.context']
        authorize(context)

        try:
            vol_type = volume_types.get_volume_type(context, id)
            volume_types.destroy(context, vol_type['id'])
            notifier_info = dict(volume_types=vol_type)
            notifier_api.notify(context, 'volumeType',
                                'volume_type.delete',
                                notifier_api.INFO, notifier_info)
        except exception.VolumeTypeInUse as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_voloume_type_error(context,
                                            'volume_type.delete',
                                            notifier_err)
            msg = 'Target volume type is still in use.'
            raise webob.exc.HTTPBadRequest(explanation=msg)
        except exception.NotFound as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_voloume_type_error(context,
                                            'volume_type.delete',
                                            notifier_err)

            raise webob.exc.HTTPNotFound()

        return webob.Response(status_int=202)
Exemplo n.º 7
0
    def create(self, req, type_id, body=None):
        """Create encryption specs for an existing volume type."""
        context = req.environ['cinder.context']
        authorize(context)

        if self._encrypted_type_in_use(context, type_id):
            expl = _('Cannot create encryption specs. Volume type in use.')
            raise webob.exc.HTTPBadRequest(explanation=expl)

        if not self.is_valid_body(body, 'encryption'):
            expl = _('Create body is not valid.')
            raise webob.exc.HTTPBadRequest(explanation=expl)

        self._check_type(context, type_id)

        encryption_specs = self._get_volume_type_encryption(context, type_id)
        if encryption_specs:
            raise exception.VolumeTypeEncryptionExists(type_id=type_id)

        encryption_specs = body['encryption']

        self._check_encryption_input(encryption_specs)

        db.volume_type_encryption_update_or_create(context, type_id,
                                                   encryption_specs)
        notifier_info = dict(type_id=type_id, specs=encryption_specs)
        notifier_api.notify(context, 'volumeTypeEncryption',
                            'volume_type_encryption.create',
                            notifier_api.INFO, notifier_info)
        return body
Exemplo n.º 8
0
    def update(self, req, type_id, id, body=None):
        """Update encryption specs for a given volume type."""
        context = req.environ['cinder.context']
        authorize(context)

        if not body:
            expl = _('Request body empty.')
            raise webob.exc.HTTPBadRequest(explanation=expl)
        if not self.is_valid_body(body, 'encryption'):
            expl = _('Update body is not valid. It must contain "encryption."')
            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_type(context, type_id)

        if self._encrypted_type_in_use(context, type_id):
            expl = _('Cannot update encryption specs. Volume type in use.')
            raise webob.exc.HTTPBadRequest(explanation=expl)

        encryption_specs = body['encryption']
        self._check_encryption_input(encryption_specs, create=False)

        db.volume_type_encryption_update(context, type_id, encryption_specs)
        notifier_info = dict(type_id=type_id, id=id)
        notifier_api.notify(context, 'volumeTypeEncryption',
                            'volume_type_encryption.update',
                            notifier_api.INFO, notifier_info)

        return body
Exemplo n.º 9
0
    def create(self, req, body=None):
        context = req.environ["cinder.context"]
        authorize(context)

        if not self.is_valid_body(body, "qos_specs"):
            raise webob.exc.HTTPBadRequest()

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

        try:
            qos_specs.create(context, name, specs)
            spec = qos_specs.get_qos_specs_by_name(context, name)
            notifier_info = dict(name=name, specs=specs)
            notifier_api.notify(context, "QoSSpecs", "QoSSpecs.create", notifier_api.INFO, notifier_info)
        except exception.InvalidInput as err:
            notifier_err = dict(name=name, error_message=str(err))
            self._notify_qos_specs_error(context, "qos_specs.create", notifier_err)
            raise webob.exc.HTTPBadRequest(explanation=str(err))
        except exception.QoSSpecsExists as err:
            notifier_err = dict(name=name, error_message=str(err))
            self._notify_qos_specs_error(context, "qos_specs.create", notifier_err)
            raise webob.exc.HTTPConflict(explanation=str(err))
        except exception.QoSSpecsCreateFailed as err:
            notifier_err = dict(name=name, error_message=str(err))
            self._notify_qos_specs_error(context, "qos_specs.create", notifier_err)
            raise webob.exc.HTTPInternalServerError(explanation=str(err))

        return self._view_builder.detail(req, spec)
Exemplo n.º 10
0
    def associations(self, req, id):
        """List all associations of given qos specs."""
        context = req.environ['cinder.context']
        authorize(context)

        LOG.debug("Get associations for qos_spec id: %s" % id)

        try:
            associates = qos_specs.get_associations(context, id)
            notifier_info = dict(id=id)
            notifier_api.notify(context, 'QoSSpecs',
                                'qos_specs.associations',
                                notifier_api.INFO, notifier_info)
        except exception.QoSSpecsNotFound as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context,
                                         'qos_specs.associations',
                                         notifier_err)
            raise webob.exc.HTTPNotFound(explanation=str(err))
        except exception.CinderException as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context,
                                         'qos_specs.associations',
                                         notifier_err)
            raise webob.exc.HTTPInternalServerError(explanation=str(err))

        return self._view_builder.associations(req, associates)
    def disassociate_all(self, req, id):
        """Disassociate a qos specs from all volume types."""
        context = req.environ['cinder.context']
        authorize(context)

        LOG.debug("Disassociate qos_spec: %s from all." % id)

        try:
            qos_specs.disassociate_all(context, id)
            notifier_info = dict(id=id)
            notifier_api.notify(context, 'QoSSpecs',
                                'qos_specs.disassociate_all',
                                notifier_api.INFO, notifier_info)
        except exception.QoSSpecsNotFound as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, 'qos_specs.disassociate_all',
                                         notifier_err)
            raise webob.exc.HTTPNotFound(explanation=str(err))
        except exception.QoSSpecsDisassociateFailed as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, 'qos_specs.disassociate_all',
                                         notifier_err)
            raise webob.exc.HTTPInternalServerError(explanation=str(err))

        return webob.Response(status_int=202)
Exemplo n.º 12
0
    def _reset_status(self, req, id, body):
        """Reset status on the resource."""
        context = req.environ['cinder.context']
        self.authorize(context, 'reset_status')
        update = self.validate_update(body['os-reset_status'])
        msg = _("Updating %(resource)s '%(id)s' with '%(update)r'")
        LOG.debug(msg, {
            'resource': self.resource_name,
            'id': id,
            'update': update
        })

        notifier_info = dict(id=id, update=update)
        notifier_api.notify(context, 'volumeStatusUpdate',
                            self.collection + '.reset_status.start',
                            notifier_api.INFO, notifier_info)

        try:
            self._update(context, id, update)
        except exception.NotFound as e:
            raise exc.HTTPNotFound(e)

        notifier_api.notify(context, 'volumeStatusUpdate',
                            self.collection + '.reset_status.end',
                            notifier_api.INFO, notifier_info)

        return webob.Response(status_int=202)
    def delete_keys(self, req, id, body):
        """Deletes specified keys in qos specs."""
        context = req.environ['cinder.context']
        authorize(context)

        if not (body and 'keys' in body
                and isinstance(body.get('keys'), list)):
            raise webob.exc.HTTPBadRequest()

        keys = body['keys']
        LOG.debug("Delete_key spec: %(id)s, keys: %(keys)s" % {
            'id': id,
            'keys': keys
        })

        try:
            qos_specs.delete_keys(context, id, keys)
            notifier_info = dict(id=id)
            notifier_api.notify(context, 'QoSSpecs', 'qos_specs.delete_keys',
                                notifier_api.INFO, notifier_info)
        except exception.QoSSpecsNotFound as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, 'qos_specs.delete_keys',
                                         notifier_err)
            raise webob.exc.HTTPNotFound(explanation=str(err))
        except exception.QoSSpecsKeyNotFound as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, 'qos_specs.delete_keys',
                                         notifier_err)
            raise webob.exc.HTTPBadRequest(explanation=str(err))

        return webob.Response(status_int=202)
Exemplo n.º 14
0
    def update(self, req, id, body=None):
        context = req.environ["cinder.context"]
        authorize(context)

        if not self.is_valid_body(body, "qos_specs"):
            raise webob.exc.HTTPBadRequest()
        specs = body["qos_specs"]
        try:
            qos_specs.update(context, id, specs)
            notifier_info = dict(id=id, specs=specs)
            notifier_api.notify(context, "QoSSpecs", "qos_specs.update", notifier_api.INFO, notifier_info)
        except exception.QoSSpecsNotFound as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, "qos_specs.update", notifier_err)
            raise webob.exc.HTTPNotFound(explanation=str(err))
        except exception.InvalidQoSSpecs as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, "qos_specs.update", notifier_err)
            raise webob.exc.HTTPBadRequest(explanation=str(err))
        except exception.QoSSpecsUpdateFailed as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, "qos_specs.update", notifier_err)
            raise webob.exc.HTTPInternalServerError(explanation=str(err))

        return body
Exemplo n.º 15
0
    def delete(self, req, id):
        """Deletes an existing qos specs."""
        context = req.environ["cinder.context"]
        authorize(context)

        force = req.params.get("force", None)

        # convert string to bool type in strict manner
        force = strutils.bool_from_string(force)
        LOG.debug("Delete qos_spec: %(id)s, force: %(force)s" % {"id": id, "force": force})

        try:
            qos_specs.delete(context, id, force)
            notifier_info = dict(id=id)
            notifier_api.notify(context, "QoSSpecs", "qos_specs.delete", notifier_api.INFO, notifier_info)
        except exception.QoSSpecsNotFound as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, "qos_specs.delete", notifier_err)
            raise webob.exc.HTTPNotFound(explanation=str(err))
        except exception.QoSSpecsInUse as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, "qos_specs.delete", notifier_err)
            if force:
                msg = _("Failed to disassociate qos specs.")
                raise webob.exc.HTTPInternalServerError(explanation=msg)
            msg = _("Qos specs still in use.")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        return webob.Response(status_int=202)
    def delete(self, req, id):
        """Deletes an existing qos specs."""
        context = req.environ['cinder.context']
        authorize(context)

        force = req.params.get('force', None)

        #convert string to bool type in strict manner
        force = strutils.bool_from_string(force)
        LOG.debug("Delete qos_spec: %(id)s, force: %(force)s" % {
            'id': id,
            'force': force
        })

        try:
            qos_specs.delete(context, id, force)
            notifier_info = dict(id=id)
            notifier_api.notify(context, 'QoSSpecs', 'qos_specs.delete',
                                notifier_api.INFO, notifier_info)
        except exception.QoSSpecsNotFound as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, 'qos_specs.delete',
                                         notifier_err)
            raise webob.exc.HTTPNotFound(explanation=str(err))
        except exception.QoSSpecsInUse as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, 'qos_specs.delete',
                                         notifier_err)
            if force:
                msg = _('Failed to disassociate qos specs.')
                raise webob.exc.HTTPInternalServerError(explanation=msg)
            msg = _('Qos specs still in use.')
            raise webob.exc.HTTPBadRequest(explanation=msg)

        return webob.Response(status_int=202)
    def create(self, req, type_id, body=None):
        """Create encryption specs for an existing volume type."""
        context = req.environ['cinder.context']
        authorize(context)

        if not self.is_valid_body(body, 'encryption'):
            expl = _('Create body is not valid.')
            raise webob.exc.HTTPBadRequest(explanation=expl)

        self._check_type(context, type_id)

        encryption_specs = self._get_volume_type_encryption(context, type_id)
        if encryption_specs:
            raise exception.VolumeTypeEncryptionExists(type_id=type_id)

        encryption_specs = body['encryption']

        self._check_encryption_input(encryption_specs)

        db.volume_type_encryption_update_or_create(context, type_id,
                                                   encryption_specs)
        notifier_info = dict(type_id=type_id, specs=encryption_specs)
        notifier_api.notify(context, 'volumeTypeEncryption',
                            'volume_type_encryption.create', notifier_api.INFO,
                            notifier_info)
        return body
Exemplo n.º 18
0
    def associations(self, req, id):
        """List all associations of given qos specs."""
        context = req.environ['cinder.context']
        authorize(context)

        LOG.debug("Get associations for qos_spec id: %s" % id)

        try:
            associates = qos_specs.get_associations(context, id)
            notifier_info = dict(id=id)
            notifier_api.notify(context, 'QoSSpecs',
                                'qos_specs.associations',
                                notifier_api.INFO, notifier_info)
        except exception.QoSSpecsNotFound as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context,
                                         'qos_specs.associations',
                                         notifier_err)
            raise webob.exc.HTTPNotFound(explanation=str(err))
        except exception.CinderException as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context,
                                         'qos_specs.associations',
                                         notifier_err)
            raise webob.exc.HTTPInternalServerError(explanation=str(err))

        return self._view_builder.associations(req, associates)
Exemplo n.º 19
0
    def delete_keys(self, req, id, body):
        """Deletes specified keys in qos specs."""
        context = req.environ["cinder.context"]
        authorize(context)

        if not (body and "keys" in body and isinstance(body.get("keys"), list)):
            raise webob.exc.HTTPBadRequest()

        keys = body["keys"]
        LOG.debug("Delete_key spec: %(id)s, keys: %(keys)s" % {"id": id, "keys": keys})

        try:
            qos_specs.delete_keys(context, id, keys)
            notifier_info = dict(id=id)
            notifier_api.notify(context, "QoSSpecs", "qos_specs.delete_keys", notifier_api.INFO, notifier_info)
        except exception.QoSSpecsNotFound as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, "qos_specs.delete_keys", notifier_err)
            raise webob.exc.HTTPNotFound(explanation=str(err))
        except exception.QoSSpecsKeyNotFound as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, "qos_specs.delete_keys", notifier_err)
            raise webob.exc.HTTPBadRequest(explanation=str(err))

        return webob.Response(status_int=202)
Exemplo n.º 20
0
    def delete(self, req, id):
        """Deletes an existing qos specs."""
        context = req.environ['cinder.context']
        authorize(context)

        force = req.params.get('force', None)

        LOG.debug("Delete qos_spec: %(id)s, force: %(force)s" %
                  {'id': id, 'force': force})

        try:
            qos_specs.get_qos_specs(context, id)
            qos_specs.delete(context, id, force)
            notifier_info = dict(id=id)
            notifier_api.notify(context, 'QoSSpecs',
                                'qos_specs.delete',
                                notifier_api.INFO, notifier_info)
        except exception.QoSSpecsNotFound as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context,
                                         'qos_specs.delete',
                                         notifier_err)
            raise webob.exc.HTTPNotFound(explanation=str(err))
        except exception.QoSSpecsInUse as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context,
                                         'qos_specs.delete',
                                         notifier_err)
            if force:
                msg = _('Failed to disassociate qos specs.')
                raise webob.exc.HTTPInternalServerError(explanation=msg)
            msg = _('Qos specs still in use.')
            raise webob.exc.HTTPBadRequest(explanation=msg)

        return webob.Response(status_int=202)
Exemplo n.º 21
0
    def create(self, req, type_id, body=None):
        """Create encryption specs for an existing volume type."""
        context = req.environ["cinder.context"]
        authorize(context)

        if not self.is_valid_body(body, "encryption"):
            expl = _("Create body is not valid.")
            raise webob.exc.HTTPBadRequest(explanation=expl)

        self._check_type(context, type_id)

        encryption_specs = self._get_volume_type_encryption(context, type_id)
        if encryption_specs:
            raise exception.VolumeTypeEncryptionExists(type_id=type_id)

        encryption_specs = body["encryption"]

        self._check_encryption_input(encryption_specs)

        db.volume_type_encryption_update_or_create(context, type_id, encryption_specs)
        notifier_info = dict(type_id=type_id, specs=encryption_specs)
        notifier_api.notify(
            context, "volumeTypeEncryption", "volume_type_encryption.create", notifier_api.INFO, notifier_info
        )
        return body
Exemplo n.º 22
0
    def disassociate(self, req, id):
        """Disassociate a qos specs from a volume type."""
        context = req.environ["cinder.context"]
        authorize(context)

        type_id = req.params.get("vol_type_id", None)

        if not type_id:
            msg = _("Volume Type id must not be None.")
            notifier_err = dict(id=id, error_message=msg)
            self._notify_qos_specs_error(context, "qos_specs.delete", notifier_err)
            raise webob.exc.HTTPBadRequest(explanation=msg)
        LOG.debug("Disassociate qos_spec: %(id)s from type: %(type_id)s" % {"id": id, "type_id": type_id})

        try:
            qos_specs.disassociate_qos_specs(context, id, type_id)
            notifier_info = dict(id=id, type_id=type_id)
            notifier_api.notify(context, "QoSSpecs", "qos_specs.disassociate", notifier_api.INFO, notifier_info)
        except exception.VolumeTypeNotFound as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, "qos_specs.disassociate", notifier_err)
            raise webob.exc.HTTPNotFound(explanation=str(err))
        except exception.QoSSpecsNotFound as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, "qos_specs.disassociate", notifier_err)
            raise webob.exc.HTTPNotFound(explanation=str(err))
        except exception.QoSSpecsDisassociateFailed as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, "qos_specs.disassociate", notifier_err)
            raise webob.exc.HTTPInternalServerError(explanation=str(err))

        return webob.Response(status_int=202)
Exemplo n.º 23
0
    def disassociate_all(self, req, id):
        """Disassociate a qos specs from all volume types."""
        context = req.environ['cinder.context']
        authorize(context)

        LOG.debug("Disassociate qos_spec: %s from all." % id)

        try:
            qos_specs.disassociate_all(context, id)
            notifier_info = dict(id=id)
            notifier_api.notify(context, 'QoSSpecs',
                                'qos_specs.disassociate_all',
                                notifier_api.INFO, notifier_info)
        except exception.QoSSpecsNotFound as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context,
                                         'qos_specs.disassociate_all',
                                         notifier_err)
            raise webob.exc.HTTPNotFound(explanation=str(err))
        except exception.QoSSpecsDisassociateFailed as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context,
                                         'qos_specs.disassociate_all',
                                         notifier_err)
            raise webob.exc.HTTPInternalServerError(explanation=str(err))

        return webob.Response(status_int=202)
    def update(self, req, id, body=None):
        context = req.environ['cinder.context']
        authorize(context)

        if not self.is_valid_body(body, 'qos_specs'):
            raise webob.exc.HTTPBadRequest()
        specs = body['qos_specs']
        try:
            qos_specs.update(context, id, specs)
            notifier_info = dict(id=id, specs=specs)
            notifier_api.notify(context, 'QoSSpecs', 'qos_specs.update',
                                notifier_api.INFO, notifier_info)
        except exception.QoSSpecsNotFound as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, 'qos_specs.update',
                                         notifier_err)
            raise webob.exc.HTTPNotFound(explanation=str(err))
        except exception.InvalidQoSSpecs as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, 'qos_specs.update',
                                         notifier_err)
            raise webob.exc.HTTPBadRequest(explanation=str(err))
        except exception.QoSSpecsUpdateFailed as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, 'qos_specs.update',
                                         notifier_err)
            raise webob.exc.HTTPInternalServerError(explanation=str(err))

        return body
Exemplo n.º 25
0
def notify_about_volume_usage(context, volume, event_suffix, extra_usage_info=None, host=None):
    if not host:
        host = CONF.host

    if not extra_usage_info:
        extra_usage_info = {}

    usage_info = _usage_from_volume(context, volume, **extra_usage_info)

    notifier_api.notify(context, "volume.%s" % host, "volume.%s" % event_suffix, notifier_api.INFO, usage_info)
Exemplo n.º 26
0
def notify_about_snapshot_usage(context, snapshot, event_suffix, extra_usage_info=None, host=None):
    if not host:
        host = CONF.host

    if not extra_usage_info:
        extra_usage_info = {}

    usage_info = _usage_from_snapshot(context, snapshot, **extra_usage_info)

    notifier_api.notify(context, "snapshot.%s" % host, "snapshot.%s" % event_suffix, notifier_api.INFO, usage_info)
Exemplo n.º 27
0
 def delete(self, req, type_id, id):
     """ Deletes an existing extra spec """
     context = req.environ['cinder.context']
     self._check_type(context, type_id)
     authorize(context)
     db.volume_type_extra_specs_delete(context, type_id, id)
     notifier_info = dict(type_id=type_id, id=id)
     notifier_api.notify(context, 'volumeTypeExtraSpecs',
                         'volume_type_extra_specs.delete',
                         notifier_api.INFO, notifier_info)
     return webob.Response(status_int=202)
Exemplo n.º 28
0
 def delete(self, req, type_id, id):
     """ Deletes an existing extra spec """
     context = req.environ['cinder.context']
     self._check_type(context, type_id)
     authorize(context)
     db.volume_type_extra_specs_delete(context, type_id, id)
     notifier_info = dict(type_id=type_id, id=id)
     notifier_api.notify(context, 'volumeTypeExtraSpecs',
                         'volume_type_extra_specs.delete',
                         notifier_api.INFO, notifier_info)
     return webob.Response(status_int=202)
Exemplo n.º 29
0
    def associate(self, req, id):
        """Associate a qos specs with a volume type."""
        context = req.environ['cinder.context']
        authorize(context)

        type_id = req.params.get('vol_type_id', None)

        if not type_id:
            msg = _('Volume Type id must not be None.')
            notifier_err = dict(id=id, error_message=msg)
            self._notify_qos_specs_error(context,
                                         'qos_specs.delete',
                                         notifier_err)
            raise webob.exc.HTTPBadRequest(explanation=msg)
        LOG.debug("Associate qos_spec: %(id)s with type: %(type_id)s" %
                  {'id': id, 'type_id': type_id})

        try:
            qos_specs.associate_qos_with_type(context, id, type_id)
            notifier_info = dict(id=id, type_id=type_id)
            notifier_api.notify(context, 'QoSSpecs',
                                'qos_specs.associate',
                                notifier_api.INFO, notifier_info)
        except exception.VolumeTypeNotFound as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context,
                                         'qos_specs.associate',
                                         notifier_err)
            raise webob.exc.HTTPNotFound(explanation=str(err))
        except exception.QoSSpecsNotFound as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context,
                                         'qos_specs.associate',
                                         notifier_err)
            raise webob.exc.HTTPNotFound(explanation=str(err))
        except exception.InvalidVolumeType as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context,
                                         'qos_specs.associate',
                                         notifier_err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.associate',
                                         notifier_err)
            raise webob.exc.HTTPBadRequest(explanation=str(err))
        except exception.QoSSpecsAssociateFailed as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context,
                                         'qos_specs.associate',
                                         notifier_err)
            raise webob.exc.HTTPInternalServerError(explanation=str(err))

        return webob.Response(status_int=202)
Exemplo n.º 30
0
def notify_about_volume_usage(context, volume, event_suffix,
                              extra_usage_info=None, host=None):
    if not host:
        host = FLAGS.host

    if not extra_usage_info:
        extra_usage_info = {}

    usage_info = _usage_from_volume(context, volume, **extra_usage_info)

    notifier_api.notify(context, 'volume.%s' % host,
                        'volume.%s' % event_suffix,
                        notifier_api.INFO, usage_info)
Exemplo n.º 31
0
    def create(self, req, type_id, body=None):
        context = req.environ['cinder.context']
        authorize(context)

        if not self.is_valid_body(body, 'extra_specs'):
            raise webob.exc.HTTPBadRequest()

        self._check_type(context, type_id)

        specs = body['extra_specs']
        db.volume_type_extra_specs_update_or_create(context, type_id, specs)
        notifier_info = dict(type_id=type_id, specs=specs)
        notifier_api.notify(context, 'volumeTypeExtraSpecs',
                            'volume_type_extra_specs.create',
                            notifier_api.INFO, notifier_info)
        return body
Exemplo n.º 32
0
    def delete(self, req, type_id, id):
        """Deletes an existing extra spec."""
        context = req.environ['cinder.context']
        self._check_type(context, type_id)
        authorize(context)

        try:
            db.volume_type_extra_specs_delete(context, type_id, id)
        except exception.VolumeTypeExtraSpecsNotFound as error:
            raise webob.exc.HTTPNotFound(explanation=error.msg)

        notifier_info = dict(type_id=type_id, id=id)
        notifier_api.notify(context, 'volumeTypeExtraSpecs',
                            'volume_type_extra_specs.delete',
                            notifier_api.INFO, notifier_info)
        return webob.Response(status_int=202)
Exemplo n.º 33
0
def notify_about_snapshot_usage(context,
                                snapshot,
                                event_suffix,
                                extra_usage_info=None,
                                host=None):
    if not host:
        host = CONF.host

    if not extra_usage_info:
        extra_usage_info = {}

    usage_info = _usage_from_snapshot(context, snapshot, **extra_usage_info)

    notifier_api.notify(context, 'snapshot.%s' % host,
                        'snapshot.%s' % event_suffix, notifier_api.INFO,
                        usage_info)
    def associate(self, req, id):
        """Associate a qos specs with a volume type."""
        context = req.environ['cinder.context']
        authorize(context)

        type_id = req.params.get('vol_type_id', None)

        if not type_id:
            msg = _('Volume Type id must not be None.')
            notifier_err = dict(id=id, error_message=msg)
            self._notify_qos_specs_error(context, 'qos_specs.delete',
                                         notifier_err)
            raise webob.exc.HTTPBadRequest(explanation=msg)
        LOG.debug("Associate qos_spec: %(id)s with type: %(type_id)s" % {
            'id': id,
            'type_id': type_id
        })

        try:
            qos_specs.associate_qos_with_type(context, id, type_id)
            notifier_info = dict(id=id, type_id=type_id)
            notifier_api.notify(context, 'QoSSpecs', 'qos_specs.associate',
                                notifier_api.INFO, notifier_info)
        except exception.VolumeTypeNotFound as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, 'qos_specs.associate',
                                         notifier_err)
            raise webob.exc.HTTPNotFound(explanation=str(err))
        except exception.QoSSpecsNotFound as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, 'qos_specs.associate',
                                         notifier_err)
            raise webob.exc.HTTPNotFound(explanation=str(err))
        except exception.InvalidVolumeType as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, 'qos_specs.associate',
                                         notifier_err)
            self._notify_qos_specs_error(context, 'qos_specs.associate',
                                         notifier_err)
            raise webob.exc.HTTPBadRequest(explanation=str(err))
        except exception.QoSSpecsAssociateFailed as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, 'qos_specs.associate',
                                         notifier_err)
            raise webob.exc.HTTPInternalServerError(explanation=str(err))

        return webob.Response(status_int=202)
Exemplo n.º 35
0
    def create(self, req, type_id, body=None):
        context = req.environ['cinder.context']
        authorize(context)

        if not self.is_valid_body(body, 'extra_specs'):
            raise webob.exc.HTTPBadRequest()

        self._check_type(context, type_id)
        specs = body['extra_specs']
        self._check_key_names(specs.keys())
        db.volume_type_extra_specs_update_or_create(context,
                                                    type_id,
                                                    specs)
        notifier_info = dict(type_id=type_id, specs=specs)
        notifier_api.notify(context, 'volumeTypeExtraSpecs',
                            'volume_type_extra_specs.create',
                            notifier_api.INFO, notifier_info)
        return body
Exemplo n.º 36
0
 def _notify_failure(cause):
     """When scheduling fails send out a event that it failed."""
     topic = "scheduler.create_volume"
     payload = {
         'request_spec': request_spec,
         'volume_properties': request_spec.get('volume_properties', {}),
         'volume_id': volume_id,
         'state': 'error',
         'method': 'create_volume',
         'reason': cause,
     }
     try:
         publisher_id = notifier.publisher_id("scheduler")
         notifier.notify(context, publisher_id, topic, notifier.ERROR,
                         payload)
     except exception.CinderException:
         LOG.exception(_("Failed notifying on %(topic)s "
                         "payload %(payload)s") % {'topic': topic,
                                                   'payload': payload})
Exemplo n.º 37
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)
     db.volume_type_extra_specs_update_or_create(context, type_id, body)
     notifier_info = dict(type_id=type_id, id=id)
     notifier_api.notify(context, 'volumeTypeExtraSpecs',
                         'volume_type_extra_specs.update',
                         notifier_api.INFO, notifier_info)
     return body
Exemplo n.º 38
0
    def disassociate(self, req, id):
        """Disassociate a qos specs from a volume type."""
        context = req.environ['cinder.context']
        authorize(context)

        type_id = req.params.get('vol_type_id', None)

        if not type_id:
            msg = _('Volume Type id must not be None.')
            notifier_err = dict(id=id, error_message=msg)
            self._notify_qos_specs_error(context,
                                         'qos_specs.delete',
                                         notifier_err)
            raise webob.exc.HTTPBadRequest(explanation=msg)
        LOG.debug("disassocicate(): id: %s, type_id: %s" % (id, type_id))

        try:
            qos_specs.get_qos_specs(context, id)
            qos_specs.disassociate_qos_specs(context, id, type_id)
            notifier_info = dict(id=id, type_id=type_id)
            notifier_api.notify(context, 'QoSSpecs',
                                'qos_specs.disassociate',
                                notifier_api.INFO, notifier_info)
        except exception.VolumeTypeNotFound as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context,
                                         'qos_specs.disassociate',
                                         notifier_err)
            raise webob.exc.HTTPNotFound(explanation=err)
        except exception.QoSSpecsNotFound as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context,
                                         'qos_specs.disassociate',
                                         notifier_err)
            raise webob.exc.HTTPNotFound(explanation=err)
        except exception.QoSSpecsDisassociateFailed as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context,
                                         'qos_specs.disassociate',
                                         notifier_err)
            raise webob.exc.HTTPInternalServerError(explanation=err)

        return webob.Response(status_int=202)
Exemplo n.º 39
0
    def _set_volume_state_and_notify(self, method, updates, context, ex,
                                     request_spec):
        LOG.warning(_("Failed to schedule_%(method)s: %(ex)s") % locals())

        volume_state = updates['volume_state']
        properties = request_spec.get('volume_properties', {})

        volume_id = request_spec.get('volume_id', None)

        if volume_id:
            db.volume_update(context, volume_id, volume_state)

        payload = dict(request_spec=request_spec,
                       volume_properties=properties,
                       volume_id=volume_id,
                       state=volume_state,
                       method=method,
                       reason=ex)

        notifier.notify(context, notifier.publisher_id("scheduler"),
                        'scheduler.' + method, notifier.ERROR, payload)
Exemplo n.º 40
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)
     db.volume_type_extra_specs_update_or_create(context,
                                                 type_id,
                                                 body)
     notifier_info = dict(type_id=type_id, id=id)
     notifier_api.notify(context, 'volumeTypeExtraSpecs',
                         'volume_type_extra_specs.update',
                         notifier_api.INFO, notifier_info)
     return body
Exemplo n.º 41
0
    def _set_volume_state_and_notify(self, method, updates, context, ex,
                                     request_spec):
        LOG.error(_("Failed to schedule_%(method)s: %(ex)s") % locals())

        volume_state = updates['volume_state']
        properties = request_spec.get('volume_properties', {})

        volume_id = request_spec.get('volume_id', None)

        if volume_id:
            db.volume_update(context, volume_id, volume_state)

        payload = dict(request_spec=request_spec,
                       volume_properties=properties,
                       volume_id=volume_id,
                       state=volume_state,
                       method=method,
                       reason=ex)

        notifier.notify(context, notifier.publisher_id("scheduler"),
                        'scheduler.' + method, notifier.ERROR, payload)
Exemplo n.º 42
0
    def create(self, req, body=None):
        context = req.environ['cinder.context']
        authorize(context)

        if not self.is_valid_body(body, 'qos_specs'):
            raise webob.exc.HTTPBadRequest()

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

        try:
            specs_ref = qos_specs.create(context, name, specs)
            qos_specs.get_qos_specs_by_name(context, name)
            notifier_info = dict(name=name, specs=specs)
            notifier_api.notify(context, 'QoSSpecs',
                                'QoSSpecs.create',
                                notifier_api.INFO, notifier_info)
        except exception.InvalidInput as err:
            notifier_err = dict(name=name, error_message=str(err))
            self._notify_qos_specs_error(context,
                                         'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPBadRequest(explanation=str(err))
        except exception.QoSSpecsExists as err:
            notifier_err = dict(name=name, error_message=str(err))
            self._notify_qos_specs_error(context,
                                         'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPConflict(explanation=str(err))
        except exception.QoSSpecsCreateFailed as err:
            notifier_err = dict(name=name, error_message=str(err))
            self._notify_qos_specs_error(context,
                                         'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPInternalServerError(explanation=str(err))

        return body
Exemplo n.º 43
0
    def create(self, req, body=None):
        context = req.environ['cinder.context']
        authorize(context)

        if not self.is_valid_body(body, 'qos_specs'):
            raise webob.exc.HTTPBadRequest()

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

        try:
            qos_specs.create(context, name, specs)
            spec = qos_specs.get_qos_specs_by_name(context, name)
            notifier_info = dict(name=name, specs=specs)
            notifier_api.notify(context, 'QoSSpecs',
                                'QoSSpecs.create',
                                notifier_api.INFO, notifier_info)
        except exception.InvalidInput as err:
            notifier_err = dict(name=name, error_message=str(err))
            self._notify_qos_specs_error(context,
                                         'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPBadRequest(explanation=str(err))
        except exception.QoSSpecsExists as err:
            notifier_err = dict(name=name, error_message=str(err))
            self._notify_qos_specs_error(context,
                                         'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPConflict(explanation=str(err))
        except exception.QoSSpecsCreateFailed as err:
            notifier_err = dict(name=name, error_message=str(err))
            self._notify_qos_specs_error(context,
                                         'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPInternalServerError(explanation=str(err))

        return self._view_builder.detail(req, spec)
Exemplo n.º 44
0
 def _notify_failure(cause):
     """When scheduling fails send out a event that it failed."""
     topic = "scheduler.create_volume"
     payload = {
         'request_spec': request_spec,
         'volume_properties': request_spec.get('volume_properties', {}),
         'volume_id': volume_id,
         'state': 'error',
         'method': 'create_volume',
         'reason': cause,
     }
     try:
         publisher_id = notifier.publisher_id("scheduler")
         notifier.notify(context, publisher_id, topic, notifier.ERROR,
                         payload)
     except exception.CinderException:
         LOG.exception(
             _("Failed notifying on %(topic)s "
               "payload %(payload)s") % {
                   'topic': topic,
                   'payload': payload
               })
Exemplo n.º 45
0
    def _set_volume_state_and_notify(self, method, updates, context, ex, request_spec):
        # TODO(harlowja): move into a task that just does this later.

        LOG.error(_("Failed to schedule_%(method)s: %(ex)s") % {"method": method, "ex": ex})

        volume_state = updates["volume_state"]
        properties = request_spec.get("volume_properties", {})

        volume_id = request_spec.get("volume_id", None)

        if volume_id:
            db.volume_update(context, volume_id, volume_state)

        payload = dict(
            request_spec=request_spec,
            volume_properties=properties,
            volume_id=volume_id,
            state=volume_state,
            method=method,
            reason=ex,
        )

        notifier.notify(context, notifier.publisher_id("scheduler"), "scheduler." + method, notifier.ERROR, payload)
Exemplo n.º 46
0
    def _reset_status(self, req, id, body):
        """Reset status on the resource."""
        context = req.environ['cinder.context']
        self.authorize(context, 'reset_status')
        update = self.validate_update(body['os-reset_status'])
        msg = _("Updating %(resource)s '%(id)s' with '%(update)r'")
        LOG.debug(msg, {'resource': self.resource_name, 'id': id,
                        'update': update})

        notifier_info = dict(id=id, update=update)
        notifier_api.notify(context, 'volumeStatusUpdate',
                            self.collection + '.reset_status.start',
                            notifier_api.INFO, notifier_info)

        try:
            self._update(context, id, update)
        except exception.NotFound as e:
            raise exc.HTTPNotFound(e)

        notifier_api.notify(context, 'volumeStatusUpdate',
                            self.collection + '.reset_status.end',
                            notifier_api.INFO, notifier_info)

        return webob.Response(status_int=202)
 def _notify_qos_specs_error(context, method, payload):
     notifier_api.notify(context, 'QoSSpecs', method, notifier_api.ERROR,
                         payload)
Exemplo n.º 48
0
 def _notify_qos_specs_error(context, method, payload):
     notifier_api.notify(context, "QoSSpecs", method, notifier_api.ERROR, payload)
Exemplo n.º 49
0
 def _notify_voloume_type_error(self, context, method, payload):
     notifier_api.notify(context,
                         'volumeType',
                         method,
                         notifier_api.ERROR,
                         payload)