Skip to content

Commit

Permalink
Removes redundant code in quantum.api.v2.base.create()
Browse files Browse the repository at this point in the history
Handles collections and one item in one routine by creating a items list

Fixes bug #1093390

Change-Id: I24b892ebff52889f17ed9ea8d17e8964e3de25f6
  • Loading branch information
Zhongyue Luo committed Dec 24, 2012
1 parent ca8ed5e commit 1ad3714
Showing 1 changed file with 8 additions and 30 deletions.
38 changes: 8 additions & 30 deletions quantum/api/v2/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,42 +292,20 @@ def create(self, request, body=None, **kwargs):
try:
if self._collection in body:
# Have to account for bulk create
for item in body[self._collection]:
self._validate_network_tenant_ownership(
request,
item[self._resource],
)
policy.enforce(request.context,
action,
item[self._resource],
plugin=self._plugin)
try:
count = QUOTAS.count(request.context, self._resource,
self._plugin, self._collection,
item[self._resource]['tenant_id'])
kwargs = {self._resource: count + 1}
except exceptions.QuotaResourceUnknown as e:
# We don't want to quota this resource
LOG.debug(e)
except Exception:
raise
else:
QUOTAS.limit_check(request.context,
item[self._resource]['tenant_id'],
**kwargs)
items = body[self._collection]
else:
self._validate_network_tenant_ownership(
request,
body[self._resource]
)
items = [body]
for item in items:
self._validate_network_tenant_ownership(request,
item[self._resource])
policy.enforce(request.context,
action,
body[self._resource],
item[self._resource],
plugin=self._plugin)
try:
count = QUOTAS.count(request.context, self._resource,
self._plugin, self._collection,
body[self._resource]['tenant_id'])
item[self._resource]['tenant_id'])
kwargs = {self._resource: count + 1}
except exceptions.QuotaResourceUnknown as e:
# We don't want to quota this resource
Expand All @@ -336,7 +314,7 @@ def create(self, request, body=None, **kwargs):
raise
else:
QUOTAS.limit_check(request.context,
body[self._resource]['tenant_id'],
item[self._resource]['tenant_id'],
**kwargs)
except exceptions.PolicyNotAuthorized:
LOG.exception(_("Create operation not authorized"))
Expand Down

0 comments on commit 1ad3714

Please sign in to comment.