diff options
author | Rick Harris <rconradharris@gmail.com> | 2013-01-29 04:18:24 +0000 |
---|---|---|
committer | Rick Harris <rconradharris@gmail.com> | 2013-01-30 18:10:11 +0000 |
commit | 045e1190f23616e266e5b054b7b192e61e37d659 (patch) | |
tree | b9c9f73d27e2c6bd50c733e2f97b118c3759fddf /nova/block_device.py | |
parent | 398b05a6c1c497c833c85077736500311082b5ef (diff) | |
download | nova-045e1190f23616e266e5b054b7b192e61e37d659.tar.gz nova-045e1190f23616e266e5b054b7b192e61e37d659.tar.xz nova-045e1190f23616e266e5b054b7b192e61e37d659.zip |
DRYing up volume_in_mapping code.
Libvirt, VMWare, and Xen drivers all reimplement this method. This
refactors the code into the `block_device` module so all drivers can
share it.
Future Work: Refactor xen so that strip_prefix doesn't need to be passed
to `volume_in_mapping`.
Change-Id: I026b655f2eb7ea9cebe84058749c05ce93bcb7d4
Diffstat (limited to 'nova/block_device.py')
-rw-r--r-- | nova/block_device.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/nova/block_device.py b/nova/block_device.py index c95961911..1805ff15f 100644 --- a/nova/block_device.py +++ b/nova/block_device.py @@ -17,8 +17,11 @@ import re +from nova.openstack.common import log as logging from nova.virt import driver +LOG = logging.getLogger(__name__) + DEFAULT_ROOT_DEV_NAME = '/dev/sda1' _DEFAULT_MAPPINGS = {'ami': 'sda1', 'ephemeral0': 'sda2', @@ -144,3 +147,25 @@ def match_device(device): if not match: return None return match.groups() + + +def volume_in_mapping(mount_device, block_device_info, strip=strip_dev): + # FIXME(sirp): xen uses strip_prefix to be mountpoint agnostic. There is + # probably a better way to handle this so that strip_dev can be used + # exclusively. + block_device_list = [strip(vol['mount_device']) + for vol in + driver.block_device_info_get_mapping( + block_device_info)] + + swap = driver.block_device_info_get_swap(block_device_info) + if driver.swap_is_usable(swap): + block_device_list.append(strip(swap['device_name'])) + + block_device_list += [strip(ephemeral['device_name']) + for ephemeral in + driver.block_device_info_get_ephemerals( + block_device_info)] + + LOG.debug(_("block_device_list %s"), block_device_list) + return strip(mount_device) in block_device_list |