Skip to content

Commit

Permalink
Remove unnecessary DB call to find EC2 AZs.
Browse files Browse the repository at this point in the history
Update get_availability_zone_by_host, so it doesn't need a list of services,
and remove unneeded service_get_all_by_host calls. This removes N DB calls in
the EC2 api when doing a DescribeInstances, where N is number if instances
that are being described.

Partially fix bug 1157437

Change-Id: I0050ba736828faad94549bc6e55f4ca1d05dcbe7
(cherry picked from commit 7ab98e9)
  • Loading branch information
jogo authored and Chuck Short committed Mar 26, 2013
1 parent 49c4334 commit c8cb579
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
3 changes: 1 addition & 2 deletions nova/api/ec2/cloud.py
Expand Up @@ -1178,8 +1178,7 @@ def _format_instances(self, context, instance_id=None, use_v6=False,
self._format_instance_bdm(context, instance['uuid'],
i['rootDeviceName'], i)
host = instance['host']
services = db.service_get_all_by_host(context.elevated(), host)
zone = ec2utils.get_availability_zone_by_host(services, host)
zone = ec2utils.get_availability_zone_by_host(host)
i['placement'] = {'availabilityZone': zone}
if instance['reservation_id'] not in reservations:
r = {}
Expand Down
8 changes: 3 additions & 5 deletions nova/api/ec2/ec2utils.py
Expand Up @@ -115,11 +115,9 @@ def get_ip_info_for_instance(context, instance):
return get_ip_info_for_instance_from_nw_info(nw_info)


def get_availability_zone_by_host(services, host, conductor_api=None):
if len(services) > 0:
return availability_zones.get_host_availability_zone(
context.get_admin_context(), host, conductor_api)
return 'unknown zone'
def get_availability_zone_by_host(host, conductor_api=None):
return availability_zones.get_host_availability_zone(
context.get_admin_context(), host, conductor_api)


def id_to_ec2_id(instance_id, template='i-%08x'):
Expand Down
4 changes: 1 addition & 3 deletions nova/api/metadata/base.py
Expand Up @@ -106,10 +106,8 @@ def __init__(self, instance, address=None, content=[], extra_md=None,
ctxt = context.get_admin_context()

capi = self.conductor_api
services = capi.service_get_all_by_host(ctxt.elevated(),
instance['host'])
self.availability_zone = ec2utils.get_availability_zone_by_host(
services, instance['host'], capi)
instance['host'], capi)

self.ip_info = ec2utils.get_ip_info_for_instance(ctxt, instance)

Expand Down

0 comments on commit c8cb579

Please sign in to comment.