获取与实例关联的卷信息 [英] Get volume information associated with Instance
本文介绍了获取与实例关联的卷信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试检索与实例关联的所有卷.
I'm trying to retrieve all the volumes associated with an instance.
if volume.attachment_state() == 'attached':
volumesinstance = ec2_connection.get_all_instances()
ids = [z for k in volumesinstance for z in k.instances]
for s in ids:
try:
tags = s.tags
instance_name = tags["Name"]
print (instance_name)
except Exception as e:
print e
但是,它没有按预期工作.
However, it's not working as intended.
推荐答案
您可以在get_all_instances方法中添加过滤器
You can add filters in get_all_instances method
像这样:
filter = {'block-device-mapping.volume-id': volume.id}
volumesinstance = ec2_connection.get_all_instances(filters=filter)
ids = [z for k in volumesinstance for z in k.instances]
for s in ids:
try:
tags = s.tags
instance_name = tags["Name"]
print (instance_name)
except Exception as e:
print e
这篇关于获取与实例关联的卷信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文