diff options
author | Joe Gordon <jogo@cloudscaling.com> | 2013-03-21 18:55:49 +0000 |
---|---|---|
committer | Joe Gordon <jogo@cloudscaling.com> | 2013-03-21 18:55:49 +0000 |
commit | 7ab98e935a63454d0736e6f8a7525a8e73cf6c04 (patch) | |
tree | d66fccabf799a2af55ea8ccc2c2b276f5c379010 | |
parent | 5499640f639009f60fbf909786770654e1f1b5a0 (diff) | |
download | nova-7ab98e935a63454d0736e6f8a7525a8e73cf6c04.tar.gz nova-7ab98e935a63454d0736e6f8a7525a8e73cf6c04.tar.xz nova-7ab98e935a63454d0736e6f8a7525a8e73cf6c04.zip |
Remove unnecessary DB call to find EC2 AZs.
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
-rw-r--r-- | nova/api/ec2/cloud.py | 3 | ||||
-rw-r--r-- | nova/api/ec2/ec2utils.py | 8 | ||||
-rw-r--r-- | nova/api/metadata/base.py | 4 |
3 files changed, 5 insertions, 10 deletions
diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index a35460576..8807042dd 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -1178,8 +1178,7 @@ class CloudController(object): 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 = {} diff --git a/nova/api/ec2/ec2utils.py b/nova/api/ec2/ec2utils.py index bb0f7245a..08a1be278 100644 --- a/nova/api/ec2/ec2utils.py +++ b/nova/api/ec2/ec2utils.py @@ -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'): diff --git a/nova/api/metadata/base.py b/nova/api/metadata/base.py index 896c8fbd7..90dcb9ca5 100644 --- a/nova/api/metadata/base.py +++ b/nova/api/metadata/base.py @@ -106,10 +106,8 @@ class InstanceMetadata(): 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) |