From dbb0304ceab81d1364e9fa9609cf994925abf745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Schr=C3=B6der?= Date: Sun, 14 Jun 2015 23:01:13 +0200 Subject: [PATCH] Adds uncammelize helper method to put the labels in the expected output format --- plugins/inventory/ec2.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/plugins/inventory/ec2.py b/plugins/inventory/ec2.py index b2374cc26f..0352a5e4f4 100755 --- a/plugins/inventory/ec2.py +++ b/plugins/inventory/ec2.py @@ -880,19 +880,19 @@ class Ec2Inventory(object): host_info = {} for key in describe_dict: value = describe_dict[key] - key = self.to_safe('ec2_' + key) + key = self.to_safe('ec2_' + self.uncammelize(key)) # Handle complex types - if key == 'ec2_ConfigurationEndpoint' and value: + if key == 'ec2_configuration_endpoint' and value: host_info['ec2_configuration_endpoint_address'] = value['Address'] host_info['ec2_configuration_endpoint_port'] = value['Port'] - if key == 'ec2_Endpoint' and value: + if key == 'ec2_endpoint' and value: host_info['ec2_endpoint_address'] = value['Address'] host_info['ec2_endpoint_port'] = value['Port'] - elif key == 'ec2_CacheParameterGroup': + elif key == 'ec2_cache_parameter_group': host_info['ec2_cache_parameter_group_name'] = value['CacheParameterGroupName'] host_info['ec2_cache_parameter_apply_status'] = value['ParameterApplyStatus'] - elif key == 'ec2_SecurityGroups': + elif key == 'ec2_security_groups': sg_ids = [] for sg in value: sg_ids.append(sg['SecurityGroupId']) @@ -972,6 +972,9 @@ class Ec2Inventory(object): cache.write(json_data) cache.close() + def uncammelize(self, key): + temp = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', key) + return re.sub('([a-z0-9])([A-Z])', r'\1_\2', temp).lower() def to_safe(self, word): ''' Converts 'bad' characters in a string to underscores so they can be