diff options
author | Scott Moser <smoser@ubuntu.com> | 2012-01-17 12:35:45 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2012-01-17 12:35:45 -0500 |
commit | 1a1da7c11e8bbb7e9f4b06a06ee5d6b18fdc1efc (patch) | |
tree | 2aaa1e47949d588bc11f05d2c139ca98b51d0ca5 /cloudinit/CloudConfig | |
parent | c33eedb47b2b22c797051da197fd80e74f1db179 (diff) | |
download | vyos-cloud-init-1a1da7c11e8bbb7e9f4b06a06ee5d6b18fdc1efc.tar.gz vyos-cloud-init-1a1da7c11e8bbb7e9f4b06a06ee5d6b18fdc1efc.zip |
[PATCH 3/4] Fix pylint conventions C0324 (comma not followed by a space)
From: Juerg Haefliger <juerg.haefliger@hp.com>
Diffstat (limited to 'cloudinit/CloudConfig')
31 files changed, 125 insertions, 125 deletions
diff --git a/cloudinit/CloudConfig/__init__.py b/cloudinit/CloudConfig/__init__.py index fb390090..caf7e333 100644 --- a/cloudinit/CloudConfig/__init__.py +++ b/cloudinit/CloudConfig/__init__.py @@ -33,7 +33,7 @@ class CloudConfig(): cfgfile = None cfg = None - def __init__(self,cfgfile, cloud=None, ds_deps=None): + def __init__(self, cfgfile, cloud=None, ds_deps=None): if cloud == None: self.cloud = cloudinit.CloudInit(ds_deps) self.cloud.get_data_source() @@ -41,7 +41,7 @@ class CloudConfig(): self.cloud = cloud self.cfg = self.get_config_obj(cfgfile) - def get_config_obj(self,cfgfile): + def get_config_obj(self, cfgfile): try: cfg = util.read_conf(cfgfile) except: @@ -58,12 +58,12 @@ class CloudConfig(): ds_cfg = { } cfg = util.mergedict(cfg, ds_cfg) - return(util.mergedict(cfg,self.cloud.cfg)) + return(util.mergedict(cfg, self.cloud.cfg)) def handle(self, name, args, freq=None): try: - mod = __import__("cc_" + name.replace("-","_"),globals()) - def_freq = getattr(mod, "frequency",per_instance) + mod = __import__("cc_" + name.replace("-", "_"), globals()) + def_freq = getattr(mod, "frequency", per_instance) handler = getattr(mod, "handle") if not freq: @@ -76,7 +76,7 @@ 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): +def read_cc_modules(cfg, name): if name not in cfg: return([]) module_list = [] @@ -85,15 +85,15 @@ def read_cc_modules(cfg,name): # array[1] = freq # array[2:] = arguemnts for item in cfg[name]: - if isinstance(item,str): + if isinstance(item, str): module_list.append((item,)) - elif isinstance(item,list): + elif isinstance(item, list): module_list.append(item) else: raise TypeError("failed to read '%s' item in config") return(module_list) -def run_cc_modules(cc,module_list,log): +def run_cc_modules(cc, module_list, log): failures = [] for cfg_mod in module_list: name = cfg_mod[0] @@ -111,7 +111,7 @@ def run_cc_modules(cc,module_list,log): except: log.warn(traceback.format_exc()) log.error("config handling of %s, %s, %s failed\n" % - (name,freq,run_args)) + (name, freq, run_args)) failures.append(name) return(failures) @@ -142,11 +142,11 @@ def get_output_cfg(cfg, mode="init"): modecfg = outcfg['all'] # if value is a string, it specifies stdout and stderr - if isinstance(modecfg,str): + if isinstance(modecfg, str): ret = [ modecfg, modecfg ] # if its a list, then we expect (stdout, stderr) - if isinstance(modecfg,list): + if isinstance(modecfg, list): if len(modecfg) > 0: ret[0] = modecfg[0] if len(modecfg) > 1: @@ -173,7 +173,7 @@ def get_output_cfg(cfg, mode="init"): found = False for s in swlist: if val.startswith(s): - val = "%s %s" % (s,val[len(s):].strip()) + val = "%s %s" % (s, val[len(s):].strip()) found = True break if not found: @@ -193,9 +193,9 @@ def get_output_cfg(cfg, mode="init"): # # with a '|', arguments are passed to shell, so one level of # shell escape is required. -def redirect_output(outfmt,errfmt, o_out=sys.stdout, o_err=sys.stderr): +def redirect_output(outfmt, errfmt, o_out=sys.stdout, o_err=sys.stderr): if outfmt: - (mode, arg) = outfmt.split(" ",1) + (mode, arg) = outfmt.split(" ", 1) if mode == ">" or mode == ">>": owith = "ab" if mode == ">": @@ -214,7 +214,7 @@ def redirect_output(outfmt,errfmt, o_out=sys.stdout, o_err=sys.stderr): return if errfmt: - (mode, arg) = errfmt.split(" ",1) + (mode, arg) = errfmt.split(" ", 1) if mode == ">" or mode == ">>": owith = "ab" if mode == ">": @@ -231,11 +231,11 @@ def redirect_output(outfmt,errfmt, o_out=sys.stdout, o_err=sys.stderr): return def run_per_instance(name, func, args, clear_on_fail=False): - semfile = "%s/%s" % (cloudinit.get_ipath_cur("data"),name) + semfile = "%s/%s" % (cloudinit.get_ipath_cur("data"), name) if os.path.exists(semfile): return - util.write_file(semfile,str(time.time())) + util.write_file(semfile, str(time.time())) try: func(*args) except: @@ -244,7 +244,7 @@ def run_per_instance(name, func, args, clear_on_fail=False): raise # apt_get top level command (install, update...), and args to pass it -def apt_get(tlc,args=None): +def apt_get(tlc, args=None): if args is None: args = [] e = os.environ.copy() @@ -252,11 +252,11 @@ def apt_get(tlc,args=None): cmd = ['apt-get', '--option', 'Dpkg::Options::=--force-confold', '--assume-yes', tlc] cmd.extend(args) - subprocess.check_call(cmd,env=e) + subprocess.check_call(cmd, env=e) def update_package_sources(): run_per_instance("update-sources", apt_get, ("update",)) def install_packages(pkglist): update_package_sources() - apt_get("install",pkglist) + apt_get("install", pkglist) diff --git a/cloudinit/CloudConfig/cc_apt_update_upgrade.py b/cloudinit/CloudConfig/cc_apt_update_upgrade.py index e4c08708..1da4e613 100644 --- a/cloudinit/CloudConfig/cc_apt_update_upgrade.py +++ b/cloudinit/CloudConfig/cc_apt_update_upgrade.py @@ -22,7 +22,7 @@ import os import glob import cloudinit.CloudConfig as cc -def handle(_name,cfg,cloud,log,_args): +def handle(_name, cfg, cloud, log, _args): update = util.get_cfg_option_bool(cfg, 'apt_update', False) upgrade = util.get_cfg_option_bool(cfg, 'apt_upgrade', False) @@ -35,7 +35,7 @@ def handle(_name,cfg,cloud,log,_args): if not util.get_cfg_option_bool(cfg, \ 'apt_preserve_sources_list', False): generate_sources_list(release, mirror) - old_mir = util.get_cfg_option_str(cfg,'apt_old_mirror', \ + old_mir = util.get_cfg_option_str(cfg, 'apt_old_mirror', \ "archive.ubuntu.com/ubuntu") rename_apt_lists(old_mir, mirror) @@ -46,7 +46,7 @@ def handle(_name,cfg,cloud,log,_args): if proxy: try: contents = "Acquire::HTTP::Proxy \"%s\";\n" - with open(proxy_filename,"w") as fp: + with open(proxy_filename, "w") as fp: fp.write(contents % proxy) except Exception as e: log.warn("Failed to write proxy to %s" % proxy_filename) @@ -69,7 +69,7 @@ def handle(_name,cfg,cloud,log,_args): log.error("Failed to run debconf-set-selections") log.debug(traceback.format_exc()) - pkglist = util.get_cfg_option_list_or_str(cfg,'packages',[]) + pkglist = util.get_cfg_option_list_or_str(cfg, 'packages', []) errors = [ ] if update or len(pkglist) or upgrade: @@ -109,18 +109,18 @@ def mirror2lists_fileprefix(mirror): pos = string.find("://") if pos >= 0: string = string[pos+3:] - string = string.replace("/","_") + string = string.replace("/", "_") return string -def rename_apt_lists(omirror,new_mirror,lists_d="/var/lib/apt/lists"): +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)) + oprefix = "%s/%s" % (lists_d, mirror2lists_fileprefix(omirror)) + nprefix = "%s/%s" % (lists_d, mirror2lists_fileprefix(new_mirror)) if(oprefix == nprefix): return olen = len(oprefix) for filename in glob.glob("%s_*" % oprefix): - os.rename(filename,"%s%s" % (nprefix, filename[olen:])) + os.rename(filename, "%s%s" % (nprefix, filename[olen:])) def get_release(): stdout, _stderr = subprocess.Popen(['lsb_release', '-cs'], stdout=subprocess.PIPE).communicate() @@ -146,7 +146,7 @@ def add_sources(srclist, searchList=None): source = ent['source'] if source.startswith("ppa:"): try: - util.subp(["add-apt-repository",source]) + util.subp(["add-apt-repository", source]) except: elst.append([source, "add-apt-repository failed"]) continue @@ -167,7 +167,7 @@ def add_sources(srclist, searchList=None): try: ent['key'] = util.getkeybyid(ent['keyid'], ks) except: - elst.append([source,"failed to get key from %s" % ks]) + elst.append([source, "failed to get key from %s" % ks]) continue if ent.has_key('key'): @@ -195,7 +195,7 @@ def find_apt_mirror(cloud, cfg): } mirror = None - cfg_mirror = cfg.get("apt_mirror",None) + cfg_mirror = cfg.get("apt_mirror", None) if cfg_mirror: mirror = cfg["apt_mirror"] elif cfg.has_key("apt_mirror_search"): diff --git a/cloudinit/CloudConfig/cc_bootcmd.py b/cloudinit/CloudConfig/cc_bootcmd.py index 47778897..98a7a747 100644 --- a/cloudinit/CloudConfig/cc_bootcmd.py +++ b/cloudinit/CloudConfig/cc_bootcmd.py @@ -21,7 +21,7 @@ import tempfile from cloudinit.CloudConfig import per_always frequency = per_always -def handle(_name,cfg,cloud,log,_args): +def handle(_name, cfg, cloud, log, _args): if not cfg.has_key("bootcmd"): return diff --git a/cloudinit/CloudConfig/cc_byobu.py b/cloudinit/CloudConfig/cc_byobu.py index 76c6f286..04825521 100644 --- a/cloudinit/CloudConfig/cc_byobu.py +++ b/cloudinit/CloudConfig/cc_byobu.py @@ -19,11 +19,11 @@ import cloudinit.util as util import subprocess import traceback -def handle(_name,cfg,_cloud,log,args): +def handle(_name, cfg, _cloud, log, args): if len(args) != 0: value = args[0] else: - value = util.get_cfg_option_str(cfg,"byobu_by_default","") + value = util.get_cfg_option_str(cfg, "byobu_by_default", "") if not value: return @@ -51,7 +51,7 @@ def handle(_name,cfg,_cloud,log,args): shcmd = "" if mod_user: - user = util.get_cfg_option_str(cfg,"user","ubuntu") + user = util.get_cfg_option_str(cfg, "user", "ubuntu") shcmd += " sudo -Hu \"%s\" byobu-launcher-%s" % (user, bl_inst) shcmd += " || X=$(($X+1)); " if mod_sys: diff --git a/cloudinit/CloudConfig/cc_chef.py b/cloudinit/CloudConfig/cc_chef.py index c40f1293..55ecdab4 100644 --- a/cloudinit/CloudConfig/cc_chef.py +++ b/cloudinit/CloudConfig/cc_chef.py @@ -23,7 +23,7 @@ import cloudinit.util as util ruby_version_default = "1.8" -def handle(_name,cfg,cloud,log,_args): +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 @@ -92,13 +92,13 @@ def install_chef_from_gems(ruby_version, chef_version = None): if not os.path.exists('/usr/bin/ruby'): os.symlink('/usr/bin/ruby%s' % ruby_version, '/usr/bin/ruby') if chef_version: - subprocess.check_call(['/usr/bin/gem','install','chef', + subprocess.check_call(['/usr/bin/gem', 'install', 'chef', '-v %s' % chef_version, '--no-ri', - '--no-rdoc','--bindir','/usr/bin','-q']) + '--no-rdoc', '--bindir', '/usr/bin', '-q']) else: - subprocess.check_call(['/usr/bin/gem','install','chef', - '--no-ri','--no-rdoc','--bindir', - '/usr/bin','-q']) + subprocess.check_call(['/usr/bin/gem', 'install', 'chef', + '--no-ri', '--no-rdoc', '--bindir', + '/usr/bin', '-q']) def ensure_dir(d): if not os.path.exists(d): diff --git a/cloudinit/CloudConfig/cc_disable_ec2_metadata.py b/cloudinit/CloudConfig/cc_disable_ec2_metadata.py index ff95f4bf..383e3b0c 100644 --- a/cloudinit/CloudConfig/cc_disable_ec2_metadata.py +++ b/cloudinit/CloudConfig/cc_disable_ec2_metadata.py @@ -21,7 +21,7 @@ from cloudinit.CloudConfig import per_always frequency = per_always -def handle(_name,cfg,_cloud,_log,_args): +def handle(_name, cfg, _cloud, _log, _args): if util.get_cfg_option_bool(cfg, "disable_ec2_metadata", False): fwall = "route add -host 169.254.169.254 reject" subprocess.call(fwall.split(' ')) diff --git a/cloudinit/CloudConfig/cc_final_message.py b/cloudinit/CloudConfig/cc_final_message.py index ef0d9ad0..7930bab5 100644 --- a/cloudinit/CloudConfig/cc_final_message.py +++ b/cloudinit/CloudConfig/cc_final_message.py @@ -24,11 +24,11 @@ frequency = per_always final_message = "cloud-init boot finished at $TIMESTAMP. Up $UPTIME seconds" -def handle(_name,cfg,_cloud,log,args): +def handle(_name, cfg, _cloud, log, args): if len(args) != 0: msg_in = args[0] else: - msg_in = util.get_cfg_option_str(cfg,"final_message",final_message) + msg_in = util.get_cfg_option_str(cfg, "final_message", final_message) try: uptimef = open("/proc/uptime") @@ -40,7 +40,7 @@ def handle(_name,cfg,_cloud,log,args): try: - ts = time.strftime("%a, %d %b %Y %H:%M:%S %z",time.gmtime()) + ts = time.strftime("%a, %d %b %Y %H:%M:%S %z", time.gmtime()) except: ts = "na" diff --git a/cloudinit/CloudConfig/cc_foo.py b/cloudinit/CloudConfig/cc_foo.py index 48d20e5b..82a44baf 100644 --- a/cloudinit/CloudConfig/cc_foo.py +++ b/cloudinit/CloudConfig/cc_foo.py @@ -22,5 +22,5 @@ from cloudinit.CloudConfig import per_instance frequency = per_instance -def handle(_name,_cfg,_cloud,_log,_args): +def handle(_name, _cfg, _cloud, _log, _args): print "hi" diff --git a/cloudinit/CloudConfig/cc_grub_dpkg.py b/cloudinit/CloudConfig/cc_grub_dpkg.py index 4e1ba4d4..1437d481 100644 --- a/cloudinit/CloudConfig/cc_grub_dpkg.py +++ b/cloudinit/CloudConfig/cc_grub_dpkg.py @@ -20,16 +20,16 @@ import cloudinit.util as util import traceback import os -def handle(_name,cfg,_cloud,log,_args): +def handle(_name, cfg, _cloud, log, _args): idevs = None idevs_empty = None if "grub-dpkg" in cfg: idevs = util.get_cfg_option_str(cfg["grub-dpkg"], - "grub-pc/install_devices",None) + "grub-pc/install_devices", None) idevs_empty = util.get_cfg_option_str(cfg["grub-dpkg"], - "grub-pc/install_devices_empty",None) + "grub-pc/install_devices_empty", None) 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") )): @@ -53,7 +53,7 @@ def handle(_name,cfg,_cloud,log,_args): dconf_sel = "grub-pc grub-pc/install_devices string %s\n" % idevs + \ "grub-pc grub-pc/install_devices_empty boolean %s\n" % idevs_empty log.debug("setting grub debconf-set-selections with '%s','%s'" % - (idevs,idevs_empty)) + (idevs, idevs_empty)) try: util.subp(('debconf-set-selections'), dconf_sel) diff --git a/cloudinit/CloudConfig/cc_keys_to_console.py b/cloudinit/CloudConfig/cc_keys_to_console.py index 08e8f085..bbc45c4a 100644 --- a/cloudinit/CloudConfig/cc_keys_to_console.py +++ b/cloudinit/CloudConfig/cc_keys_to_console.py @@ -21,12 +21,12 @@ import subprocess frequency = per_instance -def handle(_name,cfg,_cloud,log,_args): +def handle(_name, cfg, _cloud, log, _args): cmd = [ '/usr/lib/cloud-init/write-ssh-key-fingerprints' ] fp_blacklist = util.get_cfg_option_list_or_str(cfg, "ssh_fp_console_blacklist", []) key_blacklist = util.get_cfg_option_list_or_str(cfg, "ssh_key_console_blacklist", ["ssh-dss"]) try: - confp = open('/dev/console',"wb") + confp = open('/dev/console', "wb") cmd.append(','.join(fp_blacklist)) cmd.append(','.join(key_blacklist)) subprocess.call(cmd, stdout=confp) diff --git a/cloudinit/CloudConfig/cc_landscape.py b/cloudinit/CloudConfig/cc_landscape.py index 22a90665..d2d2bd19 100644 --- a/cloudinit/CloudConfig/cc_landscape.py +++ b/cloudinit/CloudConfig/cc_landscape.py @@ -32,7 +32,7 @@ lsc_builtincfg = { } } -def handle(_name,cfg,_cloud,log,_args): +def handle(_name, cfg, _cloud, log, _args): """ Basically turn a top level 'landscape' entry with a 'client' dict and render it to ConfigObj format under '[client]' section in diff --git a/cloudinit/CloudConfig/cc_locale.py b/cloudinit/CloudConfig/cc_locale.py index 31e3f56e..991f5861 100644 --- a/cloudinit/CloudConfig/cc_locale.py +++ b/cloudinit/CloudConfig/cc_locale.py @@ -28,11 +28,11 @@ def apply_locale(locale, cfgfile): util.render_to_file('default-locale', cfgfile, { 'locale' : locale }) -def handle(_name,cfg,cloud,log,args): +def handle(_name, cfg, cloud, log, args): if len(args) != 0: locale = args[0] else: - locale = util.get_cfg_option_str(cfg,"locale",cloud.get_locale()) + locale = util.get_cfg_option_str(cfg, "locale", cloud.get_locale()) locale_cfgfile = util.get_cfg_option_str(cfg, "locale_configfile", "/etc/default/locale") diff --git a/cloudinit/CloudConfig/cc_mcollective.py b/cloudinit/CloudConfig/cc_mcollective.py index 0d1f01b3..ec5da4f8 100644 --- a/cloudinit/CloudConfig/cc_mcollective.py +++ b/cloudinit/CloudConfig/cc_mcollective.py @@ -41,7 +41,7 @@ class FakeSecHead(object): else: return self.fp.readline() -def handle(_name,cfg,_cloud,_log,_args): +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 @@ -60,20 +60,20 @@ def handle(_name,cfg,_cloud,_log,_args): util.write_file(pubcert_file, cfg, mode=0644) mcollective_config.set(cfg_name, 'plugin.ssl_server_public', pubcert_file) - mcollective_config.set(cfg_name,'securityprovider','ssl') + mcollective_config.set(cfg_name, 'securityprovider', 'ssl') elif cfg_name == 'private-cert': util.write_file(pricert_file, cfg, mode=0600) mcollective_config.set(cfg_name, 'plugin.ssl_server_private', pricert_file) - mcollective_config.set(cfg_name,'securityprovider','ssl') + mcollective_config.set(cfg_name, 'securityprovider', 'ssl') else: # Iterate throug the config items, we'll use ConfigParser.set # to overwrite or create new items as needed for o, v in cfg.iteritems(): - mcollective_config.set(cfg_name,o,v) + mcollective_config.set(cfg_name, o, v) # We got all our config as wanted we'll rename # the previous server.cfg and create our new one - os.rename('/etc/mcollective/server.cfg','/etc/mcollective/server.cfg.old') + os.rename('/etc/mcollective/server.cfg', '/etc/mcollective/server.cfg.old') outputfile = StringIO.StringIO() mcollective_config.write(outputfile) # Now we got the whole file, write to disk except first line @@ -83,7 +83,7 @@ def handle(_name,cfg,_cloud,_log,_args): # search and replace of '=' with ':' could be problematic though. # this most likely needs fixing. util.write_file('/etc/mcollective/server.cfg', - outputfile.getvalue().replace('[nullsection]\n','').replace(' =',':'), + outputfile.getvalue().replace('[nullsection]\n', '').replace(' =', ':'), mode=0644) # Start mcollective diff --git a/cloudinit/CloudConfig/cc_mounts.py b/cloudinit/CloudConfig/cc_mounts.py index 248abb24..f7d8c702 100644 --- a/cloudinit/CloudConfig/cc_mounts.py +++ b/cloudinit/CloudConfig/cc_mounts.py @@ -31,7 +31,7 @@ def is_mdname(name): return True return False -def handle(_name,cfg,cloud,log,_args): +def handle(_name, cfg, cloud, log, _args): # fs_spec, fs_file, fs_vfstype, fs_mntops, fs-freq, fs_passno defvals = [ None, None, "auto", "defaults,nobootwait", "0", "2" ] defvals = cfg.get("mount_default_fields", defvals) @@ -50,7 +50,7 @@ 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): + if not isinstance(cfgmnt[i], list): continue # workaround, allow user to specify 'ephemeral' @@ -138,7 +138,7 @@ def handle(_name,cfg,cloud,log,_args): cc_lines.append('\t'.join(line)) fstab_lines = [ ] - fstab = open("/etc/fstab","r+") + fstab = open("/etc/fstab", "r+") ws = re.compile("[%s]+" % string.whitespace) for line in fstab.read().splitlines(): try: @@ -168,9 +168,9 @@ def handle(_name,cfg,cloud,log,_args): try: os.makedirs(d) except: - log.warn("Failed to make '%s' config-mount\n",d) + log.warn("Failed to make '%s' config-mount\n", d) try: - util.subp(("mount","-a")) + 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 008139b7..61b769a7 100644 --- a/cloudinit/CloudConfig/cc_phone_home.py +++ b/cloudinit/CloudConfig/cc_phone_home.py @@ -31,7 +31,7 @@ post_list_all = [ 'pub_key_dsa', 'pub_key_rsa', 'pub_key_ecdsa', 'instance_id', # url: http://my.foo.bar/$INSTANCE_ID/ # post: [ pub_key_dsa, pub_key_rsa, pub_key_ecdsa, instance_id # -def handle(_name,cfg,cloud,log,args): +def handle(_name, cfg, cloud, log, args): if len(args) != 0: ph_cfg = util.readconf(args[0]) else: @@ -45,7 +45,7 @@ def handle(_name,cfg,cloud,log,args): url = ph_cfg['url'] post_list = ph_cfg.get('post', 'all') - tries = ph_cfg.get('tries',10) + tries = ph_cfg.get('tries', 10) try: tries = int(tries) except: @@ -84,7 +84,7 @@ def handle(_name,cfg,cloud,log,args): url = util.render_string(url, { 'INSTANCE_ID' : all_keys['instance_id'] }) last_e = None - for i in range(0,tries): + for i in range(0, tries): try: util.readurl(url, submit_keys) log.debug("succeeded submit to %s on try %i" % (url, i+1)) diff --git a/cloudinit/CloudConfig/cc_puppet.py b/cloudinit/CloudConfig/cc_puppet.py index 1a8c7f3a..2686c849 100644 --- a/cloudinit/CloudConfig/cc_puppet.py +++ b/cloudinit/CloudConfig/cc_puppet.py @@ -25,7 +25,7 @@ import ConfigParser import cloudinit.CloudConfig as cc import cloudinit.util as util -def handle(_name,cfg,cloud,log,_args): +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 @@ -78,11 +78,11 @@ def handle(_name,cfg,cloud,log,_args): cloud.datasource.get_instance_id()) # certname needs to be downcase v = v.lower() - puppet_config.set(cfg_name,o,v) + puppet_config.set(cfg_name, o, v) #puppet_conf_fh.write("%s=%s\n" % (o, v)) # We got all our config as wanted we'll rename # the previous puppet.conf and create our new one - os.rename('/etc/puppet/puppet.conf','/etc/puppet/puppet.conf.old') + os.rename('/etc/puppet/puppet.conf', '/etc/puppet/puppet.conf.old') with open('/etc/puppet/puppet.conf', 'wb') as configfile: puppet_config.write(configfile) util.restorecon_if_possible('/etc/puppet/puppet.conf') diff --git a/cloudinit/CloudConfig/cc_resizefs.py b/cloudinit/CloudConfig/cc_resizefs.py index 1fdf8647..1fd9f094 100644 --- a/cloudinit/CloudConfig/cc_resizefs.py +++ b/cloudinit/CloudConfig/cc_resizefs.py @@ -25,13 +25,13 @@ from cloudinit.CloudConfig import per_always frequency = per_always -def handle(_name,cfg,_cloud,log,args): +def handle(_name, cfg, _cloud, log, args): if len(args) != 0: resize_root = False if str(args[0]).lower() in [ 'true', '1', 'on', 'yes']: resize_root = True else: - resize_root = util.get_cfg_option_bool(cfg,"resize_rootfs",True) + resize_root = util.get_cfg_option_bool(cfg, "resize_rootfs", True) if not resize_root: return @@ -43,7 +43,7 @@ def handle(_name,cfg,_cloud,log,args): try: st_dev = os.stat("/").st_dev - dev = os.makedev(os.major(st_dev),os.minor(st_dev)) + dev = os.makedev(os.major(st_dev), os.minor(st_dev)) os.mknod(devpth, 0400 | stat.S_IFBLK, dev) except: if util.islxc(): @@ -54,7 +54,7 @@ def handle(_name,cfg,_cloud,log,args): cmd = [ 'blkid', '-c', '/dev/null', '-sTYPE', '-ovalue', devpth ] try: - (fstype,_err) = util.subp(cmd) + (fstype, _err) = util.subp(cmd) except subprocess.CalledProcessError as e: log.warn("Failed to get filesystem type of maj=%s, min=%s via: %s" % (os.major(st_dev), os.minor(st_dev), cmd)) diff --git a/cloudinit/CloudConfig/cc_rightscale_userdata.py b/cloudinit/CloudConfig/cc_rightscale_userdata.py index fdbee954..61aa89d1 100644 --- a/cloudinit/CloudConfig/cc_rightscale_userdata.py +++ b/cloudinit/CloudConfig/cc_rightscale_userdata.py @@ -42,7 +42,7 @@ frequency = per_instance my_name = "cc_rightscale_userdata" my_hookname = 'CLOUD_INIT_REMOTE_HOOK' -def handle(_name,_cfg,cloud,log,_args): +def handle(_name, _cfg, cloud, log, _args): try: ud = cloud.get_userdata_raw() except: @@ -61,7 +61,7 @@ def handle(_name,_cfg,cloud,log,_args): i = 0 first_e = None for url in mdict[my_hookname]: - fname = "%s/rightscale-%02i" % (scripts_d,i) + fname = "%s/rightscale-%02i" % (scripts_d, i) i = i +1 try: content = util.readurl(url) diff --git a/cloudinit/CloudConfig/cc_rsyslog.py b/cloudinit/CloudConfig/cc_rsyslog.py index 90d09545..e5f38c36 100644 --- a/cloudinit/CloudConfig/cc_rsyslog.py +++ b/cloudinit/CloudConfig/cc_rsyslog.py @@ -24,7 +24,7 @@ import traceback DEF_FILENAME = "20-cloud-config.conf" DEF_DIR = "/etc/rsyslog.d" -def handle(_name,cfg,_cloud,log,_args): +def handle(_name, cfg, _cloud, log, _args): # rsyslog: # - "*.* @@192.158.1.1" # - content: "*.* @@192.0.2.1:10514" @@ -42,7 +42,7 @@ def handle(_name,cfg,_cloud,log,_args): files = [ ] elst = [ ] for ent in cfg['rsyslog']: - if isinstance(ent,dict): + if isinstance(ent, dict): if not "content" in ent: elst.append((ent, "no 'content' entry")) continue @@ -53,7 +53,7 @@ def handle(_name,cfg,_cloud,log,_args): filename = def_fname if not filename.startswith("/"): - filename = "%s/%s" % (def_dir,filename) + filename = "%s/%s" % (def_dir, filename) omode = "ab" # truncate filename first time you see it diff --git a/cloudinit/CloudConfig/cc_runcmd.py b/cloudinit/CloudConfig/cc_runcmd.py index 0adf31ad..3c9baa6f 100644 --- a/cloudinit/CloudConfig/cc_runcmd.py +++ b/cloudinit/CloudConfig/cc_runcmd.py @@ -18,12 +18,12 @@ import cloudinit.util as util -def handle(_name,cfg,cloud,log,_args): +def handle(_name, cfg, cloud, log, _args): if not cfg.has_key("runcmd"): return outfile = "%s/runcmd" % cloud.get_ipath('scripts') try: content = util.shellify(cfg["runcmd"]) - util.write_file(outfile,content,0700) + util.write_file(outfile, content, 0700) except: log.warn("failed to open %s for runcmd" % outfile) diff --git a/cloudinit/CloudConfig/cc_scripts_per_boot.py b/cloudinit/CloudConfig/cc_scripts_per_boot.py index fb643c6d..ee79f0a3 100644 --- a/cloudinit/CloudConfig/cc_scripts_per_boot.py +++ b/cloudinit/CloudConfig/cc_scripts_per_boot.py @@ -23,7 +23,7 @@ from cloudinit import get_cpath frequency = per_always runparts_path = "%s/%s" % (get_cpath(), "scripts/per-boot") -def handle(_name,_cfg,_cloud,log,_args): +def handle(_name, _cfg, _cloud, log, _args): try: util.runparts(runparts_path) except: diff --git a/cloudinit/CloudConfig/cc_scripts_per_instance.py b/cloudinit/CloudConfig/cc_scripts_per_instance.py index b0f0601a..499829ec 100644 --- a/cloudinit/CloudConfig/cc_scripts_per_instance.py +++ b/cloudinit/CloudConfig/cc_scripts_per_instance.py @@ -23,7 +23,7 @@ from cloudinit import get_cpath frequency = per_instance runparts_path = "%s/%s" % (get_cpath(), "scripts/per-instance") -def handle(_name,_cfg,_cloud,log,_args): +def handle(_name, _cfg, _cloud, log, _args): try: util.runparts(runparts_path) except: diff --git a/cloudinit/CloudConfig/cc_scripts_per_once.py b/cloudinit/CloudConfig/cc_scripts_per_once.py index 2ab81840..6c43c6f0 100644 --- a/cloudinit/CloudConfig/cc_scripts_per_once.py +++ b/cloudinit/CloudConfig/cc_scripts_per_once.py @@ -23,7 +23,7 @@ from cloudinit import get_cpath frequency = per_once runparts_path = "%s/%s" % (get_cpath(), "scripts/per-once") -def handle(_name,_cfg,_cloud,log,_args): +def handle(_name, _cfg, _cloud, log, _args): try: util.runparts(runparts_path) except: diff --git a/cloudinit/CloudConfig/cc_scripts_user.py b/cloudinit/CloudConfig/cc_scripts_user.py index 9c7f2322..3db3c7a6 100644 --- a/cloudinit/CloudConfig/cc_scripts_user.py +++ b/cloudinit/CloudConfig/cc_scripts_user.py @@ -23,7 +23,7 @@ from cloudinit import get_ipath_cur frequency = per_instance runparts_path = "%s/%s" % (get_ipath_cur(), "scripts") -def handle(_name,_cfg,_cloud,log,_args): +def handle(_name, _cfg, _cloud, log, _args): try: util.runparts(runparts_path) except: diff --git a/cloudinit/CloudConfig/cc_set_hostname.py b/cloudinit/CloudConfig/cc_set_hostname.py index 4f19b0c8..18189ed0 100644 --- a/cloudinit/CloudConfig/cc_set_hostname.py +++ b/cloudinit/CloudConfig/cc_set_hostname.py @@ -18,8 +18,8 @@ import cloudinit.util as util -def handle(_name,cfg,cloud,log,_args): - if util.get_cfg_option_bool(cfg,"preserve_hostname",False): +def handle(_name, cfg, cloud, log, _args): + if util.get_cfg_option_bool(cfg, "preserve_hostname", False): log.debug("preserve_hostname is set. not setting hostname") return(True) @@ -34,5 +34,5 @@ def handle(_name,cfg,cloud,log,_args): def set_hostname(hostname, log): util.subp(['hostname', hostname]) - util.write_file("/etc/hostname","%s\n" % hostname, 0644) + util.write_file("/etc/hostname", "%s\n" % hostname, 0644) log.debug("populated /etc/hostname with %s on first boot", hostname) diff --git a/cloudinit/CloudConfig/cc_set_passwords.py b/cloudinit/CloudConfig/cc_set_passwords.py index 4059e9c1..15533460 100644 --- a/cloudinit/CloudConfig/cc_set_passwords.py +++ b/cloudinit/CloudConfig/cc_set_passwords.py @@ -21,14 +21,14 @@ import sys import random import string -def handle(_name,cfg,_cloud,log,args): +def handle(_name, cfg, _cloud, log, args): if len(args) != 0: # if run from command line, and give args, wipe the chpasswd['list'] password = args[0] if 'chpasswd' in cfg and 'list' in cfg['chpasswd']: del cfg['chpasswd']['list'] else: - password = util.get_cfg_option_str(cfg,"password",None) + password = util.get_cfg_option_str(cfg, "password", None) expire = True pw_auth = "no" @@ -37,11 +37,11 @@ def handle(_name,cfg,_cloud,log,args): if 'chpasswd' in cfg: chfg = cfg['chpasswd'] - plist = util.get_cfg_option_str(chfg,'list',plist) - expire = util.get_cfg_option_bool(chfg,'expire', expire) + plist = util.get_cfg_option_str(chfg, 'list', plist) + expire = util.get_cfg_option_bool(chfg, 'expire', expire) if not plist and password: - user = util.get_cfg_option_str(cfg,"user","ubuntu") + user = util.get_cfg_option_str(cfg, "user", "ubuntu") plist = "%s:%s" % (user, password) errors = [] @@ -50,11 +50,11 @@ def handle(_name,cfg,_cloud,log,args): randlist = [] users = [] for line in plist.splitlines(): - u,p = line.split(':',1) + u, p = line.split(':', 1) if p == "R" or p == "RANDOM": p = rand_user_password() - randlist.append("%s:%s" % (u,p)) - plist_in.append("%s:%s" % (u,p)) + randlist.append("%s:%s" % (u, p)) + plist_in.append("%s:%s" % (u, p)) users.append(u) ch_in = '\n'.join(plist_in) @@ -118,7 +118,7 @@ def rand_str(strlen=32, select_from=string.letters+string.digits): return("".join([random.choice(select_from) for _x in range(0, strlen)])) def rand_user_password(pwlen=9): - selfrom = (string.letters.translate(None,'loLOI') + - string.digits.translate(None,'01')) - return(rand_str(pwlen,select_from=selfrom)) + selfrom = (string.letters.translate(None, 'loLOI') + + string.digits.translate(None, '01')) + return(rand_str(pwlen, select_from=selfrom)) diff --git a/cloudinit/CloudConfig/cc_ssh.py b/cloudinit/CloudConfig/cc_ssh.py index 6031a436..9751bba5 100644 --- a/cloudinit/CloudConfig/cc_ssh.py +++ b/cloudinit/CloudConfig/cc_ssh.py @@ -26,7 +26,7 @@ DISABLE_ROOT_OPTS = "no-port-forwarding,no-agent-forwarding,no-X11-forwarding,co global_log = None -def handle(_name,cfg,cloud,log,_args): +def handle(_name, cfg, cloud, log, _args): global global_log global_log = log @@ -49,15 +49,15 @@ def handle(_name,cfg,cloud,log,_args): "ecdsa_public" : ("/etc/ssh/ssh_host_ecdsa_key.pub", 0644), } - for key,val in cfg["ssh_keys"].items(): + for key, val in cfg["ssh_keys"].items(): if key2file.has_key(key): - util.write_file(key2file[key][0],val,key2file[key][1]) + util.write_file(key2file[key][0], val, key2file[key][1]) priv2pub = { 'rsa_private':'rsa_public', 'dsa_private':'dsa_public', 'ecdsa_private': 'ecdsa_public', } cmd = 'o=$(ssh-keygen -yf "%s") && echo "$o" root@localhost > "%s"' - for priv,pub in priv2pub.iteritems(): + for priv, pub in priv2pub.iteritems(): if pub in cfg['ssh_keys'] or not priv in cfg['ssh_keys']: continue pair = (key2file[priv][0], key2file[pub][0]) @@ -75,7 +75,7 @@ def handle(_name,cfg,cloud,log,_args): util.restorecon_if_possible('/etc/ssh', recursive=True) try: - user = util.get_cfg_option_str(cfg,'user') + user = util.get_cfg_option_str(cfg, 'user') disable_root = util.get_cfg_option_bool(cfg, "disable_root", True) disable_root_opts = util.get_cfg_option_str(cfg, "disable_root_opts", DISABLE_ROOT_OPTS) @@ -85,7 +85,7 @@ def handle(_name,cfg,cloud,log,_args): cfgkeys = cfg["ssh_authorized_keys"] keys.extend(cfgkeys) - apply_credentials(keys,user,disable_root, disable_root_opts) + apply_credentials(keys, user, disable_root, disable_root_opts) except: util.logexc(log) log.warn("applying credentials failed!\n") diff --git a/cloudinit/CloudConfig/cc_ssh_import_id.py b/cloudinit/CloudConfig/cc_ssh_import_id.py index e4588eaf..efcd4296 100644 --- a/cloudinit/CloudConfig/cc_ssh_import_id.py +++ b/cloudinit/CloudConfig/cc_ssh_import_id.py @@ -19,15 +19,15 @@ import cloudinit.util as util import subprocess import traceback -def handle(_name,cfg,_cloud,log,args): +def handle(_name, cfg, _cloud, log, args): if len(args) != 0: user = args[0] ids = [ ] if len(args) > 1: ids = args[1:] else: - user = util.get_cfg_option_str(cfg,"user","ubuntu") - ids = util.get_cfg_option_list_or_str(cfg,"ssh_import_id",[]) + 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 diff --git a/cloudinit/CloudConfig/cc_timezone.py b/cloudinit/CloudConfig/cc_timezone.py index e7c855d6..87855503 100644 --- a/cloudinit/CloudConfig/cc_timezone.py +++ b/cloudinit/CloudConfig/cc_timezone.py @@ -24,11 +24,11 @@ import shutil frequency = per_instance tz_base = "/usr/share/zoneinfo" -def handle(_name,cfg,_cloud,log,args): +def handle(_name, cfg, _cloud, log, args): if len(args) != 0: timezone = args[0] else: - timezone = util.get_cfg_option_str(cfg,"timezone",False) + timezone = util.get_cfg_option_str(cfg, "timezone", False) if not timezone: return @@ -40,7 +40,7 @@ def handle(_name,cfg,_cloud,log,args): raise Exception("Invalid timezone %s" % tz_file) try: - fp = open("/etc/timezone","wb") + fp = open("/etc/timezone", "wb") fp.write("%s\n" % timezone) fp.close() except: diff --git a/cloudinit/CloudConfig/cc_update_etc_hosts.py b/cloudinit/CloudConfig/cc_update_etc_hosts.py index 1c245e67..66f0537c 100644 --- a/cloudinit/CloudConfig/cc_update_etc_hosts.py +++ b/cloudinit/CloudConfig/cc_update_etc_hosts.py @@ -21,10 +21,10 @@ import StringIO frequency = per_always -def handle(_name,cfg,cloud,log,_args): +def handle(_name, cfg, cloud, log, _args): ( hostname, fqdn ) = util.get_hostname_fqdn(cfg, cloud) - manage_hosts = util.get_cfg_option_bool(cfg,"manage_etc_hosts", False) + manage_hosts = util.get_cfg_option_bool(cfg, "manage_etc_hosts", False) if manage_hosts in ("True", "true", True, "template"): # render from template file try: @@ -76,7 +76,7 @@ def update_etc_hosts(hostname, fqdn, _log): new_etchosts.write("%s%s" % (header, hosts_line)) need_write = True if need_write == True: - new_etcfile = open ('/etc/hosts','wb') + new_etcfile = open('/etc/hosts', 'wb') new_etcfile.write(new_etchosts.getvalue()) new_etcfile.close() new_etchosts.close() diff --git a/cloudinit/CloudConfig/cc_update_hostname.py b/cloudinit/CloudConfig/cc_update_hostname.py index 9d09bbb8..893c99e0 100644 --- a/cloudinit/CloudConfig/cc_update_hostname.py +++ b/cloudinit/CloudConfig/cc_update_hostname.py @@ -22,14 +22,14 @@ from cloudinit.CloudConfig import per_always frequency = per_always -def handle(_name,cfg,cloud,log,_args): - if util.get_cfg_option_bool(cfg,"preserve_hostname",False): +def handle(_name, cfg, cloud, log, _args): + if util.get_cfg_option_bool(cfg, "preserve_hostname", False): log.debug("preserve_hostname is set. not updating hostname") return ( hostname, _fqdn ) = util.get_hostname_fqdn(cfg, cloud) try: - prev ="%s/%s" % (cloud.get_cpath('data'),"previous-hostname") + prev ="%s/%s" % (cloud.get_cpath('data'), "previous-hostname") update_hostname(hostname, prev, log) except Exception: log.warn("failed to set hostname\n") @@ -40,7 +40,7 @@ def handle(_name,cfg,cloud,log,_args): # if file doesn't exist, or no contents, return default def read_hostname(filename, default=None): try: - fp = open(filename,"r") + fp = open(filename, "r") lines = fp.readlines() fp.close() for line in lines: @@ -81,14 +81,14 @@ def update_hostname(hostname, prev_file, log): try: for fname in update_files: - util.write_file(fname,"%s\n" % hostname, 0644) - log.debug("wrote %s to %s" % (hostname,fname)) + util.write_file(fname, "%s\n" % hostname, 0644) + log.debug("wrote %s to %s" % (hostname, fname)) except: log.warn("failed to write hostname to %s" % fname) if hostname_in_etc and hostname_prev and hostname_in_etc != hostname_prev: log.debug("%s differs from %s. assuming user maintained" % - (prev_file,etc_file)) + (prev_file, etc_file)) if etc_file in update_files: log.debug("setting hostname to %s" % hostname) |