Liste der auto scaling-Gruppe Namen, die mit einem speziellen application-tag mit boto3

War ich versucht zu Holen, auto scaling-Gruppen mit Anwendungs-tag-Wert als 'CCC'.

Die Liste ist als unten,

gweb
prd-dcc-eap-w2
gweb
prd-dcc-emc
gweb
prd-dcc-ems
CCC
dev-ccc-wer
CCC
dev-ccc-gbg
CCC
dev-ccc-wer

Das Skript codiert ich unten zeigt die Ausgabe enthält ein ASG ohne CCC tag.

#!/usr/bin/python
import boto3

client = boto3.client('autoscaling',region_name='us-west-2')

response = client.describe_auto_scaling_groups()

ccc_asg = []

all_asg = response['AutoScalingGroups']
for i in range(len(all_asg)):
    all_tags = all_asg[i]['Tags']
    for j in range(len(all_tags)):
        if all_tags[j]['Key'] == 'Name':
                asg_name = all_tags[j]['Value']
        #        print asg_name
        if all_tags[j]['Key'] == 'Application':
                app = all_tags[j]['Value']
        #        print app
        if all_tags[j]['Value'] == 'CCC':
                ccc_asg.append(asg_name)

print ccc_asg

Die Ausgabe die ich erhalte ist als unten,

['prd-dcc-ein-w2', 'dev-ccc-hap', 'dev-ccc-wfd', 'dev-ccc-sdf']

Wo, wie 'prd-dcc-ein-w2' ist ein asg mit einem anderen tag versehen 'gweb'. Und die Letzte (dev-ccc-msp-agt-asg) im CCC ASG-Liste fehlt. Ich brauche die Ausgabe wie unten

dev-ccc-hap-sdf
dev-ccc-hap-gfh
dev-ccc-hap-tyu
dev-ccc-mso-hjk

Bin ich etwas fehlt ?.

InformationsquelleAutor Ashfaq | 2017-04-25
Schreibe einen Kommentar