summaryrefslogtreecommitdiff
path: root/cloudinit/config
diff options
context:
space:
mode:
authorScott Moser <smoser@brickies.net>2017-04-27 12:50:12 -0400
committerScott Moser <smoser@brickies.net>2017-04-27 12:50:12 -0400
commit8310484a880690529a4936615df596d467e51708 (patch)
tree886aeb1a6e3ca809e466ddbcacbe9741b56dafa0 /cloudinit/config
parentaf63cf763946bca6163dc797195a3aeae975f8da (diff)
parent513e99e049eab4acea14e187f59d760adc755b40 (diff)
downloadvyos-cloud-init-8310484a880690529a4936615df596d467e51708.tar.gz
vyos-cloud-init-8310484a880690529a4936615df596d467e51708.zip
merge from 513e99e049ea at 0.7.9-113-g513e99e0
Diffstat (limited to 'cloudinit/config')
-rw-r--r--cloudinit/config/__init__.py2
-rw-r--r--cloudinit/config/cc_apt_configure.py11
-rw-r--r--cloudinit/config/cc_disk_setup.py30
-rw-r--r--cloudinit/config/cc_fan.py4
-rw-r--r--cloudinit/config/cc_growpart.py6
-rw-r--r--cloudinit/config/cc_mounts.py12
-rw-r--r--cloudinit/config/cc_resolv_conf.py2
-rw-r--r--cloudinit/config/cc_rsyslog.py7
-rwxr-xr-xcloudinit/config/cc_set_passwords.py3
-rw-r--r--cloudinit/config/cc_snap_config.py4
-rw-r--r--cloudinit/config/cc_snappy.py6
-rw-r--r--cloudinit/config/cc_yum_add_repo.py24
12 files changed, 63 insertions, 48 deletions
diff --git a/cloudinit/config/__init__.py b/cloudinit/config/__init__.py
index 57e2a44d..0ef9a748 100644
--- a/cloudinit/config/__init__.py
+++ b/cloudinit/config/__init__.py
@@ -37,7 +37,7 @@ def fixup_module(mod, def_freq=PER_INSTANCE):
else:
freq = mod.frequency
if freq and freq not in FREQUENCIES:
- LOG.warn("Module %s has an unknown frequency %s", mod, freq)
+ LOG.warning("Module %s has an unknown frequency %s", mod, freq)
if not hasattr(mod, 'distros'):
setattr(mod, 'distros', [])
if not hasattr(mod, 'osfamilies'):
diff --git a/cloudinit/config/cc_apt_configure.py b/cloudinit/config/cc_apt_configure.py
index 06804e85..7e751776 100644
--- a/cloudinit/config/cc_apt_configure.py
+++ b/cloudinit/config/cc_apt_configure.py
@@ -347,8 +347,8 @@ def dpkg_reconfigure(packages, target=None):
unhandled.append(pkg)
if len(unhandled):
- LOG.warn("The following packages were installed and preseeded, "
- "but cannot be unconfigured: %s", unhandled)
+ LOG.warning("The following packages were installed and preseeded, "
+ "but cannot be unconfigured: %s", unhandled)
if len(to_config):
util.subp(['dpkg-reconfigure', '--frontend=noninteractive'] +
@@ -441,7 +441,7 @@ def rename_apt_lists(new_mirrors, target=None):
os.rename(filename, newname)
except OSError:
# since this is a best effort task, warn with but don't fail
- LOG.warn("Failed to rename apt list:", exc_info=True)
+ LOG.warning("Failed to rename apt list:", exc_info=True)
def mirror_to_placeholder(tmpl, mirror, placeholder):
@@ -449,7 +449,7 @@ def mirror_to_placeholder(tmpl, mirror, placeholder):
replace the specified mirror in a template with a placeholder string
Checks for existance of the expected mirror and warns if not found"""
if mirror not in tmpl:
- LOG.warn("Expected mirror '%s' not found in: %s", mirror, tmpl)
+ LOG.warning("Expected mirror '%s' not found in: %s", mirror, tmpl)
return tmpl.replace(mirror, placeholder)
@@ -525,7 +525,8 @@ def generate_sources_list(cfg, release, mirrors, cloud):
if not template_fn:
template_fn = cloud.get_template_filename('sources.list')
if not template_fn:
- LOG.warn("No template found, not rendering /etc/apt/sources.list")
+ LOG.warning("No template found, "
+ "not rendering /etc/apt/sources.list")
return
tmpl = util.load_file(template_fn)
diff --git a/cloudinit/config/cc_disk_setup.py b/cloudinit/config/cc_disk_setup.py
index f39f0815..f49386e3 100644
--- a/cloudinit/config/cc_disk_setup.py
+++ b/cloudinit/config/cc_disk_setup.py
@@ -181,7 +181,7 @@ def update_fs_setup_devices(disk_setup, tformer):
# update it with the response from 'tformer'
for definition in disk_setup:
if not isinstance(definition, dict):
- LOG.warn("entry in disk_setup not a dict: %s", definition)
+ LOG.warning("entry in disk_setup not a dict: %s", definition)
continue
origname = definition.get('device')
@@ -279,7 +279,7 @@ def is_device_valid(name, partition=False):
try:
d_type = device_type(name)
except Exception:
- LOG.warn("Query against device %s failed" % name)
+ LOG.warning("Query against device %s failed", name)
return False
if partition and d_type == 'part':
@@ -372,7 +372,7 @@ def find_device_node(device, fs_type=None, label=None, valid_targets=None,
if not raw_device_used:
return (device, False)
- LOG.warn("Failed to find device during available device search.")
+ LOG.warning("Failed to find device during available device search.")
return (None, False)
@@ -638,7 +638,7 @@ def purge_disk(device):
if d['type'] not in ["disk", "crypt"]:
wipefs_cmd = [WIPEFS_CMD, "--all", "/dev/%s" % d['name']]
try:
- LOG.info("Purging filesystem on /dev/%s" % d['name'])
+ LOG.info("Purging filesystem on /dev/%s", d['name'])
util.subp(wipefs_cmd)
except Exception:
raise Exception("Failed FS purge of /dev/%s" % d['name'])
@@ -700,7 +700,7 @@ def exec_mkpart_gpt(device, layout):
[SGDISK_CMD,
'-t', '{}:{}'.format(index, partition_type), device])
except Exception:
- LOG.warn("Failed to partition device %s" % device)
+ LOG.warning("Failed to partition device %s", device)
raise
read_parttbl(device)
@@ -736,7 +736,7 @@ def mkpart(device, definition):
# ensure that we get a real device rather than a symbolic link
device = os.path.realpath(device)
- LOG.debug("Checking values for %s definition" % device)
+ LOG.debug("Checking values for %s definition", device)
overwrite = definition.get('overwrite', False)
layout = definition.get('layout', False)
table_type = definition.get('table_type', 'mbr')
@@ -766,7 +766,7 @@ def mkpart(device, definition):
LOG.debug("Checking if device is safe to partition")
if not overwrite and (is_disk_used(device) or is_filesystem(device)):
- LOG.debug("Skipping partitioning on configured device %s" % device)
+ LOG.debug("Skipping partitioning on configured device %s", device)
return
LOG.debug("Checking for device size")
@@ -774,7 +774,7 @@ def mkpart(device, definition):
LOG.debug("Calculating partition layout")
part_definition = get_partition_layout(table_type, device_size, layout)
- LOG.debug(" Layout is: %s" % part_definition)
+ LOG.debug(" Layout is: %s", part_definition)
LOG.debug("Creating partition table on %s", device)
exec_mkpart(table_type, device, part_definition)
@@ -799,7 +799,7 @@ def lookup_force_flag(fs):
if fs.lower() in flags:
return flags[fs]
- LOG.warn("Force flag for %s is unknown." % fs)
+ LOG.warning("Force flag for %s is unknown.", fs)
return ''
@@ -858,7 +858,7 @@ def mkfs(fs_cfg):
LOG.debug("Device %s has required file system", device)
return
else:
- LOG.warn("Destroying filesystem on %s", device)
+ LOG.warning("Destroying filesystem on %s", device)
else:
LOG.debug("Device %s is cleared for formating", device)
@@ -883,14 +883,14 @@ def mkfs(fs_cfg):
return
if not reuse and fs_replace and device:
- LOG.debug("Replacing file system on %s as instructed." % device)
+ LOG.debug("Replacing file system on %s as instructed.", device)
if not device:
LOG.debug("No device aviable that matches request. "
"Skipping fs creation for %s", fs_cfg)
return
elif not partition or str(partition).lower() == 'none':
- LOG.debug("Using the raw device to place filesystem %s on" % label)
+ LOG.debug("Using the raw device to place filesystem %s on", label)
else:
LOG.debug("Error in device identification handling.")
@@ -901,7 +901,7 @@ def mkfs(fs_cfg):
# Make sure the device is defined
if not device:
- LOG.warn("Device is not known: %s", device)
+ LOG.warning("Device is not known: %s", device)
return
# Check that we can create the FS
@@ -923,8 +923,8 @@ def mkfs(fs_cfg):
mkfs_cmd = util.which("mk%s" % fs_type)
if not mkfs_cmd:
- LOG.warn("Cannot create fstype '%s'. No mkfs.%s command", fs_type,
- fs_type)
+ LOG.warning("Cannot create fstype '%s'. No mkfs.%s command",
+ fs_type, fs_type)
return
fs_cmd = [mkfs_cmd, device]
diff --git a/cloudinit/config/cc_fan.py b/cloudinit/config/cc_fan.py
index f0cda3d5..0a135bbe 100644
--- a/cloudinit/config/cc_fan.py
+++ b/cloudinit/config/cc_fan.py
@@ -64,7 +64,7 @@ def stop_update_start(service, config_file, content, systemd=False):
try:
return util.subp(cmd, capture=True)
except util.ProcessExecutionError as e:
- LOG.warn("failed: %s (%s): %s", service, cmd, e)
+ LOG.warning("failed: %s (%s): %s", service, cmd, e)
return False
stop_failed = not run(cmds['stop'], msg='stop %s' % service)
@@ -74,7 +74,7 @@ def stop_update_start(service, config_file, content, systemd=False):
ret = run(cmds['start'], msg='start %s' % service)
if ret and stop_failed:
- LOG.warn("success: %s started", service)
+ LOG.warning("success: %s started", service)
if 'enable' in cmds:
ret = run(cmds['enable'], msg='enable %s' % service)
diff --git a/cloudinit/config/cc_growpart.py b/cloudinit/config/cc_growpart.py
index 089693e8..d2bc6e6c 100644
--- a/cloudinit/config/cc_growpart.py
+++ b/cloudinit/config/cc_growpart.py
@@ -252,9 +252,13 @@ def devent2dev(devent):
container = util.is_container()
# Ensure the path is a block device.
- if (dev == "/dev/root" and not os.path.exists(dev) and not container):
+ if (dev == "/dev/root" and not container):
dev = util.rootdev_from_cmdline(util.get_cmdline())
if dev is None:
+ if os.path.exists(dev):
+ # if /dev/root exists, but we failed to convert
+ # that to a "real" /dev/ path device, then return it.
+ return dev
raise ValueError("Unable to find device '/dev/root'")
return dev
diff --git a/cloudinit/config/cc_mounts.py b/cloudinit/config/cc_mounts.py
index 5b630f8b..f14a4fc5 100644
--- a/cloudinit/config/cc_mounts.py
+++ b/cloudinit/config/cc_mounts.py
@@ -216,8 +216,9 @@ def suggested_swapsize(memsize=None, maxsize=None, fsys=None):
else:
pinfo[k] = v
- LOG.debug("suggest %(size)s swap for %(mem)s memory with '%(avail)s'"
- " disk given max=%(max_in)s [max=%(max)s]'" % pinfo)
+ LOG.debug("suggest %s swap for %s memory with '%s'"
+ " disk given max=%s [max=%s]'", pinfo['size'], pinfo['mem'],
+ pinfo['avail'], pinfo['max_in'], pinfo['max'])
return size
@@ -266,7 +267,7 @@ def handle_swapcfg(swapcfg):
return None or (filename, size)
"""
if not isinstance(swapcfg, dict):
- LOG.warn("input for swap config was not a dict.")
+ LOG.warning("input for swap config was not a dict.")
return None
fname = swapcfg.get('filename', '/swap.img')
@@ -289,7 +290,8 @@ def handle_swapcfg(swapcfg):
return fname
LOG.debug("swap file %s existed, but not in /proc/swaps", fname)
except Exception:
- LOG.warn("swap file %s existed. Error reading /proc/swaps", fname)
+ LOG.warning("swap file %s existed. Error reading /proc/swaps",
+ fname)
return fname
try:
@@ -300,7 +302,7 @@ def handle_swapcfg(swapcfg):
return setup_swapfile(fname=fname, size=size, maxsize=maxsize)
except Exception as e:
- LOG.warn("failed to setup swap: %s", e)
+ LOG.warning("failed to setup swap: %s", e)
return None
diff --git a/cloudinit/config/cc_resolv_conf.py b/cloudinit/config/cc_resolv_conf.py
index 9c5cd1fe..2548d1f1 100644
--- a/cloudinit/config/cc_resolv_conf.py
+++ b/cloudinit/config/cc_resolv_conf.py
@@ -77,7 +77,7 @@ def generate_resolv_conf(template_fn, params, target_fname="/etc/resolv.conf"):
params['options'] = {}
params['flags'] = flags
- LOG.debug("Writing resolv.conf from template %s" % template_fn)
+ LOG.debug("Writing resolv.conf from template %s", template_fn)
templater.render_to_file(template_fn, target_fname, params)
diff --git a/cloudinit/config/cc_rsyslog.py b/cloudinit/config/cc_rsyslog.py
index 50316214..50ff9e35 100644
--- a/cloudinit/config/cc_rsyslog.py
+++ b/cloudinit/config/cc_rsyslog.py
@@ -252,7 +252,8 @@ def apply_rsyslog_changes(configs, def_fname, cfg_dir):
for cur_pos, ent in enumerate(configs):
if isinstance(ent, dict):
if "content" not in ent:
- LOG.warn("No 'content' entry in config entry %s", cur_pos + 1)
+ LOG.warning("No 'content' entry in config entry %s",
+ cur_pos + 1)
continue
content = ent['content']
filename = ent.get("filename", def_fname)
@@ -262,7 +263,7 @@ def apply_rsyslog_changes(configs, def_fname, cfg_dir):
filename = filename.strip()
if not filename:
- LOG.warn("Entry %s has an empty filename", cur_pos + 1)
+ LOG.warning("Entry %s has an empty filename", cur_pos + 1)
continue
filename = os.path.join(cfg_dir, filename)
@@ -389,7 +390,7 @@ def remotes_to_rsyslog_cfg(remotes, header=None, footer=None):
try:
lines.append(str(parse_remotes_line(line, name=name)))
except ValueError as e:
- LOG.warn("failed loading remote %s: %s [%s]", name, line, e)
+ LOG.warning("failed loading remote %s: %s [%s]", name, line, e)
if footer is not None:
lines.append(footer)
return '\n'.join(lines) + "\n"
diff --git a/cloudinit/config/cc_set_passwords.py b/cloudinit/config/cc_set_passwords.py
index eb0bdab0..bb24d57f 100755
--- a/cloudinit/config/cc_set_passwords.py
+++ b/cloudinit/config/cc_set_passwords.py
@@ -215,7 +215,8 @@ def handle(_name, cfg, cloud, log, args):
pw_auth))
lines = [str(l) for l in new_lines]
- util.write_file(ssh_util.DEF_SSHD_CFG, "\n".join(lines))
+ util.write_file(ssh_util.DEF_SSHD_CFG, "\n".join(lines),
+ copy_mode=True)
try:
cmd = cloud.distro.init_cmd # Default service
diff --git a/cloudinit/config/cc_snap_config.py b/cloudinit/config/cc_snap_config.py
index db511661..fe0cc73e 100644
--- a/cloudinit/config/cc_snap_config.py
+++ b/cloudinit/config/cc_snap_config.py
@@ -5,8 +5,8 @@
# This file is part of cloud-init. See LICENSE file for license information.
"""
-Snappy
-------
+Snap Config
+-----------
**Summary:** snap_config modules allows configuration of snapd.
This module uses the same ``snappy`` namespace for configuration but
diff --git a/cloudinit/config/cc_snappy.py b/cloudinit/config/cc_snappy.py
index 6ea81b84..a9682f19 100644
--- a/cloudinit/config/cc_snappy.py
+++ b/cloudinit/config/cc_snappy.py
@@ -283,8 +283,8 @@ def handle(name, cfg, cloud, log, args):
render_snap_op(**pkg_op)
except Exception as e:
fails.append((pkg_op, e,))
- LOG.warn("'%s' failed for '%s': %s",
- pkg_op['op'], pkg_op['name'], e)
+ LOG.warning("'%s' failed for '%s': %s",
+ pkg_op['op'], pkg_op['name'], e)
# Default to disabling SSH
ssh_enabled = mycfg.get('ssh_enabled', "auto")
@@ -303,7 +303,7 @@ def handle(name, cfg, cloud, log, args):
LOG.debug("Enabling SSH, password authentication requested")
ssh_enabled = True
elif ssh_enabled not in (True, False):
- LOG.warn("Unknown value '%s' in ssh_enabled", ssh_enabled)
+ LOG.warning("Unknown value '%s' in ssh_enabled", ssh_enabled)
disable_enable_ssh(ssh_enabled)
diff --git a/cloudinit/config/cc_yum_add_repo.py b/cloudinit/config/cc_yum_add_repo.py
index ef8535ed..6a42f499 100644
--- a/cloudinit/config/cc_yum_add_repo.py
+++ b/cloudinit/config/cc_yum_add_repo.py
@@ -32,7 +32,10 @@ entry, the config entry will be skipped.
import os
-import configobj
+try:
+ from configparser import ConfigParser
+except ImportError:
+ from ConfigParser import ConfigParser
import six
from cloudinit import util
@@ -52,8 +55,8 @@ def _format_repo_value(val):
return str(int(val))
if isinstance(val, (list, tuple)):
# Can handle 'lists' in certain cases
- # See: http://bit.ly/Qqrf1t
- return "\n ".join([_format_repo_value(v) for v in val])
+ # See: https://linux.die.net/man/5/yum.conf
+ return "\n".join([_format_repo_value(v) for v in val])
if not isinstance(val, six.string_types):
return str(val)
return val
@@ -62,16 +65,19 @@ def _format_repo_value(val):
# TODO(harlowja): move to distro?
# See man yum.conf
def _format_repository_config(repo_id, repo_config):
- to_be = configobj.ConfigObj()
- to_be[repo_id] = {}
+ to_be = ConfigParser()
+ to_be.add_section(repo_id)
# Do basic translation of the items -> values
for (k, v) in repo_config.items():
# For now assume that people using this know
# the format of yum and don't verify keys/values further
- to_be[repo_id][k] = _format_repo_value(v)
- lines = to_be.write()
- lines.insert(0, "# Created by cloud-init on %s" % (util.time_rfc2822()))
- return "\n".join(lines)
+ to_be.set(repo_id, k, _format_repo_value(v))
+ to_be_stream = six.StringIO()
+ to_be.write(to_be_stream)
+ to_be_stream.seek(0)
+ lines = to_be_stream.readlines()
+ lines.insert(0, "# Created by cloud-init on %s\n" % (util.time_rfc2822()))
+ return "".join(lines)
def handle(name, cfg, _cloud, log, _args):