Automatically convert device names

In the past, users have been able to specify xvda or xvdb and it
has worked. We are now validating device names against the expected
name from the backend, and this causes confusion, especially for lxc
which expecting device names to be /dev/a /dev/b /dev/c etc.

This patch addresses the issue by automatically converting between
different formats. The proper format for the backend will be returned
by the api. Includes tests to verify that the conversion works and
that the lxc values work as expected.

Fixes bug 1046020

Change-Id: Iffa552ba05f89f70b6fb93043edf8882c8412215
This commit is contained in:
Vishvananda Ishaya 2012-09-04 15:25:35 -07:00
parent 712cf7e04c
commit b7426f2b51

View File

@ -131,3 +131,11 @@ def instance_block_mapping(instance, bdms):
nebs += 1
return mappings
def match_device(device):
"""Matches device name and returns prefix, suffix"""
match = re.match("(^/dev/x{0,1}[a-z]{0,1}d{0,1})([a-z]+)[0-9]*$", device)
if not match:
return None
return match.groups()