From a43357425d32b53aa58e226613e7fa2dd0714102 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Mon, 9 Aug 2010 17:20:29 -0400 Subject: 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 --- cloudinit/DataSourceEc2.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'cloudinit') 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 -- cgit v1.2.3