-# Copyright (c) 2012 OpenStack, LLC.
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright (c) 2012 OpenStack LLC.
+# All Rights Reserved.
#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# 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.
+# 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.
import netaddr
import webob.exc
allow_bulk=self._allow_bulk)
action = self._plugin_handlers[self.CREATE]
# Check authz
- try:
- if self._collection in body:
- # Have to account for bulk create
- items = body[self._collection]
- deltas = {}
- bulk = True
- else:
- items = [body]
- bulk = False
- for item in items:
- self._validate_network_tenant_ownership(request,
- item[self._resource])
- policy.enforce(request.context,
- action,
- item[self._resource],
- plugin=self._plugin)
- try:
- tenant_id = item[self._resource]['tenant_id']
- count = QUOTAS.count(request.context, self._resource,
- self._plugin, self._collection,
- tenant_id)
- if bulk:
- delta = deltas.get(tenant_id, 0) + 1
- deltas[tenant_id] = delta
- else:
- delta = 1
- kwargs = {self._resource: count + delta}
- except exceptions.QuotaResourceUnknown as e:
- # We don't want to quota this resource
- LOG.debug(e)
- except Exception:
- raise
+ if self._collection in body:
+ # Have to account for bulk create
+ items = body[self._collection]
+ deltas = {}
+ bulk = True
+ else:
+ items = [body]
+ bulk = False
+ for item in items:
+ self._validate_network_tenant_ownership(request,
+ item[self._resource])
+ policy.enforce(request.context,
+ action,
+ item[self._resource],
+ plugin=self._plugin)
+ try:
+ tenant_id = item[self._resource]['tenant_id']
+ count = QUOTAS.count(request.context, self._resource,
+ self._plugin, self._collection,
+ tenant_id)
+ if bulk:
+ delta = deltas.get(tenant_id, 0) + 1
+ deltas[tenant_id] = delta
else:
- QUOTAS.limit_check(request.context,
- item[self._resource]['tenant_id'],
- **kwargs)
- except exceptions.PolicyNotAuthorized:
- LOG.exception(_("Create operation not authorized"))
- raise webob.exc.HTTPForbidden()
+ delta = 1
+ kwargs = {self._resource: count + delta}
+ except exceptions.QuotaResourceUnknown as e:
+ # We don't want to quota this resource
+ LOG.debug(e)
+ else:
+ QUOTAS.limit_check(request.context,
+ item[self._resource]['tenant_id'],
+ **kwargs)
def notify(create_result):
notifier_api.notify(request.context,