Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
msg = _("The share network %s does have a default subnet. Create "
"one or use a specific subnet to manage this share server "
"with API version >= 2.51.") % share_network_id
raise exc.HTTPBadRequest(explanation=msg)
if share_utils.extract_host(host, 'pool'):
msg = _("Host parameter should not contain pool.")
raise exc.HTTPBadRequest(explanation=msg)
try:
utils.validate_service_host(
context, share_utils.extract_host(host))
except exception.ServiceNotFound as e:
raise exc.HTTPBadRequest(explanation=e)
except exception.PolicyNotAuthorized as e:
raise exc.HTTPForbidden(explanation=e)
except exception.AdminRequired as e:
raise exc.HTTPForbidden(explanation=e)
except exception.ServiceIsDown as e:
raise exc.HTTPBadRequest(explanation=e)
try:
share_network = db_api.share_network_get(
context, share_network_id)
except exception.ShareNetworkNotFound as e:
raise exc.HTTPBadRequest(explanation=e)
driver_opts = data.get('driver_options')
if driver_opts is not None and not isinstance(driver_opts, dict):
msg = _("Driver options must be in dictionary format.")
raise exc.HTTPBadRequest(explanation=msg)
raise webob.exc.HTTPMethodNotAllowed()
try:
info = dict(jsonutils.loads(request.body))
except ValueError:
raise webob.exc.HTTPBadRequest()
username = request.path_info_pop()
verb = info.get("verb")
path = info.get("path")
delay, error = self._limiter.check_for_delay(verb, path, username)
if delay:
headers = {"X-Wait-Seconds": "%.2f" % delay}
return webob.exc.HTTPForbidden(headers=headers, explanation=error)
else:
return webob.exc.HTTPNoContent()
raise webob.exc.HTTPBadRequest(
explanation=e.format_message())
if bad_keys:
msg = _("Bad key(s) %s in quota_set") % ",".join(bad_keys)
raise webob.exc.HTTPBadRequest(explanation=msg)
for key in quota_class_set.keys():
value = utils.validate_integer(
body['quota_class_set'][key], key)
try:
db.quota_class_update(context, quota_class, key, value)
except exception.QuotaClassNotFound:
db.quota_class_create(context, quota_class, key, value)
except exception.AdminRequired:
raise webob.exc.HTTPForbidden()
values = QUOTAS.get_class_quotas(context, quota_class)
return self._format_quota_set(None, values)
def _resize(self, req, instance_id, flavor_id, **kwargs):
"""Begin the resize process with given instance/flavor."""
context = req.environ["nova.context"]
authorize(context, action='resize')
instance = self._get_server(context, req, instance_id)
try:
self.compute_api.resize(context, instance, flavor_id, **kwargs)
except exception.QuotaError as error:
raise exc.HTTPForbidden(
explanation=error.format_message(),
headers={'Retry-After': 0})
except exception.FlavorNotFound:
msg = _("Unable to locate requested flavor.")
raise exc.HTTPBadRequest(explanation=msg)
except exception.CannotResizeToSameFlavor:
msg = _("Resize requires a flavor change.")
raise exc.HTTPBadRequest(explanation=msg)
except (exception.CannotResizeDisk,
exception.AutoDiskConfigDisabledByImage) as e:
raise exc.HTTPBadRequest(explanation=e.format_message())
except exception.InstanceIsLocked as e:
raise exc.HTTPConflict(explanation=e.format_message())
except exception.InstanceInvalidState as state_error:
common.raise_http_conflict_for_instance_invalid_state(state_error,
'resize', instance_id)
def show(self, req, id):
context = req.environ['nova.context']
authorize_show(context)
params = urlparse.parse_qs(req.environ.get('QUERY_STRING', ''))
user_id = None
if self.ext_mgr.is_loaded('os-user-quotas'):
user_id = params.get('user_id', [None])[0]
try:
nova.context.authorize_project_context(context, id)
return self._format_quota_set(id,
self._get_quotas(context, id, user_id=user_id))
except exception.Forbidden:
raise webob.exc.HTTPForbidden()
:class:`webob.exc.HTTPForbidden` is raised.
Any functions specified using :meth:`morepath.Request.after`
are run against the response once it is created, if that
response is not an error.
:param obj: the model instance
:param request: the request
:return: A :class:`webob.response.Response` instance.
"""
request.view_code_info = self.code_info
if self.internal:
raise HTTPNotFound()
if (self.permission is not None and
not request.app._permits(request.identity, obj, self.permission)):
raise HTTPForbidden()
if self.load is not None:
content = self.func(obj, request, self.load(request))
else:
content = self.func(obj, request)
if isinstance(content, BaseResponse):
# the view took full control over the response
response = content
else:
response = self.render(content, request)
request._run_after(response)
return response
def denied_response(self, req):
"""Deny WSGI Response.
Returns a standard WSGI response callable with the status of 403 or 401
depending on whether the REMOTE_USER is set or not.
"""
if req.remote_user:
return webob.exc.HTTPForbidden(request=req)
else:
return webob.exc.HTTPUnauthorized(request=req)
user_id = params.get('user_id', [None])[0]
share_type = params.get('share_type', [None])[0]
self._validate_user_id_and_share_type_args(user_id, share_type)
try:
db.authorize_project_context(context, id)
if user_id:
QUOTAS.destroy_all_by_project_and_user(context, id, user_id)
elif share_type:
share_type_id = self._get_share_type_id(context, share_type)
QUOTAS.destroy_all_by_project_and_share_type(
context, id, share_type_id)
else:
QUOTAS.destroy_all_by_project(context, id)
return webob.Response(status_int=http_client.ACCEPTED)
except exception.NotAuthorized:
raise webob.exc.HTTPForbidden()
def assert_is_internal(self, req):
if not self.is_internal(req):
raise exc.HTTPForbidden('authorized only for internal')
# in the plural case, we just check so violating items are hidden
policy_method = policy.enforce if is_single else policy.check
plugin = manager.NeutronManager.get_plugin_for_resource(collection)
try:
resp = [self._get_filtered_item(state.request, controller,
resource, collection, item)
for item in to_process
if (state.request.method != 'GET' or
policy_method(neutron_context, action, item,
plugin=plugin,
pluralized=collection))]
except oslo_policy.PolicyNotAuthorized as e:
# This exception must be explicitly caught as the exception
# translation hook won't be called if an error occurs in the
# 'after' handler.
raise webob.exc.HTTPForbidden(str(e))
if is_single:
resp = resp[0]
state.response.json = {key: resp}