2014-01-21 19 views
1

我是python的新手,試圖編寫一個腳本來拍攝日常的amazon ebs快照。以下是列出卷並將它們輸入到for循環中的快照命令的腳本。Python boto列出了卷名,後面跟着「Volumes」:

 

#!/usr/bin/python 
#Script for purging AWS Ebs Snapshots. 

from boto.ec2 import EC2Connection 
import time 

My_access_key = "xxxxxxxxxxxxxxx" 
My_secret_key = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" 


conn = EC2Connection(My_access_key, My_secret_key) 

# List out the volumes 
vol_id = conn.get_all_volumes(volume_ids=None, filters=None) 
print vol_id 

for i in vol_id: 
snapshot = conn.create_snapshot(i, 'Daily-Snapshot') 
print "Creating Snapshot:", snapshot 

問題是,當我列出捲上市這種方式「[體積:體積-a50057e8,體積:體積-ba693ef7]」

,並創建快照配置只此作爲有效輸入「第一卷-a50057e8" 。我試圖修剪,但沒有奏效。

謝謝, Swaroop。

回答

2
volumes = conn.get_all_volumes(volume_ids=None, filters=None) 
# what you get here is a list of volume objects (not just IDs of those) 
for volume in volumes: 
    # each volume object has a field "id" which contains what you need: 
    snapshot = conn.create_snapshot(volume.id, "Daily-Snapshot") 
+0

感謝ALFE,這幫助了我。 – user3218846

+0

而不是評論你的感謝,隨時upvote任何答案,幫助你,如果一個完全解決你的問題,你應該接受它。 – Alfe

相關問題