summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-10-05 15:43:54 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-10-05 15:43:54 -0700
commitf510d8f5762f3c9d27afcc57f63d7614ec6c05cd (patch)
tree7c221eabdd07c1b55be6595ce197b411e1c69891
parent5b4fa81016f487fb6e041cef5a3b4ac0bd0863c5 (diff)
downloadvyos-cloud-init-f510d8f5762f3c9d27afcc57f63d7614ec6c05cd.tar.gz
vyos-cloud-init-f510d8f5762f3c9d27afcc57f63d7614ec6c05cd.zip
Add checks around the device names that are found
to ensure that even if they are found that they are also valid, before they are assumed to be the correct device name.
-rw-r--r--cloudinit/sources/DataSourceConfigDrive.py36
1 files changed, 24 insertions, 12 deletions
diff --git a/cloudinit/sources/DataSourceConfigDrive.py b/cloudinit/sources/DataSourceConfigDrive.py
index eebe44ec..4af2e5ae 100644
--- a/cloudinit/sources/DataSourceConfigDrive.py
+++ b/cloudinit/sources/DataSourceConfigDrive.py
@@ -68,13 +68,30 @@ class DataSourceConfigDrive(sources.DataSource):
def _os_name_to_device(self, name):
device = None
try:
- dev_entries = util.find_devs_with('LABEL=%s' % (name))
+ criteria = 'LABEL=%s' % (name)
+ if name in ['swap']:
+ criteria = 'TYPE=%s' % (name)
+ dev_entries = util.find_devs_with(criteria)
if dev_entries:
device = dev_entries[0]
except util.ProcessExecutionError:
pass
return device
+ def _validate_device_name(self, device):
+ if not device:
+ return None
+ if not device.startswith("/"):
+ device = "/dev/%s" % device
+ if os.path.exists(device):
+ return device
+ # Durn, try adjusting the mapping
+ remapped = self._remap_device(os.path.basename(device))
+ if remapped:
+ LOG.debug("Remapped device name %s => %s", device, remapped)
+ return remapped
+ return None
+
def device_name_to_device(self, name):
# Translate a 'name' to a 'physical' device
if not name:
@@ -86,31 +103,26 @@ class DataSourceConfigDrive(sources.DataSource):
if name == 'ami':
names.append('root')
device = None
+ LOG.debug("Using ec2 metadata lookup to find device %s", names)
for n in names:
device = self._ec2_name_to_device(n)
+ device = self._validate_device_name(device)
if device:
break
# Try the openstack way second
if not device:
+ LOG.debug("Using os lookup to find device %s", names)
for n in names:
device = self._os_name_to_device(n)
+ device = self._validate_device_name(device)
if device:
break
# Ok give up...
if not device:
return None
- # Ensure translated ok
- if not device.startswith("/"):
- device = "/dev/%s" % device
- if os.path.exists(device):
+ else:
+ LOG.debug("Using cfg drive lookup mapped to device %s", device)
return device
- # Durn, try adjusting the mapping
- remapped = self._remap_device(os.path.basename(device))
- if remapped:
- LOG.debug("Remapped device name %s => %s", device, remapped)
- return remapped
- # Really give up now
- return None
def get_data(self):
found = None