Optimize the instance fetched by floating_ips API

The floating_ips API fetches an instance without flavor information
and then passes it to the Network API, which eventually calls
_get_instrance_nw_info() which requires access to the flavor. This
triggers a lazy load in 100% of the situations, which is really not
necessary and wasteful.

This patch adds flavor to the list of pre-queried attributes on the
instances fetched by this API to help reduce that waste.

Change-Id: I15eae4e8c03739a34cef9c90989ad0615a96a963
Partial-Bug: #1540526
This commit is contained in:
Dan Smith 2016-02-01 13:13:29 -08:00
parent 7a9942c592
commit 06784253b1
1 changed files with 4 additions and 2 deletions

View File

@ -71,7 +71,8 @@ def get_instance_by_floating_ip_addr(self, context, address):
raise webob.exc.HTTPConflict(explanation=ex.format_message())
if instance_id:
return common.get_instance(self.compute_api, context, instance_id)
return common.get_instance(self.compute_api, context, instance_id,
expected_attrs=['flavor'])
def disassociate_floating_ip(self, context, instance, address):
@ -193,7 +194,8 @@ class FloatingIPActionController(wsgi.Controller):
address = body['addFloatingIp']['address']
instance = common.get_instance(self.compute_api, context, id)
instance = common.get_instance(self.compute_api, context, id,
expected_attrs=['flavor'])
cached_nwinfo = compute_utils.get_nw_info_for_instance(instance)
if not cached_nwinfo:
LOG.warning(