summaryrefslogtreecommitdiff
path: root/cloudinit/CloudConfig
diff options
context:
space:
mode:
authorMike Milner <mike.milner@canonical.com>2012-01-17 13:39:37 -0400
committerMike Milner <mike.milner@canonical.com>2012-01-17 13:39:37 -0400
commit69d6195ec6a37dc7a8f045fc262c74d01624eb56 (patch)
tree303ed83b05fdac41604ff3ad7c83c8c8046462eb /cloudinit/CloudConfig
parentf52ffe2dda01dd0314523fcac559e6f3fbb3578e (diff)
parent1d00c0936bfc63117493d89268da8c81611b3c40 (diff)
downloadvyos-cloud-init-69d6195ec6a37dc7a8f045fc262c74d01624eb56.tar.gz
vyos-cloud-init-69d6195ec6a37dc7a8f045fc262c74d01624eb56.zip
Merge from trunk.
Diffstat (limited to 'cloudinit/CloudConfig')
-rw-r--r--cloudinit/CloudConfig/__init__.py6
-rw-r--r--cloudinit/CloudConfig/cc_apt_update_upgrade.py39
-rw-r--r--cloudinit/CloudConfig/cc_bootcmd.py2
-rw-r--r--cloudinit/CloudConfig/cc_byobu.py2
-rw-r--r--cloudinit/CloudConfig/cc_chef.py12
-rw-r--r--cloudinit/CloudConfig/cc_disable_ec2_metadata.py2
-rw-r--r--cloudinit/CloudConfig/cc_final_message.py2
-rw-r--r--cloudinit/CloudConfig/cc_foo.py10
-rw-r--r--cloudinit/CloudConfig/cc_grub_dpkg.py4
-rw-r--r--cloudinit/CloudConfig/cc_keys_to_console.py2
-rw-r--r--cloudinit/CloudConfig/cc_landscape.py2
-rw-r--r--cloudinit/CloudConfig/cc_locale.py2
-rw-r--r--cloudinit/CloudConfig/cc_mcollective.py6
-rw-r--r--cloudinit/CloudConfig/cc_mounts.py4
-rw-r--r--cloudinit/CloudConfig/cc_phone_home.py3
-rw-r--r--cloudinit/CloudConfig/cc_puppet.py2
-rw-r--r--cloudinit/CloudConfig/cc_resizefs.py14
-rw-r--r--cloudinit/CloudConfig/cc_rightscale_userdata.py8
-rw-r--r--cloudinit/CloudConfig/cc_rsyslog.py8
-rw-r--r--cloudinit/CloudConfig/cc_runcmd.py4
-rw-r--r--cloudinit/CloudConfig/cc_scripts_per_boot.py7
-rw-r--r--cloudinit/CloudConfig/cc_scripts_per_instance.py7
-rw-r--r--cloudinit/CloudConfig/cc_scripts_per_once.py7
-rw-r--r--cloudinit/CloudConfig/cc_scripts_user.py7
-rw-r--r--cloudinit/CloudConfig/cc_set_hostname.py8
-rw-r--r--cloudinit/CloudConfig/cc_set_passwords.py6
-rw-r--r--cloudinit/CloudConfig/cc_ssh.py2
-rw-r--r--cloudinit/CloudConfig/cc_ssh_import_id.py2
-rw-r--r--cloudinit/CloudConfig/cc_timezone.py4
-rw-r--r--cloudinit/CloudConfig/cc_update_etc_hosts.py64
-rw-r--r--cloudinit/CloudConfig/cc_update_hostname.py6
31 files changed, 128 insertions, 126 deletions
diff --git a/cloudinit/CloudConfig/__init__.py b/cloudinit/CloudConfig/__init__.py
index 82f422fc..f5c4143c 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=[]):
+ def __init__(self,cfgfile, cloud=None, ds_deps=None):
if cloud == None:
self.cloud = cloudinit.CloudInit(ds_deps)
self.cloud.get_data_source()
@@ -233,7 +233,9 @@ 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=[]):
+def apt_get(tlc,args=None):
+ if args is None:
+ args = []
e=os.environ.copy()
e['DEBIAN_FRONTEND']='noninteractive'
cmd=[ 'apt-get',
diff --git a/cloudinit/CloudConfig/cc_apt_update_upgrade.py b/cloudinit/CloudConfig/cc_apt_update_upgrade.py
index a60512e1..0cbe02d4 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)
@@ -102,14 +102,14 @@ def handle(name,cfg,cloud,log,args):
return(True)
def mirror2lists_fileprefix(mirror):
- file=mirror
+ string=mirror
# take of http:// or ftp://
- if file.endswith("/"): file=file[0:-1]
- pos=file.find("://")
+ if string.endswith("/"): string=string[0:-1]
+ pos=string.find("://")
if pos >= 0:
- file=file[pos+3:]
- file=file.replace("/","_")
- return file
+ string=string[pos+3:]
+ string=string.replace("/","_")
+ return string
def rename_apt_lists(omirror,new_mirror,lists_d="/var/lib/apt/lists"):
@@ -117,11 +117,11 @@ def rename_apt_lists(omirror,new_mirror,lists_d="/var/lib/apt/lists"):
nprefix="%s/%s" % (lists_d,mirror2lists_fileprefix(new_mirror))
if(oprefix==nprefix): return
olen=len(oprefix)
- for file in glob.glob("%s_*" % oprefix):
- os.rename(file,"%s%s" % (nprefix, file[olen:]))
+ for filename in glob.glob("%s_*" % oprefix):
+ os.rename(filename,"%s%s" % (nprefix, filename[olen:]))
def get_release():
- stdout, stderr = subprocess.Popen(['lsb_release', '-cs'], stdout=subprocess.PIPE).communicate()
+ stdout, _stderr = subprocess.Popen(['lsb_release', '-cs'], stdout=subprocess.PIPE).communicate()
return(stdout.strip())
def generate_sources_list(codename, mirror):
@@ -131,7 +131,9 @@ def generate_sources_list(codename, mirror):
# srclist is a list of dictionaries,
# each entry must have: 'source'
# may have: key, ( keyid and keyserver)
-def add_sources(srclist, searchList={ }):
+def add_sources(srclist, searchList=None):
+ if searchList is None:
+ searchList = {}
elst = []
for ent in srclist:
@@ -202,19 +204,20 @@ def find_apt_mirror(cloud, cfg):
if not mirror and cloud:
# if we have a fqdn, then search its domain portion first
- ( hostname, fqdn ) = util.get_hostname_fqdn(cfg, cloud)
+ ( _hostname, fqdn ) = util.get_hostname_fqdn(cfg, cloud)
mydom = ".".join(fqdn.split(".")[1:])
if mydom:
doms.append(".%s" % mydom)
- doms.extend((".localdomain", "",))
+ if not mirror:
+ doms.extend((".localdomain", "",))
- mirror_list = []
- mirrorfmt = "http://%s-mirror%s/%s" % (distro, "%s", distro )
- for post in doms:
- mirror_list.append(mirrorfmt % post)
+ mirror_list = []
+ mirrorfmt = "http://%s-mirror%s/%s" % (distro, "%s", distro )
+ for post in doms:
+ mirror_list.append(mirrorfmt % post)
- mirror = util.search_for_mirror(mirror_list)
+ mirror = util.search_for_mirror(mirror_list)
if not mirror:
mirror = defaults[distro]
diff --git a/cloudinit/CloudConfig/cc_bootcmd.py b/cloudinit/CloudConfig/cc_bootcmd.py
index 5a9e4356..fc925447 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 406a1f67..dd510dda 100644
--- a/cloudinit/CloudConfig/cc_byobu.py
+++ b/cloudinit/CloudConfig/cc_byobu.py
@@ -19,7 +19,7 @@ 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:
diff --git a/cloudinit/CloudConfig/cc_chef.py b/cloudinit/CloudConfig/cc_chef.py
index 14960a3c..977fe80f 100644
--- a/cloudinit/CloudConfig/cc_chef.py
+++ b/cloudinit/CloudConfig/cc_chef.py
@@ -14,19 +14,16 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
import os
-import pwd
-import socket
import subprocess
import json
-import StringIO
-import ConfigParser
import cloudinit.CloudConfig as cc
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
chef_cfg = cfg['chef']
@@ -44,7 +41,6 @@ def handle(name,cfg,cloud,log,args):
with open('/etc/chef/validation.pem', 'w') as validation_key_fh:
validation_key_fh.write(validation_key)
- validation_name = chef_cfg.get('validation_name','chef-validator')
# create the chef config from template
util.render_to_file('chef_client.rb', '/etc/chef/client.rb',
{'server_url': chef_cfg['server_url'],
@@ -90,9 +86,9 @@ def get_ruby_packages(version):
def install_chef_from_gems(ruby_version, chef_version = None):
cc.install_packages(get_ruby_packages(ruby_version))
if not os.path.exists('/usr/bin/gem'):
- os.symlink('/usr/bin/gem%s' % ruby_version, '/usr/bin/gem')
+ os.symlink('/usr/bin/gem%s' % ruby_version, '/usr/bin/gem')
if not os.path.exists('/usr/bin/ruby'):
- os.symlink('/usr/bin/ruby%s' % ruby_version, '/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',
'-v %s' % chef_version, '--no-ri',
diff --git a/cloudinit/CloudConfig/cc_disable_ec2_metadata.py b/cloudinit/CloudConfig/cc_disable_ec2_metadata.py
index 5cd1d1c1..f06d4dfc 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 fbdb5c94..c8631d01 100644
--- a/cloudinit/CloudConfig/cc_final_message.py
+++ b/cloudinit/CloudConfig/cc_final_message.py
@@ -24,7 +24,7 @@ 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:
diff --git a/cloudinit/CloudConfig/cc_foo.py b/cloudinit/CloudConfig/cc_foo.py
index aa95578f..48d20e5b 100644
--- a/cloudinit/CloudConfig/cc_foo.py
+++ b/cloudinit/CloudConfig/cc_foo.py
@@ -15,10 +15,12 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-import cloudinit
-import cloudinit.util as util
+
+#import cloudinit
+#import cloudinit.util as util
from cloudinit.CloudConfig import per_instance
frequency = per_instance
-def handle(name,cfg,cloud,log,args):
- print "hi"
+
+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 b26e90e8..97d79bdb 100644
--- a/cloudinit/CloudConfig/cc_grub_dpkg.py
+++ b/cloudinit/CloudConfig/cc_grub_dpkg.py
@@ -15,12 +15,12 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
import cloudinit.util as util
-import subprocess
import traceback
import os
-def handle(name,cfg,cloud,log,args):
+def handle(_name,cfg,_cloud,log,_args):
idevs=None
idevs_empty=None
diff --git a/cloudinit/CloudConfig/cc_keys_to_console.py b/cloudinit/CloudConfig/cc_keys_to_console.py
index 79dd2ea9..08e8f085 100644
--- a/cloudinit/CloudConfig/cc_keys_to_console.py
+++ b/cloudinit/CloudConfig/cc_keys_to_console.py
@@ -21,7 +21,7 @@ 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"])
diff --git a/cloudinit/CloudConfig/cc_landscape.py b/cloudinit/CloudConfig/cc_landscape.py
index e3e4f7ba..22a90665 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 8542f641..8e91d3bf 100644
--- a/cloudinit/CloudConfig/cc_locale.py
+++ b/cloudinit/CloudConfig/cc_locale.py
@@ -28,7 +28,7 @@ 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:
diff --git a/cloudinit/CloudConfig/cc_mcollective.py b/cloudinit/CloudConfig/cc_mcollective.py
index c7912aa4..38fe4a3c 100644
--- a/cloudinit/CloudConfig/cc_mcollective.py
+++ b/cloudinit/CloudConfig/cc_mcollective.py
@@ -16,11 +16,9 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
import os
-import pwd
-import socket
import subprocess
-import fileinput
import StringIO
import ConfigParser
import cloudinit.CloudConfig as cc
@@ -40,7 +38,7 @@ class FakeSecHead(object):
finally: self.sechead = None
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
mcollective_cfg = cfg['mcollective']
diff --git a/cloudinit/CloudConfig/cc_mounts.py b/cloudinit/CloudConfig/cc_mounts.py
index db382f04..a3036d5a 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)
@@ -116,7 +116,7 @@ def handle(name,cfg,cloud,log,args):
# now, each entry in the cfgmnt list has all fstab values
# if the second field is None (not the string, the value) we skip it
- actlist = filter(lambda x: x[1] is not None, cfgmnt)
+ actlist = [x for x in cfgmnt if x[1] is not None]
if len(actlist) == 0: return
diff --git a/cloudinit/CloudConfig/cc_phone_home.py b/cloudinit/CloudConfig/cc_phone_home.py
index f291e1d4..7897d31b 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:
@@ -68,7 +68,6 @@ def handle(name,cfg,cloud,log,args):
try:
fp = open(path, "rb")
all_keys[n] = fp.read()
- all_keys[n]
fp.close()
except:
log.warn("%s: failed to open in phone_home" % path)
diff --git a/cloudinit/CloudConfig/cc_puppet.py b/cloudinit/CloudConfig/cc_puppet.py
index c635d1f5..3748559a 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
puppet_cfg = cfg['puppet']
diff --git a/cloudinit/CloudConfig/cc_resizefs.py b/cloudinit/CloudConfig/cc_resizefs.py
index 6615636f..adec70be 100644
--- a/cloudinit/CloudConfig/cc_resizefs.py
+++ b/cloudinit/CloudConfig/cc_resizefs.py
@@ -15,9 +15,9 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
import cloudinit.util as util
import subprocess
-import traceback
import os
import stat
import tempfile
@@ -25,7 +25,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 len(args) != 0:
resize_root = False
if str(args[0]).lower() in [ 'true', '1', 'on', 'yes']:
@@ -41,9 +41,9 @@ def handle(name,cfg,cloud,log,args):
os.close(fd)
try:
- st_dev=os.stat("/").st_dev
- dev=os.makedev(os.major(st_dev),os.minor(st_dev))
- os.mknod(devpth, 0400 | stat.S_IFBLK, dev)
+ st_dev=os.stat("/").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():
log.debug("inside lxc, ignoring mknod failure in resizefs")
@@ -53,7 +53,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))
@@ -74,7 +74,7 @@ def handle(name,cfg,cloud,log,args):
return
try:
- (out,err) = util.subp(resize_cmd)
+ util.subp(resize_cmd)
except subprocess.CalledProcessError as e:
log.warn("Failed to resize filesystem (%s)" % resize_cmd)
log.warn("output=%s\nerror=%s\n", e.output[0], e.output[1])
diff --git a/cloudinit/CloudConfig/cc_rightscale_userdata.py b/cloudinit/CloudConfig/cc_rightscale_userdata.py
index 4875acbe..2b43023c 100644
--- a/cloudinit/CloudConfig/cc_rightscale_userdata.py
+++ b/cloudinit/CloudConfig/cc_rightscale_userdata.py
@@ -32,8 +32,9 @@
## Therefore, this must run before that.
##
##
+
import cloudinit.util as util
-from cloudinit.CloudConfig import per_once, per_always, per_instance
+from cloudinit.CloudConfig import per_instance
from cloudinit import get_ipath_cur
from urlparse import parse_qs
@@ -41,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:
@@ -49,7 +50,7 @@ def handle(name,cfg,cloud,log,args):
return
try:
- mdict = parse_qs(cloud.get_userdata_raw())
+ mdict = parse_qs(ud)
if not my_hookname in mdict: return
except:
log.warn("failed to urlparse.parse_qa(userdata_raw())")
@@ -57,7 +58,6 @@ def handle(name,cfg,cloud,log,args):
scripts_d = get_ipath_cur('scripts')
i = 0
- errors = [ ]
first_e = None
for url in mdict[my_hookname]:
fname = "%s/rightscale-%02i" % (scripts_d,i)
diff --git a/cloudinit/CloudConfig/cc_rsyslog.py b/cloudinit/CloudConfig/cc_rsyslog.py
index a8ee8476..ab85a6d8 100644
--- a/cloudinit/CloudConfig/cc_rsyslog.py
+++ b/cloudinit/CloudConfig/cc_rsyslog.py
@@ -15,16 +15,16 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
import cloudinit
import logging
import cloudinit.util as util
-import subprocess
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"
@@ -38,8 +38,6 @@ def handle(name,cfg,cloud,log,args):
def_dir = cfg.get('rsyslog_dir', DEF_DIR)
def_fname = cfg.get('rsyslog_filename', DEF_FILENAME)
- entries = cfg['rsyslog']
-
files = [ ]
elst = [ ]
for ent in cfg['rsyslog']:
@@ -80,7 +78,7 @@ def handle(name,cfg,cloud,log,args):
# it will also return failure on the attempt, so 'restarted'
# won't get set
log.debug("restarting rsyslog")
- p = util.subp(['service', 'rsyslog', 'restart'])
+ util.subp(['service', 'rsyslog', 'restart'])
restarted = True
except Exception as e:
diff --git a/cloudinit/CloudConfig/cc_runcmd.py b/cloudinit/CloudConfig/cc_runcmd.py
index f030980a..d255223b 100644
--- a/cloudinit/CloudConfig/cc_runcmd.py
+++ b/cloudinit/CloudConfig/cc_runcmd.py
@@ -15,10 +15,10 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-import cloudinit
+
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')
diff --git a/cloudinit/CloudConfig/cc_scripts_per_boot.py b/cloudinit/CloudConfig/cc_scripts_per_boot.py
index 4e407fb7..fb643c6d 100644
--- a/cloudinit/CloudConfig/cc_scripts_per_boot.py
+++ b/cloudinit/CloudConfig/cc_scripts_per_boot.py
@@ -15,14 +15,15 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
import cloudinit.util as util
-from cloudinit.CloudConfig import per_once, per_always, per_instance
-from cloudinit import get_cpath, get_ipath_cur
+from cloudinit.CloudConfig import per_always
+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 22b41185..b0f0601a 100644
--- a/cloudinit/CloudConfig/cc_scripts_per_instance.py
+++ b/cloudinit/CloudConfig/cc_scripts_per_instance.py
@@ -15,14 +15,15 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
import cloudinit.util as util
-from cloudinit.CloudConfig import per_once, per_always, per_instance
-from cloudinit import get_cpath, get_ipath_cur
+from cloudinit.CloudConfig import per_instance
+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 9d752325..2ab81840 100644
--- a/cloudinit/CloudConfig/cc_scripts_per_once.py
+++ b/cloudinit/CloudConfig/cc_scripts_per_once.py
@@ -15,14 +15,15 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
import cloudinit.util as util
-from cloudinit.CloudConfig import per_once, per_always, per_instance
-from cloudinit import get_cpath, get_ipath_cur
+from cloudinit.CloudConfig import per_once
+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 bafecd23..9c7f2322 100644
--- a/cloudinit/CloudConfig/cc_scripts_user.py
+++ b/cloudinit/CloudConfig/cc_scripts_user.py
@@ -15,14 +15,15 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
import cloudinit.util as util
-from cloudinit.CloudConfig import per_once, per_always, per_instance
-from cloudinit import get_cpath, get_ipath_cur
+from cloudinit.CloudConfig import per_instance
+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 bc190049..4f19b0c8 100644
--- a/cloudinit/CloudConfig/cc_set_hostname.py
+++ b/cloudinit/CloudConfig/cc_set_hostname.py
@@ -15,18 +15,18 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
import cloudinit.util as util
-import subprocess
-def handle(name,cfg,cloud,log,args):
+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)
- ( hostname, fqdn ) = util.get_hostname_fqdn(cfg, cloud)
+ ( hostname, _fqdn ) = util.get_hostname_fqdn(cfg, cloud)
try:
set_hostname(hostname, log)
- except Exception as e:
+ except Exception:
util.logexc(log)
log.warn("failed to set hostname to %s\n", hostname)
diff --git a/cloudinit/CloudConfig/cc_set_passwords.py b/cloudinit/CloudConfig/cc_set_passwords.py
index edfbaeeb..07e3ca1b 100644
--- a/cloudinit/CloudConfig/cc_set_passwords.py
+++ b/cloudinit/CloudConfig/cc_set_passwords.py
@@ -15,13 +15,13 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
import cloudinit.util as util
-import subprocess
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]
@@ -115,7 +115,7 @@ def handle(name,cfg,cloud,log,args):
return
def rand_str(strlen=32, select_from=string.letters+string.digits):
- return("".join([random.choice(select_from) for x in range(0, strlen)]))
+ return("".join([random.choice(select_from) for _x in range(0, strlen)]))
def rand_user_password(pwlen=9):
selfrom=(string.letters.translate(None,'loLOI') +
diff --git a/cloudinit/CloudConfig/cc_ssh.py b/cloudinit/CloudConfig/cc_ssh.py
index 9f5dc567..0aad2187 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,comm
global_log = None
-def handle(name,cfg,cloud,log,args):
+def handle(_name,cfg,cloud,log,_args):
global global_log
global_log = log
diff --git a/cloudinit/CloudConfig/cc_ssh_import_id.py b/cloudinit/CloudConfig/cc_ssh_import_id.py
index bf1314be..7e7a54a1 100644
--- a/cloudinit/CloudConfig/cc_ssh_import_id.py
+++ b/cloudinit/CloudConfig/cc_ssh_import_id.py
@@ -19,7 +19,7 @@ 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 = [ ]
diff --git a/cloudinit/CloudConfig/cc_timezone.py b/cloudinit/CloudConfig/cc_timezone.py
index e8a453f9..26b2796d 100644
--- a/cloudinit/CloudConfig/cc_timezone.py
+++ b/cloudinit/CloudConfig/cc_timezone.py
@@ -15,16 +15,16 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
from cloudinit.CloudConfig import per_instance
from cloudinit import util
-import subprocess
import os.path
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:
diff --git a/cloudinit/CloudConfig/cc_update_etc_hosts.py b/cloudinit/CloudConfig/cc_update_etc_hosts.py
index 1dc9c1e9..1c245e67 100644
--- a/cloudinit/CloudConfig/cc_update_etc_hosts.py
+++ b/cloudinit/CloudConfig/cc_update_etc_hosts.py
@@ -21,7 +21,7 @@ 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)
@@ -34,7 +34,7 @@ def handle(name,cfg,cloud,log,args):
util.render_to_file('hosts', '/etc/hosts', \
{ 'hostname' : hostname, 'fqdn' : fqdn })
- except Exception as e:
+ except Exception:
log.warn("failed to update /etc/hosts")
raise
elif manage_hosts == "localhost":
@@ -48,37 +48,37 @@ def handle(name,cfg,cloud,log,args):
log.debug("not managing /etc/hosts")
-def update_etc_hosts(hostname, fqdn, log):
- with open('/etc/hosts', 'r') as etchosts:
- header = "# Added by cloud-init\n"
- hosts_line = "127.0.1.1\t%s %s\n" % (fqdn, hostname)
- need_write = False
- need_change = True
- new_etchosts = StringIO.StringIO()
- for line in etchosts:
- split_line = [s.strip() for s in line.split()]
- if len(split_line) < 2:
+def update_etc_hosts(hostname, fqdn, _log):
+ with open('/etc/hosts', 'r') as etchosts:
+ header = "# Added by cloud-init\n"
+ hosts_line = "127.0.1.1\t%s %s\n" % (fqdn, hostname)
+ need_write = False
+ need_change = True
+ new_etchosts = StringIO.StringIO()
+ for line in etchosts:
+ split_line = [s.strip() for s in line.split()]
+ if len(split_line) < 2:
new_etchosts.write(line)
continue
- if line == header:
+ if line == header:
continue
- ip, hosts = split_line[0], split_line[1:]
- if ip == "127.0.1.1":
- if sorted([hostname, fqdn]) == sorted(hosts):
- need_change = False
- if need_change == True:
- line = "%s%s" % (header, hosts_line)
- need_change = False
- need_write = True
- new_etchosts.write(line)
- etchosts.close()
- if need_change == True:
- new_etchosts.write("%s%s" % (header, hosts_line))
- need_write = True
- if need_write == True:
- new_etcfile = open ('/etc/hosts','wb')
- new_etcfile.write(new_etchosts.getvalue())
- new_etcfile.close()
- new_etchosts.close()
- return
+ ip, hosts = split_line[0], split_line[1:]
+ if ip == "127.0.1.1":
+ if sorted([hostname, fqdn]) == sorted(hosts):
+ need_change = False
+ if need_change == True:
+ line = "%s%s" % (header, hosts_line)
+ need_change = False
+ need_write = True
+ new_etchosts.write(line)
+ etchosts.close()
+ if need_change == True:
+ new_etchosts.write("%s%s" % (header, hosts_line))
+ need_write = True
+ if need_write == True:
+ new_etcfile = open ('/etc/hosts','wb')
+ new_etcfile.write(new_etchosts.getvalue())
+ new_etcfile.close()
+ new_etchosts.close()
+ return
diff --git a/cloudinit/CloudConfig/cc_update_hostname.py b/cloudinit/CloudConfig/cc_update_hostname.py
index 3f55c73b..4bc1cb2b 100644
--- a/cloudinit/CloudConfig/cc_update_hostname.py
+++ b/cloudinit/CloudConfig/cc_update_hostname.py
@@ -22,16 +22,16 @@ 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,"preserve_hostname",False):
log.debug("preserve_hostname is set. not updating hostname")
return
- ( hostname, fqdn ) = util.get_hostname_fqdn(cfg, cloud)
+ ( hostname, _fqdn ) = util.get_hostname_fqdn(cfg, cloud)
try:
prev ="%s/%s" % (cloud.get_cpath('data'),"previous-hostname")
update_hostname(hostname, prev, log)
- except Exception as e:
+ except Exception:
log.warn("failed to set hostname\n")
raise