mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 06:10:22 -07:00
Merge pull request #1413 from pas256/devel
Inventory script to gracefully handle AWS being down
This commit is contained in:
commit
8afa3abd41
1 changed files with 19 additions and 12 deletions
|
@ -181,9 +181,9 @@ class Ec2Inventory(object):
|
||||||
self.eucalyptus_host = None
|
self.eucalyptus_host = None
|
||||||
self.eucalyptus = False
|
self.eucalyptus = False
|
||||||
if config.has_option('ec2', 'eucalyptus'):
|
if config.has_option('ec2', 'eucalyptus'):
|
||||||
self.eucalyptus = config.getboolean('ec2', 'eucalyptus')
|
self.eucalyptus = config.getboolean('ec2', 'eucalyptus')
|
||||||
if self.eucalyptus and config.has_option('ec2', 'eucalyptus_host'):
|
if self.eucalyptus and config.has_option('ec2', 'eucalyptus_host'):
|
||||||
self.eucalyptus_host = config.get('ec2', 'eucalyptus_host')
|
self.eucalyptus_host = config.get('ec2', 'eucalyptus_host')
|
||||||
|
|
||||||
# Regions
|
# Regions
|
||||||
self.regions = []
|
self.regions = []
|
||||||
|
@ -236,16 +236,23 @@ class Ec2Inventory(object):
|
||||||
''' Makes an AWS EC2 API call to the list of instances in a particular
|
''' Makes an AWS EC2 API call to the list of instances in a particular
|
||||||
region '''
|
region '''
|
||||||
|
|
||||||
if self.eucalyptus:
|
try:
|
||||||
conn = boto.connect_euca(host=self.eucalyptus_host)
|
if self.eucalyptus:
|
||||||
conn.APIVersion = '2010-08-31'
|
conn = boto.connect_euca(host=self.eucalyptus_host)
|
||||||
else:
|
conn.APIVersion = '2010-08-31'
|
||||||
conn = ec2.connect_to_region(region)
|
else:
|
||||||
|
conn = ec2.connect_to_region(region)
|
||||||
reservations = conn.get_all_instances()
|
|
||||||
for reservation in reservations:
|
reservations = conn.get_all_instances()
|
||||||
for instance in reservation.instances:
|
for reservation in reservations:
|
||||||
self.add_instance(instance, region)
|
for instance in reservation.instances:
|
||||||
|
self.add_instance(instance, region)
|
||||||
|
|
||||||
|
except boto.exception.BotoServerError as e:
|
||||||
|
if not self.eucalyptus:
|
||||||
|
print "Looks like AWS is down again:"
|
||||||
|
print e
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def get_instance(self, region, instance_id):
|
def get_instance(self, region, instance_id):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue