summaryrefslogtreecommitdiff
path: root/cloudinit/config
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit/config')
-rw-r--r--cloudinit/config/cc_apt_configure.py2
-rw-r--r--cloudinit/config/cc_byobu.py2
-rw-r--r--cloudinit/config/cc_chef.py3
-rw-r--r--cloudinit/config/cc_disk_setup.py6
-rw-r--r--cloudinit/config/cc_grub_dpkg.py3
-rw-r--r--cloudinit/config/cc_mounts.py2
-rw-r--r--cloudinit/config/cc_phone_home.py2
-rw-r--r--cloudinit/config/cc_power_state_change.py13
-rw-r--r--cloudinit/config/cc_resizefs.py30
-rw-r--r--cloudinit/config/cc_resolv_conf.py29
-rw-r--r--cloudinit/config/cc_rightscale_userdata.py34
-rw-r--r--cloudinit/config/cc_rsyslog.py4
-rw-r--r--cloudinit/config/cc_set_passwords.py4
-rw-r--r--cloudinit/config/cc_ssh.py2
-rw-r--r--cloudinit/config/cc_ssh_authkey_fingerprints.py5
-rw-r--r--cloudinit/config/cc_ssh_import_id.py2
-rw-r--r--cloudinit/config/cc_ubuntu_init_switch.py164
-rw-r--r--cloudinit/config/cc_yum_add_repo.py4
18 files changed, 248 insertions, 63 deletions
diff --git a/cloudinit/config/cc_apt_configure.py b/cloudinit/config/cc_apt_configure.py
index 29c13a3d..f10b76a3 100644
--- a/cloudinit/config/cc_apt_configure.py
+++ b/cloudinit/config/cc_apt_configure.py
@@ -235,7 +235,7 @@ def find_apt_mirror_info(cloud, cfg):
mirror = util.search_for_mirror(search)
if (not mirror and
- util.get_cfg_option_bool(cfg, "apt_mirror_search_dns", False)):
+ util.get_cfg_option_bool(cfg, "apt_mirror_search_dns", False)):
mydom = ""
doms = []
diff --git a/cloudinit/config/cc_byobu.py b/cloudinit/config/cc_byobu.py
index 92d428b7..ef0ce7ab 100644
--- a/cloudinit/config/cc_byobu.py
+++ b/cloudinit/config/cc_byobu.py
@@ -43,7 +43,7 @@ def handle(name, cfg, cloud, log, args):
valid = ("enable-user", "enable-system", "enable",
"disable-user", "disable-system", "disable")
- if not value in valid:
+ if value not in valid:
log.warn("Unknown value %s for byobu_by_default", value)
mod_user = value.endswith("-user")
diff --git a/cloudinit/config/cc_chef.py b/cloudinit/config/cc_chef.py
index 727769cd..806deed9 100644
--- a/cloudinit/config/cc_chef.py
+++ b/cloudinit/config/cc_chef.py
@@ -87,7 +87,8 @@ def handle(name, cfg, cloud, log, _args):
# If chef is not installed, we install chef based on 'install_type'
if (not os.path.isfile('/usr/bin/chef-client') or
- util.get_cfg_option_bool(chef_cfg, 'force_install', default=False)):
+ util.get_cfg_option_bool(chef_cfg,
+ 'force_install', default=False)):
install_type = util.get_cfg_option_str(chef_cfg, 'install_type',
'packages')
diff --git a/cloudinit/config/cc_disk_setup.py b/cloudinit/config/cc_disk_setup.py
index 0b970e4e..1660832b 100644
--- a/cloudinit/config/cc_disk_setup.py
+++ b/cloudinit/config/cc_disk_setup.py
@@ -271,7 +271,7 @@ def find_device_node(device, fs_type=None, label=None, valid_targets=None,
return ('/dev/%s' % d['name'], False)
if (d['fstype'] == fs_type and
- ((label_match and d['label'] == label) or not label_match)):
+ ((label_match and d['label'] == label) or not label_match)):
# If we find a matching device, we return that
return ('/dev/%s' % d['name'], True)
@@ -447,7 +447,7 @@ def get_partition_mbr_layout(size, layout):
return "0,"
if ((len(layout) == 0 and isinstance(layout, list)) or
- not isinstance(layout, list)):
+ not isinstance(layout, list)):
raise Exception("Partition layout is invalid")
last_part_num = len(layout)
@@ -484,7 +484,7 @@ def get_partition_mbr_layout(size, layout):
def purge_disk_ptable(device):
# wipe the first and last megabyte of a disk (or file)
# gpt stores partition table both at front and at end.
- null = '\0' # pylint: disable=W1401
+ null = '\0'
start_len = 1024 * 1024
end_len = 1024 * 1024
with open(device, "rb+") as fp:
diff --git a/cloudinit/config/cc_grub_dpkg.py b/cloudinit/config/cc_grub_dpkg.py
index d96e85cf..e3219e81 100644
--- a/cloudinit/config/cc_grub_dpkg.py
+++ b/cloudinit/config/cc_grub_dpkg.py
@@ -36,7 +36,8 @@ def handle(_name, cfg, _cloud, log, _args):
"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"))):
+ (os.path.exists("/dev/xvda1")
+ and not os.path.exists("/dev/xvda"))):
if idevs is None:
idevs = ""
if idevs_empty is None:
diff --git a/cloudinit/config/cc_mounts.py b/cloudinit/config/cc_mounts.py
index 80590118..ba1303d1 100644
--- a/cloudinit/config/cc_mounts.py
+++ b/cloudinit/config/cc_mounts.py
@@ -18,7 +18,7 @@
# 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 string import whitespace # pylint: disable=W0402
+from string import whitespace
import logging
import os.path
diff --git a/cloudinit/config/cc_phone_home.py b/cloudinit/config/cc_phone_home.py
index 2e058ccd..5bc68b83 100644
--- a/cloudinit/config/cc_phone_home.py
+++ b/cloudinit/config/cc_phone_home.py
@@ -47,7 +47,7 @@ def handle(name, cfg, cloud, log, args):
if len(args) != 0:
ph_cfg = util.read_conf(args[0])
else:
- if not 'phone_home' in cfg:
+ if 'phone_home' not in cfg:
log.debug(("Skipping module named %s, "
"no 'phone_home' configuration found"), name)
return
diff --git a/cloudinit/config/cc_power_state_change.py b/cloudinit/config/cc_power_state_change.py
index 8f99e887..09d37371 100644
--- a/cloudinit/config/cc_power_state_change.py
+++ b/cloudinit/config/cc_power_state_change.py
@@ -89,8 +89,9 @@ def load_power_state(cfg):
mode = pstate.get("mode")
if mode not in opt_map:
- raise TypeError("power_state[mode] required, must be one of: %s." %
- ','.join(opt_map.keys()))
+ raise TypeError(
+ "power_state[mode] required, must be one of: %s. found: '%s'." %
+ (','.join(opt_map.keys()), mode))
delay = pstate.get("delay", "now")
# convert integer 30 or string '30' to '+30'
@@ -100,7 +101,9 @@ def load_power_state(cfg):
pass
if delay != "now" and not re.match(r"\+[0-9]+", delay):
- raise TypeError("power_state[delay] must be 'now' or '+m' (minutes).")
+ raise TypeError(
+ "power_state[delay] must be 'now' or '+m' (minutes)."
+ " found '%s'." % delay)
args = ["shutdown", opt_map[mode], delay]
if pstate.get("message"):
@@ -116,7 +119,7 @@ def load_power_state(cfg):
def doexit(sysexit):
- os._exit(sysexit) # pylint: disable=W0212
+ os._exit(sysexit)
def execmd(exe_args, output=None, data_in=None):
@@ -124,7 +127,7 @@ def execmd(exe_args, output=None, data_in=None):
proc = subprocess.Popen(exe_args, stdin=subprocess.PIPE,
stdout=output, stderr=subprocess.STDOUT)
proc.communicate(data_in)
- ret = proc.returncode # pylint: disable=E1101
+ ret = proc.returncode
except Exception:
doexit(EXIT_FAIL)
doexit(ret)
diff --git a/cloudinit/config/cc_resizefs.py b/cloudinit/config/cc_resizefs.py
index be406034..cbc07853 100644
--- a/cloudinit/config/cc_resizefs.py
+++ b/cloudinit/config/cc_resizefs.py
@@ -28,19 +28,19 @@ from cloudinit import util
frequency = PER_ALWAYS
-def _resize_btrfs(mount_point, devpth): # pylint: disable=W0613
+def _resize_btrfs(mount_point, devpth):
return ('btrfs', 'filesystem', 'resize', 'max', mount_point)
-def _resize_ext(mount_point, devpth): # pylint: disable=W0613
+def _resize_ext(mount_point, devpth):
return ('resize2fs', devpth)
-def _resize_xfs(mount_point, devpth): # pylint: disable=W0613
+def _resize_xfs(mount_point, devpth):
return ('xfs_growfs', devpth)
-def _resize_ufs(mount_point, devpth): # pylint: disable=W0613
+def _resize_ufs(mount_point, devpth):
return ('growfs', devpth)
# Do not use a dictionary as these commands should be able to be used
@@ -98,14 +98,14 @@ def handle(name, cfg, _cloud, log, args):
(devpth, fs_type, mount_point) = result
- # Ensure the path is a block device.
info = "dev=%s mnt_point=%s path=%s" % (devpth, mount_point, resize_what)
log.debug("resize_info: %s" % info)
container = util.is_container()
+ # Ensure the path is a block device.
if (devpth == "/dev/root" and not os.path.exists(devpth) and
- not container):
+ not container):
devpth = rootdev_from_cmdline(util.get_cmdline())
if devpth is None:
log.warn("Unable to find device '/dev/root'")
@@ -117,14 +117,22 @@ def handle(name, cfg, _cloud, log, args):
except OSError as exc:
if container and exc.errno == errno.ENOENT:
log.debug("Device '%s' did not exist in container. "
- "cannot resize: %s" % (devpth, info))
+ "cannot resize: %s", devpth, info)
elif exc.errno == errno.ENOENT:
- log.warn("Device '%s' did not exist. cannot resize: %s" %
- (devpth, info))
+ log.warn("Device '%s' did not exist. cannot resize: %s",
+ devpth, info)
else:
raise exc
return
+ if not os.access(devpth, os.W_OK):
+ if container:
+ log.debug("'%s' not writable in container. cannot resize: %s",
+ devpth, info)
+ else:
+ log.warn("'%s' not writable. cannot resize: %s", devpth, info)
+ return
+
if not stat.S_ISBLK(statret.st_mode) and not stat.S_ISCHR(statret.st_mode):
if container:
log.debug("device '%s' not a block device in container."
@@ -154,8 +162,8 @@ def handle(name, cfg, _cloud, log, args):
# Fork to a child that will run
# the resize command
util.fork_cb(
- util.log_time(logfunc=log.debug, msg="backgrounded Resizing",
- func=do_resize, args=(resize_cmd, log)))
+ util.log_time, logfunc=log.debug, msg="backgrounded Resizing",
+ func=do_resize, args=(resize_cmd, log))
else:
util.log_time(logfunc=log.debug, msg="Resizing",
func=do_resize, args=(resize_cmd, log))
diff --git a/cloudinit/config/cc_resolv_conf.py b/cloudinit/config/cc_resolv_conf.py
index 879b62b1..bbaa6c63 100644
--- a/cloudinit/config/cc_resolv_conf.py
+++ b/cloudinit/config/cc_resolv_conf.py
@@ -49,23 +49,22 @@
#
+from cloudinit import log as logging
from cloudinit.settings import PER_INSTANCE
from cloudinit import templater
from cloudinit import util
+LOG = logging.getLogger(__name__)
+
frequency = PER_INSTANCE
distros = ['fedora', 'rhel', 'sles']
-def generate_resolv_conf(cloud, log, params):
- template_fn = cloud.get_template_filename('resolv.conf')
- if not template_fn:
- log.warn("No template found, not rendering /etc/resolv.conf")
- return
-
+def generate_resolv_conf(template_fn, params, target_fname="/etc/resolv.conf"):
flags = []
false_flags = []
+
if 'options' in params:
for key, val in params['options'].iteritems():
if type(val) == bool:
@@ -77,12 +76,15 @@ def generate_resolv_conf(cloud, log, params):
for flag in flags + false_flags:
del params['options'][flag]
+ if not params.get('options'):
+ params['options'] = {}
+
params['flags'] = flags
- log.debug("Writing resolv.conf from template %s" % template_fn)
- templater.render_to_file(template_fn, '/etc/resolv.conf', params)
+ LOG.debug("Writing resolv.conf from template %s" % template_fn)
+ templater.render_to_file(template_fn, target_fname, params)
-def handle(name, cfg, _cloud, log, _args):
+def handle(name, cfg, cloud, log, _args):
"""
Handler for resolv.conf
@@ -102,8 +104,13 @@ def handle(name, cfg, _cloud, log, _args):
" 'manage_resolv_conf' present but set to False"), name)
return
- if not "resolv_conf" in cfg:
+ if "resolv_conf" not in cfg:
log.warn("manage_resolv_conf True but no parameters provided!")
- generate_resolv_conf(_cloud, log, cfg["resolv_conf"])
+ template_fn = cloud.get_template_filename('resolv.conf')
+ if not template_fn:
+ log.warn("No template found, not rendering /etc/resolv.conf")
+ return
+
+ generate_resolv_conf(template_fn=template_fn, params=cfg["resolv_conf"])
return
diff --git a/cloudinit/config/cc_rightscale_userdata.py b/cloudinit/config/cc_rightscale_userdata.py
index c771728d..7d2ec10a 100644
--- a/cloudinit/config/cc_rightscale_userdata.py
+++ b/cloudinit/config/cc_rightscale_userdata.py
@@ -18,22 +18,22 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-##
-## The purpose of this script is to allow cloud-init to consume
-## rightscale style userdata. rightscale user data is key-value pairs
-## in a url-query-string like format.
-##
-## for cloud-init support, there will be a key named
-## 'CLOUD_INIT_REMOTE_HOOK'.
-##
-## This cloud-config module will
-## - read the blob of data from raw user data, and parse it as key/value
-## - for each key that is found, download the content to
-## the local instance/scripts directory and set them executable.
-## - the files in that directory will be run by the user-scripts module
-## Therefore, this must run before that.
-##
-##
+#
+# The purpose of this script is to allow cloud-init to consume
+# rightscale style userdata. rightscale user data is key-value pairs
+# in a url-query-string like format.
+#
+# for cloud-init support, there will be a key named
+# 'CLOUD_INIT_REMOTE_HOOK'.
+#
+# This cloud-config module will
+# - read the blob of data from raw user data, and parse it as key/value
+# - for each key that is found, download the content to
+# the local instance/scripts directory and set them executable.
+# - the files in that directory will be run by the user-scripts module
+# Therefore, this must run before that.
+#
+#
import os
@@ -58,7 +58,7 @@ def handle(name, _cfg, cloud, log, _args):
try:
mdict = parse_qs(ud)
- if not mdict or not MY_HOOKNAME in mdict:
+ if mdict or MY_HOOKNAME not in mdict:
log.debug(("Skipping module %s, "
"did not find %s in parsed"
" raw userdata"), name, MY_HOOKNAME)
diff --git a/cloudinit/config/cc_rsyslog.py b/cloudinit/config/cc_rsyslog.py
index 0c2c6880..57486edc 100644
--- a/cloudinit/config/cc_rsyslog.py
+++ b/cloudinit/config/cc_rsyslog.py
@@ -35,7 +35,7 @@ def handle(name, cfg, cloud, log, _args):
# *.* @@syslogd.example.com
# process 'rsyslog'
- if not 'rsyslog' in cfg:
+ if 'rsyslog' not in cfg:
log.debug(("Skipping module named %s,"
" no 'rsyslog' key in configuration"), name)
return
@@ -46,7 +46,7 @@ def handle(name, cfg, cloud, log, _args):
files = []
for i, ent in enumerate(cfg['rsyslog']):
if isinstance(ent, dict):
- if not "content" in ent:
+ if "content" not in ent:
log.warn("No 'content' entry in config entry %s", i + 1)
continue
content = ent['content']
diff --git a/cloudinit/config/cc_set_passwords.py b/cloudinit/config/cc_set_passwords.py
index 4a3b21af..4ca85e21 100644
--- a/cloudinit/config/cc_set_passwords.py
+++ b/cloudinit/config/cc_set_passwords.py
@@ -28,7 +28,7 @@ from cloudinit import distros as ds
from cloudinit import ssh_util
from cloudinit import util
-from string import letters, digits # pylint: disable=W0402
+from string import letters, digits
# We are removing certain 'painful' letters/numbers
PW_SET = (letters.translate(None, 'loLOI') +
@@ -132,7 +132,7 @@ def handle(_name, cfg, cloud, log, args):
'PasswordAuthentication',
pw_auth))
- lines = [str(e) for e in new_lines]
+ lines = [str(l) for l in new_lines]
util.write_file(ssh_util.DEF_SSHD_CFG, "\n".join(lines))
try:
diff --git a/cloudinit/config/cc_ssh.py b/cloudinit/config/cc_ssh.py
index 64a5e3cb..4c76581c 100644
--- a/cloudinit/config/cc_ssh.py
+++ b/cloudinit/config/cc_ssh.py
@@ -75,7 +75,7 @@ def handle(_name, cfg, cloud, log, _args):
util.write_file(tgt_fn, val, tgt_perms)
for (priv, pub) in PRIV_2_PUB.iteritems():
- if pub in cfg['ssh_keys'] or not priv in cfg['ssh_keys']:
+ if pub in cfg['ssh_keys'] or priv not in cfg['ssh_keys']:
continue
pair = (KEY_2_FILE[priv][0], KEY_2_FILE[pub][0])
cmd = ['sh', '-xc', KEY_GEN_TPL % pair]
diff --git a/cloudinit/config/cc_ssh_authkey_fingerprints.py b/cloudinit/config/cc_ssh_authkey_fingerprints.py
index be8083db..51580633 100644
--- a/cloudinit/config/cc_ssh_authkey_fingerprints.py
+++ b/cloudinit/config/cc_ssh_authkey_fingerprints.py
@@ -55,7 +55,7 @@ def _gen_fingerprint(b64_text, hash_meth='md5'):
def _is_printable_key(entry):
if any([entry.keytype, entry.base64, entry.comment, entry.options]):
if (entry.keytype and
- entry.keytype.lower().strip() in ['ssh-dss', 'ssh-rsa']):
+ entry.keytype.lower().strip() in ['ssh-dss', 'ssh-rsa']):
return True
return False
@@ -92,9 +92,10 @@ def _pprint_key_entries(user, key_fn, key_entries, hash_meth='md5',
def handle(name, cfg, cloud, log, _args):
- if 'no_ssh_fingerprints' in cfg:
+ if util.is_true(cfg.get('no_ssh_fingerprints', False)):
log.debug(("Skipping module named %s, "
"logging of ssh fingerprints disabled"), name)
+ return
hash_meth = util.get_cfg_option_str(cfg, "authkey_hash", "md5")
(users, _groups) = ds.normalize_users_groups(cfg, cloud.distro)
diff --git a/cloudinit/config/cc_ssh_import_id.py b/cloudinit/config/cc_ssh_import_id.py
index 76c1663d..2d480d7e 100644
--- a/cloudinit/config/cc_ssh_import_id.py
+++ b/cloudinit/config/cc_ssh_import_id.py
@@ -85,7 +85,7 @@ def import_ssh_ids(ids, user, log):
return
try:
- _check = pwd.getpwnam(user)
+ pwd.getpwnam(user)
except KeyError as exc:
raise exc
diff --git a/cloudinit/config/cc_ubuntu_init_switch.py b/cloudinit/config/cc_ubuntu_init_switch.py
new file mode 100644
index 00000000..6f994bff
--- /dev/null
+++ b/cloudinit/config/cc_ubuntu_init_switch.py
@@ -0,0 +1,164 @@
+# vi: ts=4 expandtab
+#
+# Copyright (C) 2014 Canonical Ltd.
+#
+# Author: Scott Moser <scott.moser@canonical.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3, as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+"""
+ubuntu_init_switch: reboot system into another init
+
+This provides a way for the user to boot with systemd even if the
+image is set to boot with upstart. It should be run as one of the first
+cloud_init_modules, and will switch the init system and then issue a reboot.
+The next boot will come up in the target init system and no action will
+be taken.
+
+This should be inert on non-ubuntu systems, and also exit quickly.
+
+config is comes under the top level 'init_switch' dictionary.
+
+#cloud-config
+init_switch:
+ target: systemd
+ reboot: true
+
+'target' can be 'systemd' or 'upstart'. Best effort is made, but its possible
+this system will break, and probably won't interact well with any other
+mechanism you've used to switch the init system.
+
+'reboot': [default=true].
+ true: reboot if a change was made.
+ false: do not reboot.
+"""
+
+from cloudinit.settings import PER_INSTANCE
+from cloudinit import log as logging
+from cloudinit import util
+from cloudinit.distros import ubuntu
+
+import os
+import time
+
+frequency = PER_INSTANCE
+REBOOT_CMD = ["/sbin/reboot", "--force"]
+
+DEFAULT_CONFIG = {
+ 'init_switch': {'target': None, 'reboot': True}
+}
+
+SWITCH_INIT = """
+#!/bin/sh
+# switch_init: [upstart | systemd]
+
+is_systemd() {
+ [ "$(dpkg-divert --listpackage /sbin/init)" = "systemd-sysv" ]
+}
+debug() { echo "$@" 1>&2; }
+fail() { echo "$@" 1>&2; exit 1; }
+
+if [ "$1" = "systemd" ]; then
+ if is_systemd; then
+ debug "already systemd, nothing to do"
+ else
+ [ -f /lib/systemd/systemd ] || fail "no systemd available";
+ dpkg-divert --package systemd-sysv --divert /sbin/init.diverted \\
+ --rename /sbin/init
+ fi
+ [ -f /sbin/init ] || ln /lib/systemd/systemd /sbin/init
+elif [ "$1" = "upstart" ]; then
+ if is_systemd; then
+ rm -f /sbin/init
+ dpkg-divert --package systemd-sysv --rename --remove /sbin/init
+ else
+ debug "already upstart, nothing to do."
+ fi
+else
+ fail "Error. expect 'upstart' or 'systemd'"
+fi
+"""
+
+
+def handle(name, cfg, cloud, log, args):
+
+ if not isinstance(cloud.distro, ubuntu.Distro):
+ log.debug("%s: distro is '%s', not ubuntu. returning",
+ name, cloud.distro.__class__)
+ return
+
+ cfg = util.mergemanydict([cfg, DEFAULT_CONFIG])
+ target = cfg['init_switch']['target']
+ reboot = cfg['init_switch']['reboot']
+
+ if len(args) != 0:
+ target = args[0]
+ if len(args) > 1:
+ reboot = util.is_true(args[1])
+
+ if not target:
+ log.debug("%s: target=%s. nothing to do", name, target)
+ return
+
+ if not util.which('dpkg'):
+ log.warn("%s: 'dpkg' not available. Assuming not ubuntu", name)
+ return
+
+ supported = ('upstart', 'systemd')
+ if target not in supported:
+ log.warn("%s: target set to %s, expected one of: %s",
+ name, target, str(supported))
+
+ if os.path.exists("/run/systemd/system"):
+ current = "systemd"
+ else:
+ current = "upstart"
+
+ if current == target:
+ log.debug("%s: current = target = %s. nothing to do", name, target)
+ return
+
+ try:
+ util.subp(['sh', '-s', target], data=SWITCH_INIT)
+ except util.ProcessExecutionError as e:
+ log.warn("%s: Failed to switch to init '%s'. %s", name, target, e)
+ return
+
+ if util.is_false(reboot):
+ log.info("%s: switched '%s' to '%s'. reboot=false, not rebooting.",
+ name, current, target)
+ return
+
+ try:
+ log.warn("%s: switched '%s' to '%s'. rebooting.",
+ name, current, target)
+ logging.flushLoggers(log)
+ _fire_reboot(log, wait_attempts=4, initial_sleep=4)
+ except Exception as e:
+ util.logexc(log, "Requested reboot did not happen!")
+ raise
+
+
+def _fire_reboot(log, wait_attempts=6, initial_sleep=1, backoff=2):
+ util.subp(REBOOT_CMD)
+ start = time.time()
+ wait_time = initial_sleep
+ for _i in range(0, wait_attempts):
+ time.sleep(wait_time)
+ wait_time *= backoff
+ elapsed = time.time() - start
+ log.debug("Rebooted, but still running after %s seconds", int(elapsed))
+ # If we got here, not good
+ elapsed = time.time() - start
+ raise RuntimeError(("Reboot did not happen"
+ " after %s seconds!") % (int(elapsed)))
diff --git a/cloudinit/config/cc_yum_add_repo.py b/cloudinit/config/cc_yum_add_repo.py
index 5c273825..0d836f28 100644
--- a/cloudinit/config/cc_yum_add_repo.py
+++ b/cloudinit/config/cc_yum_add_repo.py
@@ -42,7 +42,7 @@ def _format_repo_value(val):
return val
-## TODO(harlowja): move to distro?
+# TODO(harlowja): move to distro?
# See man yum.conf
def _format_repository_config(repo_id, repo_config):
to_be = configobj.ConfigObj()
@@ -89,7 +89,7 @@ def handle(name, cfg, _cloud, log, _args):
repo_config = n_repo_config
missing_required = 0
for req_field in ['baseurl']:
- if not req_field in repo_config:
+ if req_field not in repo_config:
log.warn(("Repository %s does not contain a %s"
" configuration 'required' entry"),
repo_id, req_field)