Commit b8336f22 by Brian Coca

Merge pull request #11560 from oscarhealth/devel

ability to specify any combination of EC2 instance states to return
parents d75b4cd1 e0a5003b
...@@ -58,6 +58,11 @@ route53 = False ...@@ -58,6 +58,11 @@ route53 = False
# 'all_instances' to True to return all instances regardless of state. # 'all_instances' to True to return all instances regardless of state.
all_instances = False all_instances = False
# By default, only EC2 instances in the 'running' state are returned. Specify
# EC2 instance states to return as a comma-separated list. This
# option is overriden when 'all_instances' is True.
# instance_states = pending, running, shutting-down, terminated, stopping, stopped
# By default, only RDS instances in the 'available' state are returned. Set # By default, only RDS instances in the 'available' state are returned. Set
# 'all_rds_instances' to True return all RDS instances regardless of state. # 'all_rds_instances' to True return all RDS instances regardless of state.
all_rds_instances = False all_rds_instances = False
......
...@@ -244,6 +244,28 @@ class Ec2Inventory(object): ...@@ -244,6 +244,28 @@ class Ec2Inventory(object):
else: else:
self.all_instances = False self.all_instances = False
# Instance states to be gathered in inventory. Default is 'running'.
# Setting 'all_instances' to 'yes' overrides this option.
ec2_valid_instance_states = [
'pending',
'running',
'shutting-down',
'terminated',
'stopping',
'stopped'
]
self.ec2_instance_states = []
if self.all_instances:
self.ec2_instance_states = ec2_valid_instance_states
elif config.has_option('ec2', 'instance_states'):
for instance_state in config.get('ec2', 'instance_states').split(','):
instance_state = instance_state.strip()
if instance_state not in ec2_valid_instance_states:
continue
self.ec2_instance_states.append(instance_state)
else:
self.ec2_instance_states = ['running']
# Return all RDS instances? (if RDS is enabled) # Return all RDS instances? (if RDS is enabled)
if config.has_option('ec2', 'all_rds_instances') and self.rds_enabled: if config.has_option('ec2', 'all_rds_instances') and self.rds_enabled:
self.all_rds_instances = config.getboolean('ec2', 'all_rds_instances') self.all_rds_instances = config.getboolean('ec2', 'all_rds_instances')
...@@ -534,8 +556,8 @@ class Ec2Inventory(object): ...@@ -534,8 +556,8 @@ class Ec2Inventory(object):
''' Adds an instance to the inventory and index, as long as it is ''' Adds an instance to the inventory and index, as long as it is
addressable ''' addressable '''
# Only want running instances unless all_instances is True # Only return instances with desired instance states
if not self.all_instances and instance.state != 'running': if instance.state not in self.ec2_instance_states:
return return
# Select the best destination address # Select the best destination address
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment