How to use the nova.api.openstack.wsgi function in nova

To help you get started, we’ve selected a few nova examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / nova / nova / api / openstack / compute / quota_classes.py View on Github external
    @wsgi.expected_errors(400)
    @validation.schema(quota_classes.update)
    def update(self, req, id, body):
        return self._update(req, id, body, exclude_server_groups=True)
github openstack / nova / nova / api / openstack / compute / legacy_v2 / limits.py View on Github external
"""
        verb = req.method
        url = req.url
        context = req.environ.get("nova.context")

        if context:
            username = context.user_id
        else:
            username = None

        delay, error = self._limiter.check_for_delay(verb, url, username)

        if delay:
            msg = _("This request was rate-limited.")
            retry = time.time() + delay
            return wsgi.RateLimitFault(msg, error, retry)

        req.environ["nova.limits"] = self._limiter.get_limits(username)

        return self.application
github openstack / nova / nova / api / openstack / compute / plugins / v3 / image_metadata.py View on Github external
import six
from webob import exc

from nova.api.openstack import common
from nova.api.openstack.compute.schemas.v3 import image_metadata
from nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova.api import validation
from nova import exception
from nova.i18n import _
import nova.image

ALIAS = 'image-metadata'


class ImageMetadataController(wsgi.Controller):
    """The image metadata API controller for the OpenStack API."""

    def __init__(self):
        self.image_api = nova.image.API()

    def _get_image(self, context, image_id):
        try:
            return self.image_api.get(context, image_id)
        except exception.ImageNotAuthorized as e:
            raise exc.HTTPForbidden(explanation=e.format_message())
        except exception.ImageNotFound:
            msg = _("Image not found.")
            raise exc.HTTPNotFound(explanation=msg)

    @extensions.expected_errors((403, 404))
    def index(self, req, image_id):
github openstack / nova / nova / api / openstack / compute / legacy_v2 / contrib / cloudpipe_update.py View on Github external
#    License for the specific language governing permissions and limitations
#    under the License.


import webob
import webob.exc

from nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova.i18n import _
from nova import objects

authorize = extensions.extension_authorizer('compute', 'cloudpipe_update')


class CloudpipeUpdateController(wsgi.Controller):
    """Handle updating the VPN IP/port for cloudpipe instances."""

    def __init__(self):
        super(CloudpipeUpdateController, self).__init__()

    @wsgi.action("update")
    def update(self, req, id, body):
        """Configure cloudpipe parameters for the project."""

        context = req.environ['nova.context']
        authorize(context)

        if id != "configure-project":
            msg = _("Unknown action %s") % id
            raise webob.exc.HTTPBadRequest(explanation=msg)
github openstack / nova / nova / api / openstack / compute / legacy_v2 / contrib / image_size.py View on Github external
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from nova.api.openstack import extensions
from nova.api.openstack import wsgi

authorize = extensions.soft_extension_authorizer('compute', 'image_size')


class ImageSizeController(wsgi.Controller):

    def _extend_image(self, image, image_cache):
        key = "%s:size" % Image_size.alias
        image[key] = image_cache['size']

    @wsgi.extends
    def show(self, req, resp_obj, id):
        context = req.environ["nova.context"]
        if authorize(context):
            image_resp = resp_obj.obj['image']
            # image guaranteed to be in the cache due to the core API adding
            # it in its 'show' method
            image_cached = req.get_db_item('images', image_resp['id'])
            self._extend_image(image_resp, image_cached)

    @wsgi.extends
github openstack / nova / nova / api / openstack / compute / server_tags.py View on Github external
    @wsgi.Controller.api_version("2.26")
    @wsgi.expected_errors((400, 404, 409))
    @validation.schema(schema.update)
    def update(self, req, server_id, id, body):
        context = req.environ["nova.context"]
        context.can(st_policies.POLICY_ROOT % 'update')
        im = _get_instance_mapping(context, server_id)

        with nova_context.target_cell(context, im.cell_mapping) as cctxt:
            instance = self._check_instance_in_valid_state(
                cctxt, server_id, 'update tag')

        try:
            jsonschema.validate(id, parameter_types.tag)
        except jsonschema.ValidationError as e:
            msg = (_("Tag '%(tag)s' is invalid. It must be a non empty string "
                     "without characters '/' and ','. Validation error "
github openstack / nova / nova / api / openstack / compute / contrib / flavor_access.py View on Github external
    @wsgi.action("addTenantAccess")
    def _addTenantAccess(self, req, id, body):
        context = req.environ['nova.context']
        authorize(context, action="addTenantAccess")
        # NOTE(alex_xu): back-compatible with db layer hard-code admin
        # permission checks.
        nova_context.require_admin_context(context)
        self._check_body(body)

        vals = body['addTenantAccess']
        tenant = vals.get('tenant')
        if not tenant:
            msg = _("Missing tenant parameter")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        flavor = objects.Flavor(context=context, flavorid=id)
        try:
github openstack / nova / nova / api / openstack / compute / legacy_v2 / contrib / extended_ips.py View on Github external
    @wsgi.extends
    def detail(self, req, resp_obj):
        context = req.environ['nova.context']
        if authorize(context):
            servers = list(resp_obj.obj['servers'])
            for server in servers:
                db_instance = req.get_db_instance(server['id'])
                # server['id'] is guaranteed to be in the cache due to
                # the core API adding it in its 'detail' method.
                self._extend_server(context, server, db_instance)
github openstack / nova / nova / api / openstack / compute / quota_sets.py View on Github external
    @wsgi.expected_errors(400)
    @validation.schema(quota_sets.update)
    def update(self, req, id, body):
        return self._update(req, id, body, [])
github openstack / nova / nova / api / openstack / volume / volumes.py View on Github external
def create_resource():
    return wsgi.Resource(VolumeController())