在Boto中列出EC2卷 [英] List EC2 volumes in Boto

查看:75
本文介绍了在Boto中列出EC2卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想列出连接到我的ec2的所有卷。

I want to list all volumes attached to my ec2.

conn = EC2Connection()
attribute = get_instance_metadata()
region=attribute['local-hostname'].split('.')[1]
inst_id = attribute['instance-id']
aws = boto.ec2.connect_to_region(region)
volume=attribute['local-hostname']
volumes = str(aws.get_all_volumes(filters={'attachment.instance-id': inst_id}))

使用我的代码,我可以列出音量,但结果是这样的:

With my code I can list volume but the result is like that :

[vol-35b0b5fa,Volume:vol-6cbbbea3]

[vol-35b0b5fa, Volume:vol-6cbbbea3]

我需要类似的东西:

vol -35b0b5fa

vol-35b0b5fa

vol-6cbbbea3

vol-6cbbbea3

我不知道该怎么做,而我的研究也做不到

I don't know how i can do, and my research don"t help me.

有人可以帮助我吗?

推荐答案

如果您使用的是Boto3库,则以下命令将列出所有连接的卷

If you are using Boto3 library then here is the command to list out all attached volumes

import boto3
ec2 = boto3.resource('ec2', region_name='us-west-2')
volumes = ec2.volumes.all() # If you want to list out all volumes
volumes = ec2.volumes.filter(Filters=[{'Name': 'status', 'Values': ['in-use']}]) # if you want to list out only attached volumes
[volume for volume in volumes]

这篇关于在Boto中列出EC2卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆