From c7ae6b9fd5d705be117bdd2db02da538f95a8c3f Mon Sep 17 00:00:00 2001 From: Elijah Lynn Date: Tue, 9 May 2017 16:56:54 -0400 Subject: [PATCH] [cloud][inventory] Get tags for RDS instances. (#23989) * Get tags for RDS instances. Boto3 only at this time. Relates to #11569, #14464. * Add a check for boto3 * Fix HAS_BOTO3 error --- contrib/inventory/ec2.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/contrib/inventory/ec2.py b/contrib/inventory/ec2.py index 7b3c6d44a87..f2d2e624154 100755 --- a/contrib/inventory/ec2.py +++ b/contrib/inventory/ec2.py @@ -623,6 +623,13 @@ class Ec2Inventory(object): ''' Makes an AWS API call to the list of RDS instances in a particular region ''' + if not HAS_BOTO3: + self.fail_with_error("Working with RDS instances requires boto3 - please install boto3 and try again", + "getting RDS instances") + + client = ec2_utils.boto3_inventory_conn('client', 'rds', region, **self.credentials) + db_instances = client.describe_db_instances() + try: conn = self.connect_to_aws(rds, region) if conn: @@ -630,7 +637,14 @@ class Ec2Inventory(object): while True: instances = conn.get_all_dbinstances(marker=marker) marker = instances.marker - for instance in instances: + for index, instance in enumerate(instances): + # Add tags to instances. + instance.arn = db_instances['DBInstances'][index]['DBInstanceArn'] + tags = client.list_tags_for_resource(ResourceName=instance.arn)['TagList'] + instance.tags = {} + for tag in tags: + instance.tags[tag['Key']] = tag['Value'] + self.add_rds_instance(instance, region) if not marker: break