Skip to content

Commit

Permalink
Optimize the instance fetched by floating_ips API
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kk7ds committed Feb 1, 2016
1 parent 7a9942c commit 0678425
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions nova/api/openstack/compute/floating_ips.py
Expand Up @@ -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):
Expand Down Expand Up @@ -193,7 +194,8 @@ def _add_floating_ip(self, req, id, body):

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(
Expand Down

0 comments on commit 0678425

Please sign in to comment.