diff options
-rw-r--r-- | cloudinit/CloudConfig/cc_mounts.py | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/cloudinit/CloudConfig/cc_mounts.py b/cloudinit/CloudConfig/cc_mounts.py index ffc647aa..d48177d0 100644 --- a/cloudinit/CloudConfig/cc_mounts.py +++ b/cloudinit/CloudConfig/cc_mounts.py @@ -20,6 +20,14 @@ import os import re import string +def is_mdname(name): + # return true if this is a metadata service name + if name in [ "ami", "root", "swap" ]: + return True + if name.startswith("ephemeral") and name.find(":") == -1: + return True + return False + def handle(name,cfg,cloud,log,args): # these are our default set of mounts defmnts = [ [ "ephemeral0", "/mnt", "auto", "defaults", "0", "0" ], @@ -32,6 +40,10 @@ def handle(name,cfg,cloud,log,args): if cfg.has_key("mounts"): cfgmnt = cfg["mounts"] + # shortname matches 'sda', 'sda1', 'xvda', 'hda' + shortname_filter = r"^[x]{0,1}[shv]d[a-z][0-9]*$" + shortname = re.compile(shortname_filter) + for i in range(len(cfgmnt)): # skip something that wasn't a list if not isinstance(cfgmnt[i],list): continue @@ -41,24 +53,19 @@ def handle(name,cfg,cloud,log,args): if cfgmnt[i][0] == "ephemeral": cfgmnt[i][0] = "ephemeral0" - newname = cfgmnt[i][0] - if not newname.startswith("/"): + if is_mdname(cfgmnt[i][0]): newname = cloud.device_name_to_device(cfgmnt[i][0]) - if newname is not None: - cfgmnt[i][0] = newname - else: - # there is no good way of differenciating between - # a name that *couldn't* exist in the md service and - # one that merely didnt - # in order to allow user to specify 'sda3' rather - # than '/dev/sda3', go through some hoops - ok = False - for f in [ "/", "sd", "hd", "vd", "xvd" ]: - if cfgmnt[i][0].startswith(f): - ok = True - break - if not ok: + if not newname: + log.debug("ignoring nonexistant named mount %s" % cfgmnt[i][0]) cfgmnt[i][1] = None + else: + if newname.startswith("/"): + cfgmnt[i][0] = newname + else: + cfgmnt[i][0] = "/dev/%s" % newname + else: + if shortname.match(cfgmnt[i][0]): + cfgmnt[i][0] = "/dev/%s" % cfgmnt[i][0] for i in range(len(cfgmnt)): # fill in values with @@ -68,9 +75,6 @@ def handle(name,cfg,cloud,log,args): elif cfgmnt[i][j] is None: cfgmnt[i][j] = defvals[j] - if not cfgmnt[i][0].startswith("/"): - cfgmnt[i][0]="/dev/%s" % cfgmnt[i][0] - # if the second entry in the list is 'None' this # clears all previous entries of that same 'fs_spec' # (fs_spec is the first field in /etc/fstab, ie, that device) |