~smoser/cloud-init/snappy-fix-config

« back to all changes in this revision

Viewing changes to cloudinit/CloudConfig/cc_mounts.py

  • Committer: Scott Moser
  • Date: 2012-01-17 19:41:29 UTC
  • Revision ID: smoser@ubuntu.com-20120117194129-nftss2ywh8hp9xpi
[PATCH] PEP8 coding style fixes.
From: Juerg Haefliger <juerg.haefliger@hp.com>

This pulls in the named patch for LP: #914739 with a few other changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import re
21
21
import string
22
22
 
 
23
 
23
24
def is_mdname(name):
24
25
    # return true if this is a metadata service name
25
 
    if name in [ "ami", "root", "swap" ]:
 
26
    if name in ["ami", "root", "swap"]:
26
27
        return True
27
28
    # names 'ephemeral0' or 'ephemeral1'
28
29
    # 'ebs[0-9]' appears when '--block-device-mapping sdf=snap-d4d90bbc'
29
 
    for enumname in ( "ephemeral", "ebs" ):
 
30
    for enumname in ("ephemeral", "ebs"):
30
31
        if name.startswith(enumname) and name.find(":") == -1:
31
32
            return True
32
33
    return False
33
34
 
 
35
 
34
36
def handle(_name, cfg, cloud, log, _args):
35
37
    # fs_spec, fs_file, fs_vfstype, fs_mntops, fs-freq, fs_passno
36
 
    defvals = [ None, None, "auto", "defaults,nobootwait", "0", "2" ]
 
38
    defvals = [None, None, "auto", "defaults,nobootwait", "0", "2"]
37
39
    defvals = cfg.get("mount_default_fields", defvals)
38
40
 
39
41
    # these are our default set of mounts
40
 
    defmnts = [ [ "ephemeral0", "/mnt", "auto", defvals[3], "0", "2" ],
41
 
                [ "swap", "none", "swap", "sw", "0", "0" ] ]
 
42
    defmnts = [["ephemeral0", "/mnt", "auto", defvals[3], "0", "2"],
 
43
               ["swap", "none", "swap", "sw", "0", "0"]]
42
44
 
43
 
    cfgmnt = [ ]
44
 
    if cfg.has_key("mounts"):
 
45
    cfgmnt = []
 
46
    if "mounts" in cfg:
45
47
        cfgmnt = cfg["mounts"]
46
48
 
47
49
    # shortname matches 'sda', 'sda1', 'xvda', 'hda', 'sdb', xvdb, vda, vdd1
94
96
                if cfgmnt[j][0] == cfgmnt[i][0]:
95
97
                    cfgmnt[j][1] = None
96
98
 
97
 
 
98
99
    # for each of the "default" mounts, add them only if no other
99
100
    # entry has the same device name
100
101
    for defmnt in defmnts:
111
112
            if cfgm[0] == defmnt[0]:
112
113
                cfgmnt_has = True
113
114
                break
114
 
        
 
115
 
115
116
        if cfgmnt_has:
116
117
            continue
117
118
        cfgmnt.append(defmnt)
118
119
 
119
 
 
120
120
    # now, each entry in the cfgmnt list has all fstab values
121
121
    # if the second field is None (not the string, the value) we skip it
122
122
    actlist = [x for x in cfgmnt if x[1] is not None]
125
125
        return
126
126
 
127
127
    comment = "comment=cloudconfig"
128
 
    cc_lines = [ ]
 
128
    cc_lines = []
129
129
    needswap = False
130
 
    dirs = [ ]
 
130
    dirs = []
131
131
    for line in actlist:
132
132
        # write 'comment' in the fs_mntops, entry,  claiming this
133
133
        line[3] = "%s,comment=cloudconfig" % line[3]
137
137
            dirs.append(line[1])
138
138
        cc_lines.append('\t'.join(line))
139
139
 
140
 
    fstab_lines = [ ]
 
140
    fstab_lines = []
141
141
    fstab = open("/etc/fstab", "r+")
142
142
    ws = re.compile("[%s]+" % string.whitespace)
143
143
    for line in fstab.read().splitlines():
150
150
        fstab_lines.append(line)
151
151
 
152
152
    fstab_lines.extend(cc_lines)
153
 
        
 
153
 
154
154
    fstab.seek(0)
155
155
    fstab.write("%s\n" % '\n'.join(fstab_lines))
156
156
    fstab.truncate()