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
(cherry picked from commit 7ab98e935a
)
This commit is contained in:
parent
49c4334158
commit
c8cb579663
|
@ -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 = {}
|
||||
|
|
|
@ -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'):
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue