gpt4 book ai didi

python - 我如何通过 boto3 获取 aws 卷的可用大小

转载 作者:行者123 更新时间:2023-11-30 22:29:27 26 4
gpt4 key购买 nike

#/usr/bin/python
import boto3
ec2 = boto3.resource('ec2', region_name='us-west-2')
instance = ec2.Instance('i-xxxxxx')
volumes = instance.volumes.all()
print volumes

我得到的答案ec2.Instance.volumesCollection(ec2.Instance(id='i-xxxxxx'), ec2.Volume)

它只是列出卷总大小和状态(可用、使用中...),我如何获取它?

最佳答案

假设您使用的是Python 2.7:

for volume in volumes:
print volume.size, volume.state

输出

16 in-use
500 in-use

对于其他属性:

dir(volume)

[u'attach_to_instance', u'attachments', u'availability_zone', u'create_snapshot', u'create_tags', u'create_time', u'delete', u'describe_attribute', u'describe_status', u'detach_from_instance', u'enable_io', u'encrypted', 'get_available_subresources', u'id', u'iops', u'kms_key_id', 'load', 'meta', u'modify_attribute', 'reload', u'size', u'snapshot_id', u'snapshots', u'state', u'tags', u'volume_id', u'volume_type']

关于python - 我如何通过 boto3 获取 aws 卷的可用大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46368997/

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