diff options
author | Scott Moser <smoser@ubuntu.com> | 2010-08-09 17:20:29 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2010-08-09 17:20:29 -0400 |
commit | a43357425d32b53aa58e226613e7fa2dd0714102 (patch) | |
tree | 5440986dbb85f807725c22c073c00c45a95a9771 /cloudinit/DataSourceEc2.py | |
parent | 01ac0f133c331ad959df4e4f0e248846ab07198f (diff) | |
download | vyos-cloud-init-a43357425d32b53aa58e226613e7fa2dd0714102.tar.gz vyos-cloud-init-a43357425d32b53aa58e226613e7fa2dd0714102.zip |
DataSourceEc2.py: remap dev names when metadata service disagress with kernel
device names presented in the metadata service may not be what the kernel
has named them. This can be for more than 1 reason. But some examples:
- device is virtio, metadata named 'sd'
- device is xvdX, metadata named sd
Those are the two situations that are covered here. More complex, but
not covered are possibly:
- metadata service named device 'sda1', but it should actually be 'vdb1'
LP: #611137
Diffstat (limited to 'cloudinit/DataSourceEc2.py')
-rw-r--r-- | cloudinit/DataSourceEc2.py | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/cloudinit/DataSourceEc2.py b/cloudinit/DataSourceEc2.py index e468bf50..cf50a3d5 100644 --- a/cloudinit/DataSourceEc2.py +++ b/cloudinit/DataSourceEc2.py @@ -24,6 +24,7 @@ import urllib2 import time import sys import boto_utils +import os.path class DataSourceEc2(DataSource.DataSource): api_ver = '2009-04-04' @@ -160,10 +161,38 @@ class DataSourceEc2(DataSource.DataSource): if not self.metadata.has_key('block-device-mapping'): return(None) + found = None for entname, device in self.metadata['block-device-mapping'].items(): if entname == name: - return(device) + found = device + break # LP: #513842 mapping in Euca has 'ephemeral' not 'ephemeral0' if entname == "ephemeral" and name == "ephemeral0": - return(device) + found = device + if found == None: + cloudinit.log.warn("returning None") + return None + + # LP: #611137 + # the metadata service may believe that devices are named 'sda' + # when the kernel named them 'vda' or 'xvda' + # we want to return the correct value for what will actually + # exist in this instance + mappings = { "sd": ("vd", "xvd") } + ofound = found + short = os.path.basename(found) + + if not found.startswith("/"): + found="/dev/%s" % found + + if os.path.exists(found): + return(found) + + for nfrom, tlist in mappings.items(): + if not short.startswith(nfrom): continue + for nto in tlist: + cand = "/dev/%s%s" % (nto, short[len(nfrom):]) + if os.path.exists(cand): + cloudinit.log.debug("remapped device name %s => %s" % (found,cand)) + return(cand) return None |