本文介绍了使用Boto查找安装到哪个设备和EBS Volume的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何找到Python Boto v2.0将EBS卷安装到哪个设备?

How do I find to which device an EBS Volume is mounted with Python Boto v2.0?

具有一些有趣的属性,例如 attachment_state volume_state 。但是设备映射有任何功能吗?

boto.ec2.Volume has some interesting properies like attachment_state and volume_state. But are there any functions for device mapping?

具有 get_device(自己,参数),但需要CommandLineGetter。

boto.manage.volume has get_device(self, params) but requires a CommandLineGetter.

关于如何进行操作的任何指针或使用 boto.manage 的某些示例?

Any pointers on how to proceed or some samples of using boto.manage?

推荐答案

我相信您正在寻找attach_data.device。

I believe attach_data.device is what your looking for. part of volume.

在这里举一个例子,不确定这是否是最好的方法,但是它会输出volumeid,instanceid和attachment_data,例如:

Heres an example, not sure if this is the best way, but it outputs volumeid, instanceid, and attachment_data something like:

Attached Volume ID - Instance ID - Device Name
vol-12345678 - i-ab345678 - /dev/sdp
vol-12345678 - i-ab345678 - /dev/sda1
vol-12345678 - i-cd345678 - /dev/sda1


import boto
ec2 = boto.connect_ec2()
res = ec2.get_all_instances()
instances = [i for r in res for i in r.instances]
vol = ec2.get_all_volumes()
def attachedvolumes():
    print 'Attached Volume ID - Instance ID','-','Device Name'
    for volumes in vol:
        if volumes.attachment_state() == 'attached':
            filter = {'block-device-mapping.volume-id':volumes.id}
            volumesinstance = ec2.get_all_instances(filters=filter)
            ids = [z for k in volumesinstance for z in k.instances]
            for s in ids:
                 print volumes.id,'-',s.id,'-',volumes.attach_data.device
# Get a list of unattached volumes           
def unattachedvolumes():
   for unattachedvol in vol:
       state = unattachedvol.attachment_state()
   if state == None:
        print unattachedvol.id, state
attachedvolumes()
unattachedvolumes()

这篇关于使用Boto查找安装到哪个设备和EBS Volume的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 00:35