【问题标题】:How can i get the aws volumes available size by boto3如何通过 boto3 获取 aws 卷的可用大小
【发布时间】:2018-03-04 06:51:33
【问题描述】:
#/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)

它只是列出了卷总大小和status(available,in-use...),我怎样才能得到它?

【问题讨论】:

  • 请更新您正在使用哪种编程语言,您的代码在哪里运行等问题。

标签: python python-2.7 amazon-web-services amazon-ec2 boto3


【解决方案1】:

假设您使用的是 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'加密', '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']

【讨论】:

  • 但是volume.size是总大小,哪个key可以得到可用大小?
  • 想想吧。 SDK/API 可以获得的是在管理程序级别可用的信息。管理程序中只有总大小(和其他此类信息)可用。操作系统会知道可用的大小。您可以在 AWS 控制台中查看可用大小吗?没有。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-27
  • 1970-01-01
  • 2015-09-03
  • 2020-02-09
  • 1970-01-01
相关资源
最近更新 更多