简体   繁体   中英

How can i get the aws volumes available size by boto3

#/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

The answer I got ec2.Instance.volumesCollection(ec2.Instance(id='i-xxxxxx'), ec2.Volume)

It just list the volume total size and status(available,in-use...) , how can i get it?

Assuming you are using Python 2.7 :

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

Output

16 in-use
500 in-use

For other attributes:

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']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM