From c6f2b08a6010d2309f25c3d82bd97dd3794562f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Schr=C3=B6der?= Date: Sun, 14 Jun 2015 22:57:03 +0200 Subject: [PATCH] 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) --- plugins/inventory/ec2.py | 41 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/plugins/inventory/ec2.py b/plugins/inventory/ec2.py index 0f61413451..b2374cc26f 100755 --- a/plugins/inventory/ec2.py +++ b/plugins/inventory/ec2.py @@ -775,7 +775,9 @@ class Ec2Inventory(object): # Global Tag: all ElastiCache clusters 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): ''' Get and store the map of resource records to domain names that @@ -870,6 +872,43 @@ class Ec2Inventory(object): 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): ''' Get variables about a specific host '''