mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Creates get_host_info_dict_from_describe_dict helper method to translate information from a 'describe' call (we don't have instance objects in this case)
This commit is contained in:
parent
2cd76cf0e3
commit
c6f2b08a60
1 changed files with 40 additions and 1 deletions
|
@ -775,7 +775,9 @@ class Ec2Inventory(object):
|
||||||
# Global Tag: all ElastiCache clusters
|
# Global Tag: all ElastiCache clusters
|
||||||
self.push(self.inventory, 'elasticache_clusters', cluster['CacheClusterId'])
|
self.push(self.inventory, 'elasticache_clusters', cluster['CacheClusterId'])
|
||||||
|
|
||||||
self.inventory["_meta"]["hostvars"][dest] = self.get_host_info_dict_from_instance(cluster)
|
host_info = self.get_host_info_dict_from_describe_dict(cluster)
|
||||||
|
|
||||||
|
self.inventory["_meta"]["hostvars"][dest] = host_info
|
||||||
|
|
||||||
def get_route53_records(self):
|
def get_route53_records(self):
|
||||||
''' Get and store the map of resource records to domain names that
|
''' Get and store the map of resource records to domain names that
|
||||||
|
@ -870,6 +872,43 @@ class Ec2Inventory(object):
|
||||||
|
|
||||||
return instance_vars
|
return instance_vars
|
||||||
|
|
||||||
|
def get_host_info_dict_from_describe_dict(self, describe_dict):
|
||||||
|
''' Parses the dictionary returned by the API call into a flat list
|
||||||
|
of parameters. This method should be used only when 'describe' is
|
||||||
|
used directly because Boto doesn't provide specific classes. '''
|
||||||
|
|
||||||
|
host_info = {}
|
||||||
|
for key in describe_dict:
|
||||||
|
value = describe_dict[key]
|
||||||
|
key = self.to_safe('ec2_' + key)
|
||||||
|
|
||||||
|
# Handle complex types
|
||||||
|
if key == 'ec2_ConfigurationEndpoint' and value:
|
||||||
|
host_info['ec2_configuration_endpoint_address'] = value['Address']
|
||||||
|
host_info['ec2_configuration_endpoint_port'] = value['Port']
|
||||||
|
if key == 'ec2_Endpoint' and value:
|
||||||
|
host_info['ec2_endpoint_address'] = value['Address']
|
||||||
|
host_info['ec2_endpoint_port'] = value['Port']
|
||||||
|
elif key == 'ec2_CacheParameterGroup':
|
||||||
|
host_info['ec2_cache_parameter_group_name'] = value['CacheParameterGroupName']
|
||||||
|
host_info['ec2_cache_parameter_apply_status'] = value['ParameterApplyStatus']
|
||||||
|
elif key == 'ec2_SecurityGroups':
|
||||||
|
sg_ids = []
|
||||||
|
for sg in value:
|
||||||
|
sg_ids.append(sg['SecurityGroupId'])
|
||||||
|
host_info["ec2_security_group_ids"] = ','.join([str(i) for i in sg_ids])
|
||||||
|
elif type(value) in [int, bool]:
|
||||||
|
host_info[key] = value
|
||||||
|
elif isinstance(value, six.string_types):
|
||||||
|
host_info[key] = value.strip()
|
||||||
|
elif type(value) == type(None):
|
||||||
|
host_info[key] = ''
|
||||||
|
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return host_info
|
||||||
|
|
||||||
def get_host_info(self):
|
def get_host_info(self):
|
||||||
''' Get variables about a specific host '''
|
''' Get variables about a specific host '''
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue