2

How can I obtain a list of volumes that are currently attached to a node? I have the Node object, but since I created the volumes with a block device mapping when I created the node with deploy_node, I don't have the volume object that I could use as reference.

David Gay
  • 1,094
  • 2
  • 16
  • 32

1 Answers1

1

I've found that there isn't a direct way to obtain a list of StorageVolumes attached to a node. There is a solution, however.

With the EC2 driver, you can use a Node's block device mapping to get volume IDs and device names. After you've got the volume ID(s), you can easily select that volume from the list returned by list_volumes(). Below, I demonstrate this by obtaining the ID of an EBS volume with device name /dev/sdb attached to a Node and then selecting the matching StorageVolume from the list returned by list_volumes().

vol_id = [x['ebs']['volume_id'] for x in node.extra['block_device_mapping']
          if x['device_name'] == '/dev/sdb'][0]
# vol_id is a string
volume = [v for v in driver.list_volumes() if v.id == vol_id][0]
# volume is a StorageVolume

Keep in mind that this exact method can't be used if the driver you're working with doesn't provide a block device mapping in its Node's extra dict. If you're not working with the EC2 driver, first check to see what metadata is provided by a Node's extra dict.

David Gay
  • 1,094
  • 2
  • 16
  • 32
  • Do you have a solution for Google Compute's driver – Zulu Oct 09 '14 at 20:15
  • @Zulu I haven't added GCE code yet. But: I can offer a suggestion or two. Since the GCE driver has methods to list Nodes and Volumes, we can see what *is* offered, if not a block device mapping. Get a GCE Node to test with and check `node.extra.keys()`. If there's no extra attribute, see what Node *does* have. Second, check on what is provided about Volumes in a similar way -- check one's attributes. It's my guess that there will be an ID or similar info you can use to find the right Volume from your `driver.list_volumes()` call. Please feel free to email me if you'd like help poking around. – David Gay Oct 15 '14 at 01:51