Ejemplo n.º 1
0
    def _set_share_state_and_notify(self, method, state, context, ex,
                                    request_spec, action=None):

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

        properties = request_spec.get('share_properties', {})

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

        if share_id:
            db.share_update(context, share_id, state)

        if action:
            self.message_api.create(
                context, action, context.project_id,
                resource_type=message_field.Resource.SHARE,
                resource_id=share_id, exception=ex)

        payload = dict(request_spec=request_spec,
                       share_properties=properties,
                       share_id=share_id,
                       state=state,
                       method=method,
                       reason=ex)

        rpc.get_notifier("scheduler").error(
            context, 'scheduler.' + method, payload)
Ejemplo n.º 2
0
    def _delete(self, req, id):
        """Deletes an existing volume type."""
        context = req.environ['manila.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)
            rpc.get_notifier('volumeType').info(
                context, 'volume_type.delete', notifier_info)
        except exception.VolumeTypeInUse as err:
            notifier_err = dict(id=id, error_message=six.text_type(err))
            self._notify_volume_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=six.text_type(err))
            self._notify_volume_type_error(context,
                                           'volume_type.delete',
                                           notifier_err)

            raise webob.exc.HTTPNotFound()

        return webob.Response(status_int=202)
Ejemplo n.º 3
0
    def _delete(self, req, id):
        """Deletes an existing volume type."""
        context = req.environ['manila.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)
            rpc.get_notifier('volumeType').info(context, 'volume_type.delete',
                                                notifier_info)
        except exception.VolumeTypeInUse as err:
            notifier_err = dict(id=id, error_message=six.text_type(err))
            self._notify_volume_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=six.text_type(err))
            self._notify_volume_type_error(context, 'volume_type.delete',
                                           notifier_err)

            raise webob.exc.HTTPNotFound()

        return webob.Response(status_int=202)
Ejemplo n.º 4
0
    def _create(self, req, body, set_defaults=False):
        """Creates a new share type."""
        context = req.environ['manila.context']

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

        elif self.is_valid_body(body, 'share_type'):
            share_type = body['share_type']
        else:
            share_type = body['volume_type']
        name = share_type.get('name')
        specs = share_type.get('extra_specs', {})
        is_public = share_type.get(
            'os-share-type-access:is_public',
            share_type.get('share_type_access:is_public', True),
        )

        if name is None or name == "" or len(name) > 255:
            msg = _("Type name is not valid.")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        # Note(cknight): Set the default extra spec value for snapshot_support
        # for API versions before it was required.
        if set_defaults:
            if constants.ExtraSpecs.SNAPSHOT_SUPPORT not in specs:
                specs[constants.ExtraSpecs.SNAPSHOT_SUPPORT] = True

        try:
            required_extra_specs = (
                share_types.get_valid_required_extra_specs(specs)
            )
            share_types.create(context, name, specs, is_public)
            share_type = share_types.get_share_type_by_name(context, name)
            share_type['required_extra_specs'] = required_extra_specs
            req.cache_db_share_type(share_type)
            notifier_info = dict(share_types=share_type)
            rpc.get_notifier('shareType').info(
                context, 'share_type.create', notifier_info)

        except exception.InvalidExtraSpec as e:
            raise webob.exc.HTTPBadRequest(explanation=six.text_type(e))
        except exception.ShareTypeExists as err:
            notifier_err = dict(share_types=share_type,
                                error_message=six.text_type(err))
            self._notify_share_type_error(context, 'share_type.create',
                                          notifier_err)

            raise webob.exc.HTTPConflict(explanation=six.text_type(err))
        except exception.NotFound as err:
            notifier_err = dict(share_types=share_type,
                                error_message=six.text_type(err))
            self._notify_share_type_error(context, 'share_type.create',
                                          notifier_err)
            raise webob.exc.HTTPNotFound()

        return self._view_builder.show(req, share_type)
Ejemplo n.º 5
0
    def _create(self, req, body, set_defaults=False):
        """Creates a new share type."""
        context = req.environ['manila.context']

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

        elif self.is_valid_body(body, 'share_type'):
            share_type = body['share_type']
        else:
            share_type = body['volume_type']
        name = share_type.get('name')
        specs = share_type.get('extra_specs', {})
        is_public = share_type.get(
            'os-share-type-access:is_public',
            share_type.get('share_type_access:is_public', True),
        )

        if name is None or name == "" or len(name) > 255:
            msg = _("Type name is not valid.")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        # Note(cknight): Set the default extra spec value for snapshot_support
        # for API versions before it was required.
        if set_defaults:
            if constants.ExtraSpecs.SNAPSHOT_SUPPORT not in specs:
                specs[constants.ExtraSpecs.SNAPSHOT_SUPPORT] = True

        try:
            required_extra_specs = (
                share_types.get_valid_required_extra_specs(specs)
            )
            share_types.create(context, name, specs, is_public)
            share_type = share_types.get_share_type_by_name(context, name)
            share_type['required_extra_specs'] = required_extra_specs
            req.cache_db_share_type(share_type)
            notifier_info = dict(share_types=share_type)
            rpc.get_notifier('shareType').info(
                context, 'share_type.create', notifier_info)

        except exception.InvalidExtraSpec as e:
            raise webob.exc.HTTPBadRequest(explanation=six.text_type(e))
        except exception.ShareTypeExists as err:
            notifier_err = dict(share_types=share_type,
                                error_message=six.text_type(err))
            self._notify_share_type_error(context, 'share_type.create',
                                          notifier_err)

            raise webob.exc.HTTPConflict(explanation=six.text_type(err))
        except exception.NotFound as err:
            notifier_err = dict(share_types=share_type,
                                error_message=six.text_type(err))
            self._notify_share_type_error(context, 'share_type.create',
                                          notifier_err)
            raise webob.exc.HTTPNotFound()

        return self._view_builder.show(req, share_type)
Ejemplo n.º 6
0
    def _create(self, req, body):
        """Creates a new share type."""
        context = req.environ['manila.context']

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

        elif self.is_valid_body(body, 'share_type'):
            share_type = body['share_type']
        else:
            share_type = body['volume_type']
        name = share_type.get('name', None)
        specs = share_type.get('extra_specs', {})
        is_public = share_type.get(
            'os-share-type-access:is_public',
            share_type.get('share_type_access:is_public', True),
        )

        if name is None or name == "" or len(name) > 255:
            msg = _("Type name is not valid.")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        try:
            required_extra_specs = (
                share_types.get_valid_required_extra_specs(specs)
            )
        except exception.InvalidExtraSpec as e:
            raise webob.exc.HTTPBadRequest(explanation=six.text_type(e))

        try:
            share_types.create(context, name, specs, is_public)
            share_type = share_types.get_share_type_by_name(context, name)
            share_type['required_extra_specs'] = required_extra_specs
            req.cache_db_share_type(share_type)
            notifier_info = dict(share_types=share_type)
            rpc.get_notifier('shareType').info(
                context, 'share_type.create', notifier_info)

        except exception.ShareTypeExists as err:
            notifier_err = dict(share_types=share_type,
                                error_message=six.text_type(err))
            self._notify_share_type_error(context, 'share_type.create',
                                          notifier_err)

            raise webob.exc.HTTPConflict(explanation=six.text_type(err))
        except exception.NotFound as err:
            notifier_err = dict(share_types=share_type,
                                error_message=six.text_type(err))
            self._notify_share_type_error(context, 'share_type.create',
                                          notifier_err)
            raise webob.exc.HTTPNotFound()

        return self._view_builder.show(req, share_type)
Ejemplo n.º 7
0
def notify_about_share_usage(context, share, share_instance,
                             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_share(share, share_instance, **extra_usage_info)

    rpc.get_notifier("share", host).info(context, 'share.%s' % event_suffix,
                                         usage_info)
Ejemplo n.º 8
0
def notify_about_share_usage(context,
                             share,
                             share_instance,
                             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_share(share, share_instance, **extra_usage_info)

    rpc.get_notifier("share", host).info(context, 'share.%s' % event_suffix,
                                         usage_info)
Ejemplo n.º 9
0
    def _set_share_error_state_and_notify(self, method, context, ex, request_spec):
        LOG.error(_LE("Failed to schedule_%(method)s: %(ex)s"), {"method": method, "ex": ex})

        share_state = {"status": "error"}
        properties = request_spec.get("share_properties", {})

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

        if share_id:
            db.share_update(context, share_id, share_state)

        payload = dict(
            request_spec=request_spec,
            share_properties=properties,
            share_id=share_id,
            state=share_state,
            method=method,
            reason=ex,
        )

        rpc.get_notifier("scheduler").error(context, "scheduler." + method, payload)
Ejemplo n.º 10
0
    def _set_share_error_state_and_notify(self, method, context, ex,
                                          request_spec):
        LOG.warning(_("Failed to schedule_%(method)s: %(ex)s") % locals())

        share_state = {'status': 'error'}
        properties = request_spec.get('share_properties', {})

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

        if share_id:
            db.share_update(context, share_id, share_state)

        payload = dict(request_spec=request_spec,
                       share_properties=properties,
                       share_id=share_id,
                       state=share_state,
                       method=method,
                       reason=ex)

        rpc.get_notifier("scheduler").error(
            context, 'scheduler.' + method, payload)
Ejemplo n.º 11
0
    def _set_share_state_and_notify(self, method, state, context, ex,
                                    request_spec):

        LOG.error(_LE("Failed to schedule %(method)s: %(ex)s"),
                  {"method": method, "ex": six.text_type(ex)})

        properties = request_spec.get('share_properties', {})

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

        if share_id:
            db.share_update(context, share_id, state)

        payload = dict(request_spec=request_spec,
                       share_properties=properties,
                       share_id=share_id,
                       state=state,
                       method=method,
                       reason=ex)

        rpc.get_notifier("scheduler").error(
            context, 'scheduler.' + method, payload)
Ejemplo n.º 12
0
    def _create(self, req, body):
        """Creates a new volume type."""
        context = req.environ['manila.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 == "" or len(name) > 255:
            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)
            rpc.get_notifier('volumeType').info(
                context, 'volume_type.create', notifier_info)

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

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

        return self._view_builder.show(req, vol_type)
Ejemplo n.º 13
0
    def _set_share_state_and_notify(self, method, state, context, ex,
                                    request_spec):

        LOG.error(_LE("Failed to schedule %(method)s: %(ex)s"),
                  {"method": method, "ex": six.text_type(ex)})

        properties = request_spec.get('share_properties', {})

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

        if share_id:
            db.share_update(context, share_id, state)

        payload = dict(request_spec=request_spec,
                       share_properties=properties,
                       share_id=share_id,
                       state=state,
                       method=method,
                       reason=ex)

        rpc.get_notifier("scheduler").error(
            context, 'scheduler.' + method, payload)
Ejemplo n.º 14
0
    def _create(self, req, body):
        """Creates a new volume type."""
        context = req.environ['manila.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 == "" or len(name) > 255:
            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)
            rpc.get_notifier('volumeType').info(context, 'volume_type.create',
                                                notifier_info)

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

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

        return self._view_builder.show(req, vol_type)
    def create(self, req, type_id, body=None):
        context = req.environ['manila.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._verify_extra_specs(specs, False)
        self._check_key_names(specs.keys())
        db.share_type_extra_specs_update_or_create(context, type_id, specs)
        notifier_info = dict(type_id=type_id, specs=specs)
        notifier = rpc.get_notifier('shareTypeExtraSpecs')
        notifier.info(context, 'share_type_extra_specs.create', notifier_info)
        return body
Ejemplo n.º 16
0
    def _delete(self, req, id):
        """Deletes an existing share type."""
        context = req.environ['manila.context']

        try:
            share_type = share_types.get_share_type(context, id)
            share_types.destroy(context, share_type['id'])
            notifier_info = dict(share_types=share_type)
            rpc.get_notifier('shareType').info(
                context, 'share_type.delete', notifier_info)
        except exception.ShareTypeInUse as err:
            notifier_err = dict(id=id, error_message=six.text_type(err))
            self._notify_share_type_error(context, 'share_type.delete',
                                          notifier_err)
            msg = 'Target share type is still in use.'
            raise webob.exc.HTTPBadRequest(explanation=msg)
        except exception.NotFound as err:
            notifier_err = dict(id=id, error_message=six.text_type(err))
            self._notify_share_type_error(context, 'share_type.delete',
                                          notifier_err)

            raise webob.exc.HTTPNotFound()

        return webob.Response(status_int=http_client.ACCEPTED)
Ejemplo n.º 17
0
    def delete(self, req, type_id, id):
        """Deletes an existing extra spec."""
        context = req.environ['manila.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 = rpc.get_notifier('volumeTypeExtraSpecs')
        notifier.info(context, 'volume_type_extra_specs.delete', notifier_info)
        return webob.Response(status_int=202)
Ejemplo n.º 18
0
    def _delete(self, req, id):
        """Deletes an existing share type."""
        context = req.environ['manila.context']

        try:
            share_type = share_types.get_share_type(context, id)
            share_types.destroy(context, share_type['id'])
            notifier_info = dict(share_types=share_type)
            rpc.get_notifier('shareType').info(context, 'share_type.delete',
                                               notifier_info)
        except exception.ShareTypeInUse as err:
            notifier_err = dict(id=id, error_message=six.text_type(err))
            self._notify_share_type_error(context, 'share_type.delete',
                                          notifier_err)
            msg = 'Target share type is still in use.'
            raise webob.exc.HTTPBadRequest(explanation=msg)
        except exception.NotFound as err:
            notifier_err = dict(id=id, error_message=six.text_type(err))
            self._notify_share_type_error(context, 'share_type.delete',
                                          notifier_err)

            raise webob.exc.HTTPNotFound()

        return webob.Response(status_int=http_client.ACCEPTED)
Ejemplo n.º 19
0
    def delete(self, req, type_id, id):
        """Deletes an existing extra spec."""
        context = req.environ['manila.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 = rpc.get_notifier('volumeTypeExtraSpecs')
        notifier.info(context, 'volume_type_extra_specs.delete', notifier_info)
        return webob.Response(status_int=202)
Ejemplo n.º 20
0
    def create(self, req, type_id, body=None):
        context = req.environ['manila.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._verify_extra_specs(specs, False)
        self._check_key_names(specs.keys())
        db.share_type_extra_specs_update_or_create(context, type_id, specs)
        notifier_info = dict(type_id=type_id, specs=specs)
        notifier = rpc.get_notifier('shareTypeExtraSpecs')
        notifier.info(context, 'share_type_extra_specs.create', notifier_info)
        return body
    def _delete(self, req, type_id, id):
        """Deletes an existing extra spec."""
        context = req.environ['manila.context']

        if id in share_types.get_required_extra_specs():
            msg = _("Extra spec '%s' can't be deleted.") % id
            raise webob.exc.HTTPForbidden(explanation=msg)

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

        notifier_info = dict(type_id=type_id, id=id)
        notifier = rpc.get_notifier('shareTypeExtraSpecs')
        notifier.info(context, 'share_type_extra_specs.delete', notifier_info)
        return webob.Response(status_int=202)
Ejemplo n.º 22
0
    def _delete(self, req, type_id, id):
        """Deletes an existing extra spec."""
        context = req.environ['manila.context']

        if id in share_types.get_required_extra_specs():
            msg = _("Extra spec '%s' can't be deleted.") % id
            raise webob.exc.HTTPForbidden(explanation=msg)

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

        notifier_info = dict(type_id=type_id, id=id)
        notifier = rpc.get_notifier('shareTypeExtraSpecs')
        notifier.info(context, 'share_type_extra_specs.delete', notifier_info)
        return webob.Response(status_int=http_client.ACCEPTED)
Ejemplo n.º 23
0
 def update(self, req, type_id, id, body=None):
     context = req.environ['manila.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._verify_extra_specs(body, False)
     db.share_type_extra_specs_update_or_create(context, type_id, body)
     notifier_info = dict(type_id=type_id, id=id)
     notifier = rpc.get_notifier('shareTypeExtraSpecs')
     notifier.info(context, 'share_type_extra_specs.update', notifier_info)
     return body
 def update(self, req, type_id, id, body=None):
     context = req.environ['manila.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._verify_extra_specs(body, False)
     db.share_type_extra_specs_update_or_create(context, type_id, body)
     notifier_info = dict(type_id=type_id, id=id)
     notifier = rpc.get_notifier('shareTypeExtraSpecs')
     notifier.info(context, 'share_type_extra_specs.update', notifier_info)
     return body
Ejemplo n.º 25
0
 def _notify_share_type_error(self, context, method, payload):
     rpc.get_notifier('shareType').error(context, method, payload)
Ejemplo n.º 26
0
 def _notify_share_type_error(self, context, method, payload):
     rpc.get_notifier('shareType').error(context, method, payload)
Ejemplo n.º 27
0
 def _notify_volume_type_error(self, context, method, payload):
     rpc.get_notifier('volumeType').error(context, method, payload)
Ejemplo n.º 28
0
 def _notify_volume_type_error(self, context, method, payload):
     rpc.get_notifier('volumeType').error(context, method, payload)
Ejemplo n.º 29
0
 def _notify_share_type_info(self, context, method, share_type):
     payload = dict(share_types=share_type)
     rpc.get_notifier('shareType').info(context, method, payload)