How do I find to which device an EBS Volume is mounted with Python Boto v2.0?
boto.ec2.Volume has some interesting properies like attachment_state
and volume_state
. But are there any functions for device mapping?
boto.manage.volume has get_device(self, params)
but requires a CommandLineGetter.
Any pointers on how to proceed or some samples of using boto.manage
?
If you also want the block device mappings (in linux, the local device name of the EBS volume), you can also use
EC2Connection.get_instance_attribute
to retrieve a list of the local device names and their corresponding EBS objects:This will return a dictionary with local device names as keys, and EBS objects as values (from which you can get all sorts of things like the volume-id).
The best way I've found is to get all resources in one region at a time and associate them yourself:
It isn't clear if you're running this from the instance itself or externally. If the latter, you will not need the metadata call. Just supply the instance id.
Note that an instance may have multiple volumes, so robust code won't assume there's a single device.
I believe attach_data.device is what your looking for. part of volume.
Heres an example, not sure if this is the best way, but it outputs volumeid, instanceid, and attachment_data something like: