我正在尝试获取连接EBS卷的设备名称。我可以提取附加数据,但只想隔离设备名称。
import boto3
from botocore.client import ClientError
ec2 = boto3.resource('ec2')
filters = [{
'Name': 'tag:app',
'Values': [ 'splunklogidx' ],
'Name': 'tag:splunksnap',
'Values': [ 'yes' ]
}]
#volumes = ec2.volumes.all() # list all volumes
volumes = ec2.volumes.filter(Filters=filters) # list all volumes
for v in volumes:
print "v.id = %s" % v.id
#print "v.tags = %s" % v.tags
print "v.attachments = %s" % v.attachments
#for atDev in v.attachments:
#if atDev['Key'] == 'Device':
#print "device = %s" % atDev['Value']
输出示例如下,我希望能够从中提取/dev/sda1
。
谢谢你,K。
v.attachments = [
{u'AttachTime': datetime.datetime(2017, 8, 11, 10, 35, 8, tzinfo=tzutc()),
u'InstanceId': 'i-004821f294d20085d',
u'VolumeId': 'vol-069d956bf5076c68d',
u'State': 'attached',
u'DeleteOnTermination': True,
u'Device': '/dev/sda1'}
]