diff options
author | Scott Moser <smoser@ubuntu.com> | 2012-01-17 12:33:38 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2012-01-17 12:33:38 -0500 |
commit | 89eafa0a6c1a28331b3b3c59ba94803052c63583 (patch) | |
tree | 8ebd0885d0caded95d6c5c6d471b0c35fc16272a /cloudinit/CloudConfig | |
parent | 1d00c0936bfc63117493d89268da8c81611b3c40 (diff) | |
download | vyos-cloud-init-89eafa0a6c1a28331b3b3c59ba94803052c63583.tar.gz vyos-cloud-init-89eafa0a6c1a28331b3b3c59ba94803052c63583.zip |
[PATCH 1/4] Fix pylint conventions C0321 (more than one statement on a single line)
From: Juerg Haefliger <juerg.haefliger@hp.com>
Diffstat (limited to 'cloudinit/CloudConfig')
-rw-r--r-- | cloudinit/CloudConfig/__init__.py | 33 | ||||
-rw-r--r-- | cloudinit/CloudConfig/cc_apt_update_upgrade.py | 18 | ||||
-rw-r--r-- | cloudinit/CloudConfig/cc_byobu.py | 3 | ||||
-rw-r--r-- | cloudinit/CloudConfig/cc_chef.py | 6 | ||||
-rw-r--r-- | cloudinit/CloudConfig/cc_grub_dpkg.py | 9 | ||||
-rw-r--r-- | cloudinit/CloudConfig/cc_locale.py | 3 | ||||
-rw-r--r-- | cloudinit/CloudConfig/cc_mcollective.py | 12 | ||||
-rw-r--r-- | cloudinit/CloudConfig/cc_mounts.py | 42 | ||||
-rw-r--r-- | cloudinit/CloudConfig/cc_phone_home.py | 3 | ||||
-rw-r--r-- | cloudinit/CloudConfig/cc_puppet.py | 3 | ||||
-rw-r--r-- | cloudinit/CloudConfig/cc_resizefs.py | 3 | ||||
-rw-r--r-- | cloudinit/CloudConfig/cc_rightscale_userdata.py | 6 | ||||
-rw-r--r-- | cloudinit/CloudConfig/cc_rsyslog.py | 3 | ||||
-rw-r--r-- | cloudinit/CloudConfig/cc_ssh.py | 9 | ||||
-rw-r--r-- | cloudinit/CloudConfig/cc_ssh_import_id.py | 3 | ||||
-rw-r--r-- | cloudinit/CloudConfig/cc_timezone.py | 3 | ||||
-rw-r--r-- | cloudinit/CloudConfig/cc_update_hostname.py | 3 |
17 files changed, 108 insertions, 54 deletions
diff --git a/cloudinit/CloudConfig/__init__.py b/cloudinit/CloudConfig/__init__.py index f5c4143c..a30940fa 100644 --- a/cloudinit/CloudConfig/__init__.py +++ b/cloudinit/CloudConfig/__init__.py @@ -49,7 +49,8 @@ class CloudConfig(): cloudinit.log.critical("Failed loading of cloud config '%s'. Continuing with empty config\n" % cfgfile) cloudinit.log.debug(traceback.format_exc() + "\n") cfg = None - if cfg is None: cfg = { } + if cfg is None: + cfg = { } try: ds_cfg = self.cloud.datasource.get_config_obj() @@ -76,7 +77,8 @@ class CloudConfig(): # reads a cloudconfig module list, returns # a 2 dimensional array suitable to pass to run_cc_modules def read_cc_modules(cfg,name): - if name not in cfg: return([]) + if name not in cfg: + return([]) module_list = [] # create 'module_list', an array of arrays # where array[0] = config @@ -126,13 +128,15 @@ def run_cc_modules(cc,module_list,log): # None if if none is given def get_output_cfg(cfg, mode="init"): ret = [ None, None ] - if not 'output' in cfg: return ret + if not 'output' in cfg: + return ret outcfg = cfg['output'] if mode in outcfg: modecfg = outcfg[mode] else: - if 'all' not in outcfg: return ret + if 'all' not in outcfg: + return ret # if there is a 'all' item in the output list # then it applies to all users of this (init, config, final) modecfg = outcfg['all'] @@ -143,7 +147,8 @@ def get_output_cfg(cfg, mode="init"): # if its a list, then we expect (stdout, stderr) if isinstance(modecfg,list): - if len(modecfg) > 0: ret[0] = modecfg[0] + if len(modecfg) > 0: + ret[0] = modecfg[0] if len(modecfg) > 1: ret[1] = modecfg[1] @@ -157,11 +162,13 @@ def get_output_cfg(cfg, mode="init"): # if err's entry == "&1", then make it same as stdout # as in shell syntax of "echo foo >/dev/null 2>&1" - if ret[1] == "&1": ret[1] = ret[0] + if ret[1] == "&1": + ret[1] = ret[0] swlist = [ ">>", ">", "|" ] for i in range(len(ret)): - if not ret[i]: continue + if not ret[i]: + continue val = ret[i].lstrip() found = False for s in swlist: @@ -191,7 +198,8 @@ def redirect_output(outfmt,errfmt, o_out=sys.stdout, o_err=sys.stderr): (mode, arg) = outfmt.split(" ",1) if mode == ">" or mode == ">>": owith = "ab" - if mode == ">": owith = "wb" + if mode == ">": + owith = "wb" new_fp = open(arg, owith) elif mode == "|": proc = subprocess.Popen(arg, shell=True, stdin=subprocess.PIPE) @@ -209,7 +217,8 @@ def redirect_output(outfmt,errfmt, o_out=sys.stdout, o_err=sys.stderr): (mode, arg) = errfmt.split(" ",1) if mode == ">" or mode == ">>": owith = "ab" - if mode == ">": owith = "wb" + if mode == ">": + owith = "wb" new_fp = open(arg, owith) elif mode == "|": proc = subprocess.Popen(arg, shell=True, stdin=subprocess.PIPE) @@ -223,13 +232,15 @@ def redirect_output(outfmt,errfmt, o_out=sys.stdout, o_err=sys.stderr): def run_per_instance(name, func, args, clear_on_fail=False): semfile = "%s/%s" % (cloudinit.get_ipath_cur("data"),name) - if os.path.exists(semfile): return + if os.path.exists(semfile): + return util.write_file(semfile,str(time.time())) try: func(*args) except: - if clear_on_fail: os.unlink(semfile) + if clear_on_fail: + os.unlink(semfile) raise # apt_get top level command (install, update...), and args to pass it diff --git a/cloudinit/CloudConfig/cc_apt_update_upgrade.py b/cloudinit/CloudConfig/cc_apt_update_upgrade.py index 0cbe02d4..e911db89 100644 --- a/cloudinit/CloudConfig/cc_apt_update_upgrade.py +++ b/cloudinit/CloudConfig/cc_apt_update_upgrade.py @@ -104,7 +104,8 @@ def handle(_name,cfg,cloud,log,_args): def mirror2lists_fileprefix(mirror): string=mirror # take of http:// or ftp:// - if string.endswith("/"): string=string[0:-1] + if string.endswith("/"): + string=string[0:-1] pos=string.find("://") if pos >= 0: string=string[pos+3:] @@ -115,7 +116,8 @@ def rename_apt_lists(omirror,new_mirror,lists_d="/var/lib/apt/lists"): oprefix="%s/%s" % (lists_d,mirror2lists_fileprefix(omirror)) nprefix="%s/%s" % (lists_d,mirror2lists_fileprefix(new_mirror)) - if(oprefix==nprefix): return + if(oprefix==nprefix): + return olen=len(oprefix) for filename in glob.glob("%s_*" % oprefix): os.rename(filename,"%s%s" % (nprefix, filename[olen:])) @@ -143,7 +145,8 @@ def add_sources(srclist, searchList=None): source=ent['source'] if source.startswith("ppa:"): - try: util.subp(["add-apt-repository",source]) + try: + util.subp(["add-apt-repository",source]) except: elst.append([source, "add-apt-repository failed"]) continue @@ -159,7 +162,8 @@ def add_sources(srclist, searchList=None): if ( ent.has_key('keyid') and not ent.has_key('key') ): ks = "keyserver.ubuntu.com" - if ent.has_key('keyserver'): ks = ent['keyserver'] + if ent.has_key('keyserver'): + ks = ent['keyserver'] try: ent['key'] = util.getkeybyid(ent['keyid'], ks) except: @@ -167,11 +171,13 @@ def add_sources(srclist, searchList=None): continue if ent.has_key('key'): - try: util.subp(('apt-key', 'add', '-'), ent['key']) + try: + util.subp(('apt-key', 'add', '-'), ent['key']) except: elst.append([source, "failed add key"]) - try: util.write_file(ent['filename'], source + "\n", omode="ab") + try: + util.write_file(ent['filename'], source + "\n", omode="ab") except: elst.append([source, "failed write to file %s" % ent['filename']]) diff --git a/cloudinit/CloudConfig/cc_byobu.py b/cloudinit/CloudConfig/cc_byobu.py index dd510dda..76c6f286 100644 --- a/cloudinit/CloudConfig/cc_byobu.py +++ b/cloudinit/CloudConfig/cc_byobu.py @@ -25,7 +25,8 @@ def handle(_name,cfg,_cloud,log,args): else: value = util.get_cfg_option_str(cfg,"byobu_by_default","") - if not value: return + if not value: + return if value == "user" or value == "system": value = "enable-%s" % value diff --git a/cloudinit/CloudConfig/cc_chef.py b/cloudinit/CloudConfig/cc_chef.py index 977fe80f..c40f1293 100644 --- a/cloudinit/CloudConfig/cc_chef.py +++ b/cloudinit/CloudConfig/cc_chef.py @@ -25,7 +25,8 @@ ruby_version_default = "1.8" def handle(_name,cfg,cloud,log,_args): # If there isn't a chef key in the configuration don't do anything - if not cfg.has_key('chef'): return + if not cfg.has_key('chef'): + return chef_cfg = cfg['chef'] # ensure the chef directories we use exist @@ -57,7 +58,8 @@ def handle(_name,cfg,cloud,log,_args): initial_json['run_list'] = chef_cfg['run_list'] if chef_cfg.has_key('initial_attributes'): initial_attributes = chef_cfg['initial_attributes'] - for k in initial_attributes.keys(): initial_json[k] = initial_attributes[k] + for k in initial_attributes.keys(): + initial_json[k] = initial_attributes[k] firstboot_json_fh.write(json.dumps(initial_json)) # If chef is not installed, we install chef based on 'install_type' diff --git a/cloudinit/CloudConfig/cc_grub_dpkg.py b/cloudinit/CloudConfig/cc_grub_dpkg.py index 97d79bdb..fde8cca1 100644 --- a/cloudinit/CloudConfig/cc_grub_dpkg.py +++ b/cloudinit/CloudConfig/cc_grub_dpkg.py @@ -33,10 +33,13 @@ def handle(_name,cfg,_cloud,log,_args): if (( os.path.exists("/dev/sda1") and not os.path.exists("/dev/sda") ) or ( os.path.exists("/dev/xvda1") and not os.path.exists("/dev/xvda") )): - if idevs == None: idevs="" - if idevs_empty == None: idevs_empty="true" + if idevs == None: + idevs="" + if idevs_empty == None: + idevs_empty="true" else: - if idevs_empty == None: idevs_empty="false" + if idevs_empty == None: + idevs_empty="false" if idevs == None: idevs = "/dev/sda" for dev in ( "/dev/sda", "/dev/vda", "/dev/sda1", "/dev/vda1"): diff --git a/cloudinit/CloudConfig/cc_locale.py b/cloudinit/CloudConfig/cc_locale.py index 8e91d3bf..31e3f56e 100644 --- a/cloudinit/CloudConfig/cc_locale.py +++ b/cloudinit/CloudConfig/cc_locale.py @@ -37,7 +37,8 @@ def handle(_name,cfg,cloud,log,args): locale_cfgfile = util.get_cfg_option_str(cfg, "locale_configfile", "/etc/default/locale") - if not locale: return + if not locale: + return log.debug("setting locale to %s" % locale) diff --git a/cloudinit/CloudConfig/cc_mcollective.py b/cloudinit/CloudConfig/cc_mcollective.py index 38fe4a3c..0d1f01b3 100644 --- a/cloudinit/CloudConfig/cc_mcollective.py +++ b/cloudinit/CloudConfig/cc_mcollective.py @@ -34,13 +34,17 @@ class FakeSecHead(object): self.sechead = '[nullsection]\n' def readline(self): if self.sechead: - try: return self.sechead - finally: self.sechead = None - else: return self.fp.readline() + try: + return self.sechead + finally: + self.sechead = None + else: + return self.fp.readline() def handle(_name,cfg,_cloud,_log,_args): # If there isn't a mcollective key in the configuration don't do anything - if not cfg.has_key('mcollective'): return + if not cfg.has_key('mcollective'): + return mcollective_cfg = cfg['mcollective'] # Start by installing the mcollective package ... cc.install_packages(("mcollective",)) diff --git a/cloudinit/CloudConfig/cc_mounts.py b/cloudinit/CloudConfig/cc_mounts.py index a3036d5a..94ad1bba 100644 --- a/cloudinit/CloudConfig/cc_mounts.py +++ b/cloudinit/CloudConfig/cc_mounts.py @@ -50,7 +50,8 @@ def handle(_name,cfg,cloud,log,_args): for i in range(len(cfgmnt)): # skip something that wasn't a list - if not isinstance(cfgmnt[i],list): continue + if not isinstance(cfgmnt[i],list): + continue # workaround, allow user to specify 'ephemeral' # rather than more ec2 correct 'ephemeral0' @@ -98,7 +99,8 @@ def handle(_name,cfg,cloud,log,_args): # entry has the same device name for defmnt in defmnts: devname = cloud.device_name_to_device(defmnt[0]) - if devname is None: continue + if devname is None: + continue if devname.startswith("/"): defmnt[0] = devname else: @@ -110,7 +112,8 @@ def handle(_name,cfg,cloud,log,_args): cfgmnt_has = True break - if cfgmnt_has: continue + if cfgmnt_has: + continue cfgmnt.append(defmnt) @@ -118,7 +121,8 @@ def handle(_name,cfg,cloud,log,_args): # if the second field is None (not the string, the value) we skip it actlist = [x for x in cfgmnt if x[1] is not None] - if len(actlist) == 0: return + if len(actlist) == 0: + return comment="comment=cloudconfig" cc_lines = [ ] @@ -127,8 +131,10 @@ def handle(_name,cfg,cloud,log,_args): for line in actlist: # write 'comment' in the fs_mntops, entry, claiming this line[3]="%s,comment=cloudconfig" % line[3] - if line[2] == "swap": needswap = True - if line[1].startswith("/"): dirs.append(line[1]) + if line[2] == "swap": + needswap = True + if line[1].startswith("/"): + dirs.append(line[1]) cc_lines.append('\t'.join(line)) fstab_lines = [ ] @@ -137,7 +143,8 @@ def handle(_name,cfg,cloud,log,_args): for line in fstab.read().splitlines(): try: toks = ws.split(line) - if toks[3].find(comment) != -1: continue + if toks[3].find(comment) != -1: + continue except: pass fstab_lines.append(line) @@ -150,13 +157,20 @@ def handle(_name,cfg,cloud,log,_args): fstab.close() if needswap: - try: util.subp(("swapon", "-a")) - except: log.warn("Failed to enable swap") + try: + util.subp(("swapon", "-a")) + except: + log.warn("Failed to enable swap") for d in dirs: - if os.path.exists(d): continue - try: os.makedirs(d) - except: log.warn("Failed to make '%s' config-mount\n",d) + if os.path.exists(d): + continue + try: + os.makedirs(d) + except: + log.warn("Failed to make '%s' config-mount\n",d) - try: util.subp(("mount","-a")) - except: log.warn("'mount -a' failed") + try: + util.subp(("mount","-a")) + except: + log.warn("'mount -a' failed") diff --git a/cloudinit/CloudConfig/cc_phone_home.py b/cloudinit/CloudConfig/cc_phone_home.py index 7897d31b..008139b7 100644 --- a/cloudinit/CloudConfig/cc_phone_home.py +++ b/cloudinit/CloudConfig/cc_phone_home.py @@ -35,7 +35,8 @@ def handle(_name,cfg,cloud,log,args): if len(args) != 0: ph_cfg = util.readconf(args[0]) else: - if not 'phone_home' in cfg: return + if not 'phone_home' in cfg: + return ph_cfg = cfg['phone_home'] if 'url' not in ph_cfg: diff --git a/cloudinit/CloudConfig/cc_puppet.py b/cloudinit/CloudConfig/cc_puppet.py index 3748559a..1a8c7f3a 100644 --- a/cloudinit/CloudConfig/cc_puppet.py +++ b/cloudinit/CloudConfig/cc_puppet.py @@ -27,7 +27,8 @@ import cloudinit.util as util def handle(_name,cfg,cloud,log,_args): # If there isn't a puppet key in the configuration don't do anything - if not cfg.has_key('puppet'): return + if not cfg.has_key('puppet'): + return puppet_cfg = cfg['puppet'] # Start by installing the puppet package ... cc.install_packages(("puppet",)) diff --git a/cloudinit/CloudConfig/cc_resizefs.py b/cloudinit/CloudConfig/cc_resizefs.py index adec70be..29e0fa34 100644 --- a/cloudinit/CloudConfig/cc_resizefs.py +++ b/cloudinit/CloudConfig/cc_resizefs.py @@ -33,7 +33,8 @@ def handle(_name,cfg,_cloud,log,args): else: resize_root = util.get_cfg_option_bool(cfg,"resize_rootfs",True) - if not resize_root: return + if not resize_root: + return # this really only uses the filename from mktemp, then we mknod into it (fd, devpth) = tempfile.mkstemp() diff --git a/cloudinit/CloudConfig/cc_rightscale_userdata.py b/cloudinit/CloudConfig/cc_rightscale_userdata.py index 2b43023c..fdbee954 100644 --- a/cloudinit/CloudConfig/cc_rightscale_userdata.py +++ b/cloudinit/CloudConfig/cc_rightscale_userdata.py @@ -51,7 +51,8 @@ def handle(_name,_cfg,cloud,log,_args): try: mdict = parse_qs(ud) - if not my_hookname in mdict: return + if not my_hookname in mdict: + return except: log.warn("failed to urlparse.parse_qa(userdata_raw())") raise @@ -66,7 +67,8 @@ def handle(_name,_cfg,cloud,log,_args): content = util.readurl(url) util.write_file(fname, content, mode=0700) except Exception as e: - if not first_e: first_e = None + if not first_e: + first_e = None log.warn("%s failed to read %s: %s" % (my_name, url, e)) if first_e: diff --git a/cloudinit/CloudConfig/cc_rsyslog.py b/cloudinit/CloudConfig/cc_rsyslog.py index ab85a6d8..90d09545 100644 --- a/cloudinit/CloudConfig/cc_rsyslog.py +++ b/cloudinit/CloudConfig/cc_rsyslog.py @@ -33,7 +33,8 @@ def handle(_name,cfg,_cloud,log,_args): # *.* @@syslogd.example.com # process 'rsyslog' - if not 'rsyslog' in cfg: return + if not 'rsyslog' in cfg: + return def_dir = cfg.get('rsyslog_dir', DEF_DIR) def_fname = cfg.get('rsyslog_filename', DEF_FILENAME) diff --git a/cloudinit/CloudConfig/cc_ssh.py b/cloudinit/CloudConfig/cc_ssh.py index 0aad2187..897ba9dc 100644 --- a/cloudinit/CloudConfig/cc_ssh.py +++ b/cloudinit/CloudConfig/cc_ssh.py @@ -33,8 +33,10 @@ def handle(_name,cfg,cloud,log,_args): # remove the static keys from the pristine image if cfg.get("ssh_deletekeys", True): for f in glob.glob("/etc/ssh/ssh_host_*key*"): - try: os.unlink(f) - except: pass + try: + os.unlink(f) + except: + pass if cfg.has_key("ssh_keys"): # if there are keys in cloud-config, use them @@ -56,7 +58,8 @@ def handle(_name,cfg,cloud,log,_args): cmd = 'o=$(ssh-keygen -yf "%s") && echo "$o" root@localhost > "%s"' for priv,pub in priv2pub.iteritems(): - if pub in cfg['ssh_keys'] or not priv in cfg['ssh_keys']: continue + if pub in cfg['ssh_keys'] or not priv in cfg['ssh_keys']: + continue pair=(key2file[priv][0], key2file[pub][0]) subprocess.call(('sh', '-xc', cmd % pair)) log.debug("generated %s from %s" % pair) diff --git a/cloudinit/CloudConfig/cc_ssh_import_id.py b/cloudinit/CloudConfig/cc_ssh_import_id.py index 7e7a54a1..e4588eaf 100644 --- a/cloudinit/CloudConfig/cc_ssh_import_id.py +++ b/cloudinit/CloudConfig/cc_ssh_import_id.py @@ -29,7 +29,8 @@ def handle(_name,cfg,_cloud,log,args): user = util.get_cfg_option_str(cfg,"user","ubuntu") ids = util.get_cfg_option_list_or_str(cfg,"ssh_import_id",[]) - if len(ids) == 0: return + if len(ids) == 0: + return cmd = [ "sudo", "-Hu", user, "ssh-import-id" ] + ids diff --git a/cloudinit/CloudConfig/cc_timezone.py b/cloudinit/CloudConfig/cc_timezone.py index 26b2796d..091271f4 100644 --- a/cloudinit/CloudConfig/cc_timezone.py +++ b/cloudinit/CloudConfig/cc_timezone.py @@ -30,7 +30,8 @@ def handle(_name,cfg,_cloud,log,args): else: timezone = util.get_cfg_option_str(cfg,"timezone",False) - if not timezone: return + if not timezone: + return tz_file = "%s/%s" % (tz_base , timezone) diff --git a/cloudinit/CloudConfig/cc_update_hostname.py b/cloudinit/CloudConfig/cc_update_hostname.py index 4bc1cb2b..9d09bbb8 100644 --- a/cloudinit/CloudConfig/cc_update_hostname.py +++ b/cloudinit/CloudConfig/cc_update_hostname.py @@ -51,7 +51,8 @@ def read_hostname(filename, default=None): if line: return line except IOError as e: - if e.errno != errno.ENOENT: raise + if e.errno != errno.ENOENT: + raise return default def update_hostname(hostname, prev_file, log): |