Ejemplo n.º 1
0
 def show(self, req, flavor_id, id):
     """Return a single extra spec item."""
     context = req.environ['compute.context']
     authorize(context, action='show')
     flavor = common.get_flavor(context, flavor_id)
     try:
         return {id: flavor.extra_specs[id]}
     except KeyError:
         msg = _("Flavor %(flavor_id)s has no extra specs with "
                 "key %(key)s.") % dict(flavor_id=flavor_id,
                                        key=id)
         raise webob.exc.HTTPNotFound(explanation=msg)
Ejemplo n.º 2
0
    def index(self, req, flavor_id):
        context = req.environ['compute.context']
        authorize(context)

        flavor = common.get_flavor(context, flavor_id)

        # public flavor to all projects
        if flavor.is_public:
            explanation = _("Access list not available for public flavors.")
            raise webob.exc.HTTPNotFound(explanation=explanation)

        # private flavor to listed projects only
        return _marshall_flavor_access(flavor)
Ejemplo n.º 3
0
    def index(self, req, flavor_id):
        context = req.environ['compute.context']
        authorize(context)

        flavor = common.get_flavor(context, flavor_id)

        # public flavor to all projects
        if flavor.is_public:
            explanation = _("Access list not available for public flavors.")
            raise webob.exc.HTTPNotFound(explanation=explanation)

        # private flavor to listed projects only
        return _marshall_flavor_access(flavor)
Ejemplo n.º 4
0
    def create(self, req, flavor_id, body):
        context = req.environ['compute.context']
        authorize(context, action='create')

        specs = body['extra_specs']
        self._check_extra_specs_value(specs)
        flavor = common.get_flavor(context, flavor_id)
        try:
            flavor.extra_specs = dict(flavor.extra_specs, **specs)
            flavor.save()
        except exception.FlavorExtraSpecUpdateCreateFailed as e:
            raise webob.exc.HTTPConflict(explanation=e.format_message())
        except exception.FlavorNotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.format_message())
        return body
Ejemplo n.º 5
0
    def index(self, req, flavor_id):
        context = req.environ['compute.context']
        authorize(context)
        # NOTE(alex_xu): back-compatible with db layer hard-code admin
        # permission checks.
        nova_context.require_admin_context(context)

        flavor = common.get_flavor(context, flavor_id)

        # public flavor to all projects
        if flavor.is_public:
            explanation = _("Access list not available for public flavors.")
            raise webob.exc.HTTPNotFound(explanation=explanation)

        # private flavor to listed projects only
        return _marshall_flavor_access(flavor)
Ejemplo n.º 6
0
 def delete(self, req, flavor_id, id):
     """Deletes an existing extra spec."""
     context = req.environ['compute.context']
     authorize(context, action='delete')
     flavor = common.get_flavor(context, flavor_id)
     try:
         del flavor.extra_specs[id]
         flavor.save()
     except (exception.FlavorExtraSpecsNotFound,
             exception.FlavorNotFound) as e:
         raise webob.exc.HTTPNotFound(explanation=e.format_message())
     except KeyError:
         msg = _("Flavor %(flavor_id)s has no extra specs with "
                 "key %(key)s.") % dict(flavor_id=flavor_id,
                                        key=id)
         raise webob.exc.HTTPNotFound(explanation=msg)
Ejemplo n.º 7
0
    def update(self, req, flavor_id, id, body):
        context = req.environ['compute.context']
        authorize(context, action='update')

        self._check_extra_specs_value(body)
        if id not in body:
            expl = _('Request body and URI mismatch')
            raise webob.exc.HTTPBadRequest(explanation=expl)
        flavor = common.get_flavor(context, flavor_id)
        try:
            flavor.extra_specs = dict(flavor.extra_specs, **body)
            flavor.save()
        except exception.FlavorExtraSpecUpdateCreateFailed as e:
            raise webob.exc.HTTPConflict(explanation=e.format_message())
        except exception.FlavorNotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.format_message())
        return body
Ejemplo n.º 8
0
    def _add_tenant_access(self, req, id, body):
        context = req.environ['compute.context']
        authorize(context, action="add_tenant_access")

        vals = body['addTenantAccess']
        tenant = vals['tenant']

        flavor = common.get_flavor(context, id)

        try:
            if api_version_request.is_supported(req, min_version='2.7'):
                if flavor.is_public:
                    exp = _("Can not add access to a public flavor.")
                    raise webob.exc.HTTPConflict(explanation=exp)
            flavor.add_access(tenant)
        except exception.FlavorNotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.format_message())
        except exception.FlavorAccessExists as err:
            raise webob.exc.HTTPConflict(explanation=err.format_message())
        except exception.AdminRequired as e:
            raise webob.exc.HTTPForbidden(explanation=e.format_message())
        return _marshall_flavor_access(flavor)
Ejemplo n.º 9
0
    def _add_tenant_access(self, req, id, body):
        context = req.environ['compute.context']
        authorize(context, action="add_tenant_access")

        vals = body['addTenantAccess']
        tenant = vals['tenant']

        flavor = common.get_flavor(context, id)

        try:
            if api_version_request.is_supported(req, min_version='2.7'):
                if flavor.is_public:
                    exp = _("Can not add access to a public flavor.")
                    raise webob.exc.HTTPConflict(explanation=exp)
            flavor.add_access(tenant)
        except exception.FlavorNotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.format_message())
        except exception.FlavorAccessExists as err:
            raise webob.exc.HTTPConflict(explanation=err.format_message())
        except exception.AdminRequired as e:
            raise webob.exc.HTTPForbidden(explanation=e.format_message())
        return _marshall_flavor_access(flavor)
Ejemplo n.º 10
0
 def _get_extra_specs(self, context, flavor_id):
     flavor = common.get_flavor(context, flavor_id)
     return dict(extra_specs=flavor.extra_specs)