diff options
author | Scott Moser <smoser@ubuntu.com> | 2010-07-08 20:44:28 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2010-07-08 20:44:28 -0400 |
commit | d96186bc66b86639e9f9257aa288256e11e44ad5 (patch) | |
tree | af095467edd2a8fc92a3858c8d863406418ee8aa /cloudinit/CloudConfig/cc_mounts.py | |
parent | 93fc41ed689c1380f60ee774fd20101829a5cafb (diff) | |
download | vyos-cloud-init-d96186bc66b86639e9f9257aa288256e11e44ad5.tar.gz vyos-cloud-init-d96186bc66b86639e9f9257aa288256e11e44ad5.zip |
fix bug where nfs/network mounts could not be specified (LP: #603329)
What caused this was having an open ended list on what "names" might be
found in the metadata service. That list is now trimmed down to the
the following values:
ephemeral*
root
ami
swap
The above list was found from crawled medata data services in the latest
maverick tests I did. The following is the complete list of entries that
were there:
'ami': '/dev/sda1',
'ami': 'sda1',
'ephemeral0': '/dev/sda2'
'ephemeral0': '/dev/sdb'
'ephemeral0': 'sda2'
'ephemeral0': 'sdb'
'ephemeral1': 'sdc'
'ephemeral2': 'sdd'
'ephemeral3': 'sde'
'root': '/dev/sda1'
'root': '/dev/sda1'
'swap': 'sda3'
Also, this limits which devices will have "/dev/" prepended to them to
sda, sda1, xvda, xvda1, hda1, hda, vda.
LP: #603329
Diffstat (limited to 'cloudinit/CloudConfig/cc_mounts.py')
-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) |