diff options
author | Isaku Yamahata <yamahata@valinux.co.jp> | 2011-07-23 16:55:25 +0900 |
---|---|---|
committer | Isaku Yamahata <yamahata@valinux.co.jp> | 2011-07-23 16:55:25 +0900 |
commit | ba6b6a20eeedb0311e06090d2f60d36964d67cf4 (patch) | |
tree | e61aad73d4aeb529db10a89dbc7afd0c19f9f912 /nova/block_device.py | |
parent | 1f55e116adbf00a0a5bd990f99a680e9d6b1618e (diff) | |
download | nova-ba6b6a20eeedb0311e06090d2f60d36964d67cf4.tar.gz nova-ba6b6a20eeedb0311e06090d2f60d36964d67cf4.tar.xz nova-ba6b6a20eeedb0311e06090d2f60d36964d67cf4.zip |
block_device: introduce helper function to check swap or ephemeral device
and move generic function, mappings_prepend_dev() from ec2utils to
block_device
Diffstat (limited to 'nova/block_device.py')
-rw-r--r-- | nova/block_device.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/nova/block_device.py b/nova/block_device.py index 963dffa37..8d95e0029 100644 --- a/nova/block_device.py +++ b/nova/block_device.py @@ -15,6 +15,8 @@ # License for the specific language governing permissions and limitations # under the License. +import re + def properties_root_device_name(properties): """get root device name from image meta data. @@ -33,3 +35,37 @@ def properties_root_device_name(properties): root_device_name = properties['root_device_name'] return root_device_name + + +_ephemeral = re.compile('^ephemeral(\d|[1-9]\d+)$') + + +def is_ephemeral(device_name): + return _ephemeral.match(device_name) + + +def ephemeral_num(ephemeral_name): + assert is_ephemeral(ephemeral_name) + return int(_ephemeral.sub('\\1', ephemeral_name)) + + +def is_swap_or_ephemeral(device_name): + return device_name == 'swap' or is_ephemeral(device_name) + + +def mappings_prepend_dev(mappings): + """Prepend '/dev/' to 'device' entry of swap/ephemeral virtual type""" + for m in mappings: + virtual = m['virtual'] + if (is_swap_or_ephemeral(virtual) and + (not m['device'].startswith('/'))): + m['device'] = '/dev/' + m['device'] + return mappings + + +_dev = re.compile('^/dev/') + + +def strip_dev(device_name): + """remove leading '/dev/'""" + return _dev.sub('', device_name) |