Skip to content

Commit

Permalink
Merge "Optimizes flavor_access to not make a db request"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Sep 5, 2012
2 parents 07e0b77 + 559cb7a commit c69982e
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions nova/api/openstack/compute/contrib/flavor_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,9 @@ def show(self, req, resp_obj, id):
if authorize(context):
# Attach our slave template to the response object
resp_obj.attach(xml=FlavorextradatumTemplate())
db_flavor = req.get_db_flavor(id)

try:
flavor_ref = instance_types.get_instance_type_by_flavor_id(id)
except exception.FlavorNotFound:
explanation = _("Flavor not found.")
raise webob.exc.HTTPNotFound(explanation=explanation)

self._extend_flavor(resp_obj.obj['flavor'], flavor_ref)
self._extend_flavor(resp_obj.obj['flavor'], db_flavor)

@wsgi.extends
def detail(self, req, resp_obj):
Expand All @@ -156,11 +151,9 @@ def detail(self, req, resp_obj):
resp_obj.attach(xml=FlavorextradataTemplate())

flavors = list(resp_obj.obj['flavors'])
flavor_refs = self._get_flavor_refs(context)

for flavor_rval in flavors:
flavor_ref = flavor_refs[flavor_rval['id']]
self._extend_flavor(flavor_rval, flavor_ref)
db_flavor = req.get_db_flavor(flavor_rval['id'])
self._extend_flavor(flavor_rval, db_flavor)

@wsgi.extends(action='create')
def create(self, req, body, resp_obj):
Expand All @@ -169,14 +162,9 @@ def create(self, req, body, resp_obj):
# Attach our slave template to the response object
resp_obj.attach(xml=FlavorextradatumTemplate())

try:
fid = resp_obj.obj['flavor']['id']
flavor_ref = instance_types.get_instance_type_by_flavor_id(fid)
except exception.FlavorNotFound:
explanation = _("Flavor not found.")
raise webob.exc.HTTPNotFound(explanation=explanation)
db_flavor = req.get_db_flavor(resp_obj.obj['flavor']['id'])

self._extend_flavor(resp_obj.obj['flavor'], flavor_ref)
self._extend_flavor(resp_obj.obj['flavor'], db_flavor)

@wsgi.serializers(xml=FlavorAccessTemplate)
@wsgi.action("addTenantAccess")
Expand Down

0 comments on commit c69982e

Please sign in to comment.