gpt4 book ai didi

Python boto 列出卷名称后跟 "Volumes:"

转载 作者:行者123 更新时间:2023-12-01 05:26:24 25 4
gpt4 key购买 nike

我是 python 新手,正在尝试编写一个脚本来拍摄每日 amazon ebs 快照。下面的脚本列出了卷并将它们输入到 for 循环中的快照命令。

#!/usr/bin/python#Script for purging AWS Ebs Snapshots.from boto.ec2 import EC2Connectionimport timeMy_access_key = "xxxxxxxxxxxxxxx"My_secret_key = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"conn = EC2Connection(My_access_key, My_secret_key)# List out the volumesvol_id = conn.get_all_volumes(volume_ids=None, filters=None)print vol_idfor i in vol_id:snapshot = conn.create_snapshot(i, 'Daily-Snapshot')print "Creating Snapshot:", snapshot

问题是当我列出卷时,其列表方式为“[Volume:vol-a50057e8,Volume:vol-ba693ef7]”

并且创建快照命令将仅将此作为有效输入“vol-a50057e8”。我尝试修剪,但没有成功。

谢谢,斯瓦鲁普。

最佳答案

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")

关于Python boto 列出卷名称后跟 "Volumes:",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21256315/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com