2014-09-23 64 views
1

我試圖用博託v2.32.0列出在一個特定的ASG標籤AWS博託v2.32.0 - 爲ASG

一些簡單的像這顯然不工作(特別是缺乏一個列表標籤過濾系統):

import boto.ec2.autoscale 

asg = boto.ec2.autoscale.connect_to_region('ap-southeast-2') 
tags = asg.get_all_tags('asgname') 
print tags 

或:

asg = boto.ec2.autoscale.connect_to_region('ap-southeast-2') 
group = asg.get_all_groups(names='asgname') 
tags = asg.get_all_tags(group) 
print tags 

或:

asg = boto.ec2.autoscale.connect_to_region('ap-southeast-2') 
group = asg.get_all_groups(names='asgname') 
tags = group.get_all_tags() 
print tags 

沒有指定'asgname',它不會返回每個ASG。儘管文檔中提到的有關返回令牌以查看下一頁的內容,但似乎並未正確實施 - 尤其是當每個ASG擁有大量ASG和標記時。

嘗試這樣的事情已經基本上顯示出令牌系統似乎被破壞。它在返回「無」之前並不是「循環」通過所有ASG和標籤:

asg = boto.ec2.autoscale.connect_to_region('ap-southeast-2') 

nt = None 

while (True): 
     tags = asg.get_all_tags(next_token=nt) 
     for t in tags: 
       if (t.key == "MyTag"): 
         print t.resource_id 
         print t.value 
     if (tags.next_token == None): 
       break 
     else: 
       nt = str(tags.next_token) 

有沒有人設法實現這個目標?

感謝

回答

0

我最終通過創建一個使用亞馬遜cli的工作來回答我自己的問題。由於自從我問到這個問題以來,這個問題就沒有任何活動,我將這種解決方法作爲解決方案發布。

import os 
import json 

## bash command 
awscli = "/usr/local/bin/aws autoscaling describe-tags --filters Name=auto-scaling-group,Values=" + str(asgname) 

output = str() 
# run it 
cmd = os.popen(awscli,"r") 
while 1: 
    # get tag lines 
    lines = cmd.readline() 
    if not lines: break 
    output += lines 

# json.load to manipulate 
tags = json.loads(output.replace('\n','')) 
1

此功能在AWS可使用AutoScaling DescribeTags API調用,但不幸的是博託沒有完全實現這個調用。

您應該能夠傳遞一個Filter與API調用來僅獲取特定ASG的標籤,但如果你看看在boto source code for get_all_tags()(v2.32.1),過濾器未實現:

:type filters: dict 
:param filters: The value of the filter type used 
       to identify the tags to be returned. NOT IMPLEMENTED YET. 

(引用上面提到的源代碼)。

+0

嗨@dcro,我看到,但希望有人可能知道使用由「get_all_tags」返回的列表工作。到目前爲止,我認爲我發現令牌系統並沒有很好地實現。 – jonsnowed 2014-09-23 06:37:05

+0

我根據我的新發現更新了我的問題。希望有人會有一些投入。 – jonsnowed 2014-09-23 06:41:18

+1

對於任何人仍然可以得到這個答案,它仍然沒有實施自v2.35.1,我不得不使用下面接受的aws-cli解決方案。 – WheresWardy 2015-01-15 11:14:49