in ec2instanceconnectcli/EC2InstanceConnectCLI.py [0:0]
def call_ec2(self):
"""
Fetches information on the associated EC2 instance
"""
for bundle in self.instance_bundles:
session = bundle['session']
#If bundle['target'] has a value, then use it.
if bundle['target']:
bundle['host_info'] = bundle['target']
else:
bundle['host_info'] = None
if (bundle['target'] and bundle['zone']) or len(bundle['instance_id']) == 0:
# If both are specified or we're not using an instance then we have no reason to call EC2
self.logger.debug("{0} does not require lookup".format(bundle['target']))
continue
instance_info = ec2_util.get_instance_data(session, bundle['instance_id'])
bundle['zone'] = instance_info.availability_zone
#If host_info is not available, fallback to using public ipaddress and then private ipaddress.
if not bundle['host_info']:
bundle['host_info'] = instance_info.public_ip if instance_info.public_ip else instance_info.private_ip
self.logger.debug('Successfully got instance information from EC2 API for {0}'.format(bundle['instance_id']))