summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cloudinit/config/cc_apt_configure.py2
-rw-r--r--cloudinit/config/cc_apt_pipelining.py3
-rw-r--r--cloudinit/config/cc_byobu.py1
-rw-r--r--cloudinit/config/cc_ca_certs.py1
-rw-r--r--cloudinit/config/cc_disk_setup.py1
-rw-r--r--cloudinit/config/cc_emit_upstart.py2
-rw-r--r--cloudinit/config/cc_growpart.py1
-rw-r--r--cloudinit/config/cc_grub_dpkg.py3
-rw-r--r--cloudinit/config/cc_keys_to_console.py2
-rw-r--r--cloudinit/config/cc_locale.py1
-rw-r--r--cloudinit/config/cc_migrator.py1
-rw-r--r--cloudinit/config/cc_mounts.py1
-rw-r--r--cloudinit/config/cc_package_update_upgrade_install.py1
-rw-r--r--cloudinit/config/cc_phone_home.py1
-rw-r--r--cloudinit/config/cc_puppet.py1
-rw-r--r--cloudinit/config/cc_resizefs.py1
-rw-r--r--cloudinit/config/cc_resolv_conf.py1
-rw-r--r--cloudinit/config/cc_rightscale_userdata.py1
-rw-r--r--cloudinit/config/cc_rsyslog.py1
-rw-r--r--cloudinit/config/cc_salt_minion.py1
-rw-r--r--cloudinit/config/cc_seed_random.py1
-rw-r--r--cloudinit/config/cc_set_hostname.py1
-rw-r--r--cloudinit/config/cc_set_passwords.py6
-rw-r--r--cloudinit/config/cc_ssh_authkey_fingerprints.py1
-rw-r--r--cloudinit/config/cc_timezone.py1
-rw-r--r--cloudinit/config/cc_update_etc_hosts.py1
-rw-r--r--cloudinit/config/cc_update_hostname.py1
-rw-r--r--cloudinit/config/cc_users_groups.py1
-rw-r--r--cloudinit/config/cc_yum_add_repo.py2
-rw-r--r--cloudinit/distros/__init__.py10
-rw-r--r--cloudinit/distros/gentoo.py184
-rw-r--r--sysvinit/gentoo/cloud-config13
-rw-r--r--sysvinit/gentoo/cloud-final11
-rw-r--r--sysvinit/gentoo/cloud-init12
-rw-r--r--sysvinit/gentoo/cloud-init-local11
-rw-r--r--tests/unittests/test_distros/test_is_excluded.py15
-rw-r--r--tests/unittests/test_handler/test_handler_yum_add_repo.py7
37 files changed, 301 insertions, 4 deletions
diff --git a/cloudinit/config/cc_apt_configure.py b/cloudinit/config/cc_apt_configure.py
index 29c13a3d..ccb45bb9 100644
--- a/cloudinit/config/cc_apt_configure.py
+++ b/cloudinit/config/cc_apt_configure.py
@@ -51,6 +51,8 @@ EXPORT_GPG_KEYID = """
def handle(name, cfg, cloud, log, _args):
+ if cloud.distro.is_excluded(name):
+ return
release = get_release()
mirrors = find_apt_mirror_info(cloud, cfg)
if not mirrors or "primary" not in mirrors:
diff --git a/cloudinit/config/cc_apt_pipelining.py b/cloudinit/config/cc_apt_pipelining.py
index e5629175..bd180e82 100644
--- a/cloudinit/config/cc_apt_pipelining.py
+++ b/cloudinit/config/cc_apt_pipelining.py
@@ -35,7 +35,8 @@ APT_PIPE_TPL = ("//Written by cloud-init per 'apt_pipelining'\n"
def handle(_name, cfg, _cloud, log, _args):
-
+ if _cloud.distro.is_excluded(_name):
+ return
apt_pipe_value = util.get_cfg_option_str(cfg, "apt_pipelining", False)
apt_pipe_value_s = str(apt_pipe_value).lower().strip()
diff --git a/cloudinit/config/cc_byobu.py b/cloudinit/config/cc_byobu.py
index 92d428b7..4821693b 100644
--- a/cloudinit/config/cc_byobu.py
+++ b/cloudinit/config/cc_byobu.py
@@ -29,6 +29,7 @@ distros = ['ubuntu', 'debian']
def handle(name, cfg, cloud, log, args):
+
if len(args) != 0:
value = args[0]
else:
diff --git a/cloudinit/config/cc_ca_certs.py b/cloudinit/config/cc_ca_certs.py
index 4f2a46a1..7b339274 100644
--- a/cloudinit/config/cc_ca_certs.py
+++ b/cloudinit/config/cc_ca_certs.py
@@ -79,6 +79,7 @@ def handle(name, cfg, _cloud, log, _args):
@param args: Any module arguments from cloud.cfg
"""
# If there isn't a ca-certs section in the configuration don't do anything
+
if "ca-certs" not in cfg:
log.debug(("Skipping module named %s,"
" no 'ca-certs' key in configuration"), name)
diff --git a/cloudinit/config/cc_disk_setup.py b/cloudinit/config/cc_disk_setup.py
index 0b970e4e..d0274ba6 100644
--- a/cloudinit/config/cc_disk_setup.py
+++ b/cloudinit/config/cc_disk_setup.py
@@ -40,6 +40,7 @@ def handle(_name, cfg, cloud, log, _args):
See doc/examples/cloud-config_disk-setup.txt for documentation on the
format.
"""
+
disk_setup = cfg.get("disk_setup")
if isinstance(disk_setup, dict):
update_disk_setup_devices(disk_setup, cloud.device_name_to_device)
diff --git a/cloudinit/config/cc_emit_upstart.py b/cloudinit/config/cc_emit_upstart.py
index 6d376184..5c2f6a31 100644
--- a/cloudinit/config/cc_emit_upstart.py
+++ b/cloudinit/config/cc_emit_upstart.py
@@ -29,6 +29,8 @@ distros = ['ubuntu', 'debian']
def handle(name, _cfg, cloud, log, args):
+ if cloud.distro.is_excluded(name):
+ return
event_names = args
if not event_names:
# Default to the 'cloud-config'
diff --git a/cloudinit/config/cc_growpart.py b/cloudinit/config/cc_growpart.py
index f52c41f0..4c5997fa 100644
--- a/cloudinit/config/cc_growpart.py
+++ b/cloudinit/config/cc_growpart.py
@@ -255,6 +255,7 @@ def resize_devices(resizer, devices):
def handle(_name, cfg, _cloud, log, _args):
+
if 'growpart' not in cfg:
log.debug("No 'growpart' entry in cfg. Using default: %s" %
DEFAULT_CONFIG)
diff --git a/cloudinit/config/cc_grub_dpkg.py b/cloudinit/config/cc_grub_dpkg.py
index b3ce6fb6..3fd92426 100644
--- a/cloudinit/config/cc_grub_dpkg.py
+++ b/cloudinit/config/cc_grub_dpkg.py
@@ -26,9 +26,12 @@ distros = ['ubuntu', 'debian']
def handle(_name, cfg, _cloud, log, _args):
+
idevs = None
idevs_empty = None
+ if _cloud.distro.is_excluded(_name):
+ return
if "grub-dpkg" in cfg:
idevs = util.get_cfg_option_str(cfg["grub-dpkg"],
"grub-pc/install_devices", None)
diff --git a/cloudinit/config/cc_keys_to_console.py b/cloudinit/config/cc_keys_to_console.py
index ed7af690..c9563e25 100644
--- a/cloudinit/config/cc_keys_to_console.py
+++ b/cloudinit/config/cc_keys_to_console.py
@@ -30,6 +30,8 @@ HELPER_TOOL = '/usr/lib/cloud-init/write-ssh-key-fingerprints'
def handle(name, cfg, _cloud, log, _args):
+ if _cloud.distro.is_excluded(name):
+ return
if not os.path.exists(HELPER_TOOL):
log.warn(("Unable to activate module %s,"
" helper tool not found at %s"), name, HELPER_TOOL)
diff --git a/cloudinit/config/cc_locale.py b/cloudinit/config/cc_locale.py
index 6feaae9d..68399993 100644
--- a/cloudinit/config/cc_locale.py
+++ b/cloudinit/config/cc_locale.py
@@ -22,6 +22,7 @@ from cloudinit import util
def handle(name, cfg, cloud, log, args):
+
if len(args) != 0:
locale = args[0]
else:
diff --git a/cloudinit/config/cc_migrator.py b/cloudinit/config/cc_migrator.py
index facaa538..f7b2211a 100644
--- a/cloudinit/config/cc_migrator.py
+++ b/cloudinit/config/cc_migrator.py
@@ -75,6 +75,7 @@ def _migrate_legacy_sems(cloud, log):
def handle(name, cfg, cloud, log, _args):
+
do_migrate = util.get_cfg_option_str(cfg, "migrate", True)
if not util.translate_bool(do_migrate):
log.debug("Skipping module named %s, migration disabled", name)
diff --git a/cloudinit/config/cc_mounts.py b/cloudinit/config/cc_mounts.py
index 80590118..c1ac76d4 100644
--- a/cloudinit/config/cc_mounts.py
+++ b/cloudinit/config/cc_mounts.py
@@ -76,6 +76,7 @@ def sanitize_devname(startname, transformer, log):
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)
diff --git a/cloudinit/config/cc_package_update_upgrade_install.py b/cloudinit/config/cc_package_update_upgrade_install.py
index 73b0e30d..85bc0240 100644
--- a/cloudinit/config/cc_package_update_upgrade_install.py
+++ b/cloudinit/config/cc_package_update_upgrade_install.py
@@ -49,6 +49,7 @@ def _fire_reboot(log, wait_attempts=6, initial_sleep=1, backoff=2):
def handle(_name, cfg, cloud, log, _args):
+
# Handle the old style + new config names
update = _multi_cfg_bool_get(cfg, 'apt_update', 'package_update')
upgrade = _multi_cfg_bool_get(cfg, 'package_upgrade', 'apt_upgrade')
diff --git a/cloudinit/config/cc_phone_home.py b/cloudinit/config/cc_phone_home.py
index 2e058ccd..360fd83e 100644
--- a/cloudinit/config/cc_phone_home.py
+++ b/cloudinit/config/cc_phone_home.py
@@ -44,6 +44,7 @@ POST_LIST_ALL = [
# post: [ pub_key_dsa, pub_key_rsa, pub_key_ecdsa, instance_id
#
def handle(name, cfg, cloud, log, args):
+
if len(args) != 0:
ph_cfg = util.read_conf(args[0])
else:
diff --git a/cloudinit/config/cc_puppet.py b/cloudinit/config/cc_puppet.py
index 471a1a8a..717734d1 100644
--- a/cloudinit/config/cc_puppet.py
+++ b/cloudinit/config/cc_puppet.py
@@ -49,6 +49,7 @@ def _autostart_puppet(log):
def handle(name, cfg, cloud, log, _args):
+
# If there isn't a puppet key in the configuration don't do anything
if 'puppet' not in cfg:
log.debug(("Skipping module named %s,"
diff --git a/cloudinit/config/cc_resizefs.py b/cloudinit/config/cc_resizefs.py
index be406034..9d767873 100644
--- a/cloudinit/config/cc_resizefs.py
+++ b/cloudinit/config/cc_resizefs.py
@@ -76,6 +76,7 @@ def rootdev_from_cmdline(cmdline):
def handle(name, cfg, _cloud, log, args):
+
if len(args) != 0:
resize_root = args[0]
else:
diff --git a/cloudinit/config/cc_resolv_conf.py b/cloudinit/config/cc_resolv_conf.py
index 879b62b1..feacebcd 100644
--- a/cloudinit/config/cc_resolv_conf.py
+++ b/cloudinit/config/cc_resolv_conf.py
@@ -92,6 +92,7 @@ def handle(name, cfg, _cloud, log, _args):
@param log: Pre-initialized Python logger object to use for logging.
@param args: Any module arguments from cloud.cfg
"""
+
if "manage_resolv_conf" not in cfg:
log.debug(("Skipping module named %s,"
" no 'manage_resolv_conf' key in configuration"), name)
diff --git a/cloudinit/config/cc_rightscale_userdata.py b/cloudinit/config/cc_rightscale_userdata.py
index c771728d..f99524d1 100644
--- a/cloudinit/config/cc_rightscale_userdata.py
+++ b/cloudinit/config/cc_rightscale_userdata.py
@@ -50,6 +50,7 @@ MY_HOOKNAME = 'CLOUD_INIT_REMOTE_HOOK'
def handle(name, _cfg, cloud, log, _args):
+
try:
ud = cloud.get_userdata_raw()
except:
diff --git a/cloudinit/config/cc_rsyslog.py b/cloudinit/config/cc_rsyslog.py
index 0c2c6880..7f70167e 100644
--- a/cloudinit/config/cc_rsyslog.py
+++ b/cloudinit/config/cc_rsyslog.py
@@ -35,6 +35,7 @@ def handle(name, cfg, cloud, log, _args):
# *.* @@syslogd.example.com
# process 'rsyslog'
+
if not 'rsyslog' in cfg:
log.debug(("Skipping module named %s,"
" no 'rsyslog' key in configuration"), name)
diff --git a/cloudinit/config/cc_salt_minion.py b/cloudinit/config/cc_salt_minion.py
index 53013dcb..b48762c8 100644
--- a/cloudinit/config/cc_salt_minion.py
+++ b/cloudinit/config/cc_salt_minion.py
@@ -22,6 +22,7 @@ from cloudinit import util
def handle(name, cfg, cloud, log, _args):
+
# If there isn't a salt key in the configuration don't do anything
if 'salt_minion' not in cfg:
log.debug(("Skipping module named %s,"
diff --git a/cloudinit/config/cc_seed_random.py b/cloudinit/config/cc_seed_random.py
index 22a31f29..1676dd0a 100644
--- a/cloudinit/config/cc_seed_random.py
+++ b/cloudinit/config/cc_seed_random.py
@@ -39,6 +39,7 @@ def _decode(data, encoding=None):
def handle(name, cfg, cloud, log, _args):
+
if not cfg or "random_seed" not in cfg:
log.debug(("Skipping module named %s, "
"no 'random_seed' configuration found"), name)
diff --git a/cloudinit/config/cc_set_hostname.py b/cloudinit/config/cc_set_hostname.py
index 5d7f4331..38246b57 100644
--- a/cloudinit/config/cc_set_hostname.py
+++ b/cloudinit/config/cc_set_hostname.py
@@ -22,6 +22,7 @@ from cloudinit import util
def handle(name, cfg, cloud, log, _args):
+
if util.get_cfg_option_bool(cfg, "preserve_hostname", False):
log.debug(("Configuration option 'preserve_hostname' is set,"
" not setting the hostname in module %s"), name)
diff --git a/cloudinit/config/cc_set_passwords.py b/cloudinit/config/cc_set_passwords.py
index 56a36906..967769de 100644
--- a/cloudinit/config/cc_set_passwords.py
+++ b/cloudinit/config/cc_set_passwords.py
@@ -36,6 +36,7 @@ PW_SET = (letters.translate(None, 'loLOI') +
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]
@@ -136,9 +137,12 @@ def handle(_name, cfg, cloud, log, args):
util.write_file(ssh_util.DEF_SSHD_CFG, "\n".join(lines))
try:
- cmd = ['service']
+ cmd = cloud.distro.init_cmd # Default service
cmd.append(cloud.distro.get_option('ssh_svcname', 'ssh'))
cmd.append('restart')
+ if 'systemctl' in cmd: # Switch action ordering
+ cmd[1], cmd[2] = cmd[2], cmd[1]
+ cmd = filter(None, cmd) # Remove empty arguments
util.subp(cmd)
log.debug("Restarted the ssh daemon")
except:
diff --git a/cloudinit/config/cc_ssh_authkey_fingerprints.py b/cloudinit/config/cc_ssh_authkey_fingerprints.py
index be8083db..8b2708b1 100644
--- a/cloudinit/config/cc_ssh_authkey_fingerprints.py
+++ b/cloudinit/config/cc_ssh_authkey_fingerprints.py
@@ -92,6 +92,7 @@ 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:
log.debug(("Skipping module named %s, "
"logging of ssh fingerprints disabled"), name)
diff --git a/cloudinit/config/cc_timezone.py b/cloudinit/config/cc_timezone.py
index b9eb85b2..bddcd0e9 100644
--- a/cloudinit/config/cc_timezone.py
+++ b/cloudinit/config/cc_timezone.py
@@ -26,6 +26,7 @@ frequency = PER_INSTANCE
def handle(name, cfg, cloud, log, args):
+
if len(args) != 0:
timezone = args[0]
else:
diff --git a/cloudinit/config/cc_update_etc_hosts.py b/cloudinit/config/cc_update_etc_hosts.py
index d3dd1f32..3e3b4228 100644
--- a/cloudinit/config/cc_update_etc_hosts.py
+++ b/cloudinit/config/cc_update_etc_hosts.py
@@ -27,6 +27,7 @@ frequency = PER_ALWAYS
def handle(name, cfg, cloud, log, _args):
+
manage_hosts = util.get_cfg_option_str(cfg, "manage_etc_hosts", False)
if util.translate_bool(manage_hosts, addons=['template']):
(hostname, fqdn) = util.get_hostname_fqdn(cfg, cloud)
diff --git a/cloudinit/config/cc_update_hostname.py b/cloudinit/config/cc_update_hostname.py
index e396ba13..56f6ebb7 100644
--- a/cloudinit/config/cc_update_hostname.py
+++ b/cloudinit/config/cc_update_hostname.py
@@ -27,6 +27,7 @@ frequency = PER_ALWAYS
def handle(name, cfg, cloud, log, _args):
+
if util.get_cfg_option_bool(cfg, "preserve_hostname", False):
log.debug(("Configuration option 'preserve_hostname' is set,"
" not updating the hostname in module %s"), name)
diff --git a/cloudinit/config/cc_users_groups.py b/cloudinit/config/cc_users_groups.py
index bf5b4581..30bf455d 100644
--- a/cloudinit/config/cc_users_groups.py
+++ b/cloudinit/config/cc_users_groups.py
@@ -27,6 +27,7 @@ frequency = PER_INSTANCE
def handle(name, cfg, cloud, _log, _args):
+
(users, groups) = ds.normalize_users_groups(cfg, cloud.distro)
for (name, members) in groups.items():
cloud.distro.create_group(name, members)
diff --git a/cloudinit/config/cc_yum_add_repo.py b/cloudinit/config/cc_yum_add_repo.py
index 5c273825..f63e3e08 100644
--- a/cloudinit/config/cc_yum_add_repo.py
+++ b/cloudinit/config/cc_yum_add_repo.py
@@ -58,6 +58,8 @@ def _format_repository_config(repo_id, repo_config):
def handle(name, cfg, _cloud, log, _args):
+ if _cloud.distro.is_excluded(name):
+ return
repos = cfg.get('yum_repos')
if not repos:
log.debug(("Skipping module named %s,"
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index b58c8460..8fc0da9f 100644
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -39,6 +39,7 @@ from cloudinit.distros.parsers import hosts
OSFAMILIES = {
'debian': ['debian', 'ubuntu'],
'redhat': ['fedora', 'rhel'],
+ 'gentoo': ['gentoo'],
'freebsd': ['freebsd'],
'suse': ['sles'],
'arch': ['arch'],
@@ -54,12 +55,21 @@ class Distro(object):
ci_sudoers_fn = "/etc/sudoers.d/90-cloud-init-users"
hostname_conf_fn = "/etc/hostname"
tz_zone_dir = "/usr/share/zoneinfo"
+ init_cmd = ['service'] # systemctl, service etc
+ exclude_modules = []
def __init__(self, name, cfg, paths):
self._paths = paths
self._cfg = cfg
self.name = name
+ def is_excluded(self, name):
+ if name in self.exclude_modules:
+ distro = getattr(self, name, None) or getattr(self, 'osfamily')
+ LOG.debug(("Skipping module named %s, distro %s excluded"), name,
+ distro)
+ return True
+
@abc.abstractmethod
def install_packages(self, pkglist):
raise NotImplementedError()
diff --git a/cloudinit/distros/gentoo.py b/cloudinit/distros/gentoo.py
new file mode 100644
index 00000000..e8778e15
--- /dev/null
+++ b/cloudinit/distros/gentoo.py
@@ -0,0 +1,184 @@
+# vi: ts=4 expandtab
+#
+# Copyright (C) 2014 Rackspace, US Inc.
+#
+# Author: Nate House <nathan.house@rackspace.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/>.
+
+from cloudinit import distros
+from cloudinit import helpers
+from cloudinit import log as logging
+from cloudinit import util
+
+from cloudinit.distros.parsers.hostname import HostnameConf
+
+from cloudinit.settings import PER_INSTANCE
+
+LOG = logging.getLogger(__name__)
+
+
+class Distro(distros.Distro):
+ locale_conf_fn = "/etc/locale.gen"
+ network_conf_fn = "/etc/conf.d/net"
+ tz_conf_fn = "/etc/timezone"
+ tz_local_fn = "/etc/localtime"
+ init_cmd = [''] # init scripts
+ exclude_modules = [
+ 'grub-dpkg',
+ 'apt-configure',
+ 'apt-pipelining',
+ 'yum-add-repo',
+ ]
+
+ def __init__(self, name, cfg, paths):
+ distros.Distro.__init__(self, name, cfg, paths)
+ # This will be used to restrict certain
+ # calls from repeatly happening (when they
+ # should only happen say once per instance...)
+ self._runner = helpers.Runners(paths)
+ self.osfamily = 'gentoo'
+ # Fix sshd restarts
+ cfg['ssh_svcname'] = '/etc/init.d/sshd'
+
+ def apply_locale(self, locale, out_fn=None):
+ if not out_fn:
+ out_fn = self.locale_conf_fn
+ util.subp(['locale-gen', '-G', locale], capture=False)
+ # "" provides trailing newline during join
+ lines = [
+ util.make_header(),
+ 'LANG="%s"' % (locale),
+ "",
+ ]
+ util.write_file(out_fn, "\n".join(lines))
+
+ def install_packages(self, pkglist):
+ self.update_package_sources()
+ self.package_command('', pkgs=pkglist)
+
+ def _write_network(self, settings):
+ util.write_file(self.network_conf_fn, settings)
+ return ['all']
+
+ def _bring_up_interface(self, device_name):
+ cmd = ['/etc/init.d/net.%s' % device_name, 'restart']
+ LOG.debug("Attempting to run bring up interface %s using command %s",
+ device_name, cmd)
+ try:
+ (_out, err) = util.subp(cmd)
+ if len(err):
+ LOG.warn("Running %s resulted in stderr output: %s", cmd, err)
+ return True
+ except util.ProcessExecutionError:
+ util.logexc(LOG, "Running interface command %s failed", cmd)
+ return False
+
+ def _bring_up_interfaces(self, device_names):
+ use_all = False
+ for d in device_names:
+ if d == 'all':
+ use_all = True
+ if use_all:
+ # Grab device names from init scripts
+ cmd = ['ls', '/etc/init.d/net.*']
+ try:
+ (_out, err) = util.subp(cmd)
+ if len(err):
+ LOG.warn("Running %s resulted in stderr output: %s", cmd,
+ err)
+ except util.ProcessExecutionError:
+ util.logexc(LOG, "Running interface command %s failed", cmd)
+ return False
+ devices = [x.split('.')[2] for x in _out.split(' ')]
+ return distros.Distro._bring_up_interfaces(self, devices)
+ else:
+ return distros.Distro._bring_up_interfaces(self, device_names)
+
+ def _select_hostname(self, hostname, fqdn):
+ # Prefer the short hostname over the long
+ # fully qualified domain name
+ if not hostname:
+ return fqdn
+ return hostname
+
+ def _write_hostname(self, your_hostname, out_fn):
+ conf = None
+ try:
+ # Try to update the previous one
+ # so lets see if we can read it first.
+ conf = self._read_hostname_conf(out_fn)
+ except IOError:
+ pass
+ if not conf:
+ conf = HostnameConf('')
+ conf.set_hostname(your_hostname)
+ util.write_file(out_fn, str(conf), 0644)
+
+ def _read_system_hostname(self):
+ sys_hostname = self._read_hostname(self.hostname_conf_fn)
+ return (self.hostname_conf_fn, sys_hostname)
+
+ def _read_hostname_conf(self, filename):
+ conf = HostnameConf(util.load_file(filename))
+ conf.parse()
+ return conf
+
+ def _read_hostname(self, filename, default=None):
+ hostname = None
+ try:
+ conf = self._read_hostname_conf(filename)
+ hostname = conf.hostname
+ except IOError:
+ pass
+ if not hostname:
+ return default
+ return hostname
+
+ def set_timezone(self, tz):
+ tz_file = self._find_tz_file(tz)
+ # Note: "" provides trailing newline during join
+ tz_lines = [
+ util.make_header(),
+ str(tz),
+ "",
+ ]
+ util.write_file(self.tz_conf_fn, "\n".join(tz_lines))
+ # This ensures that the correct tz will be used for the system
+ util.copy(tz_file, self.tz_local_fn)
+
+ def package_command(self, command, args=None, pkgs=None):
+ if pkgs is None:
+ pkgs = []
+
+ cmd = ['emerge']
+ # Redirect output
+ cmd.append("--quiet")
+
+ if args and isinstance(args, str):
+ cmd.append(args)
+ elif args and isinstance(args, list):
+ cmd.extend(args)
+
+ if command:
+ cmd.append(command)
+
+ pkglist = util.expand_package_list('%s-%s', pkgs)
+ cmd.extend(pkglist)
+
+ # Allow the output of this to flow outwards (ie not be captured)
+ util.subp(cmd, capture=False)
+
+ def update_package_sources(self):
+ self._runner.run("update-sources", self.package_command,
+ ["-u", "world", "--quiet"], freq=PER_INSTANCE)
diff --git a/sysvinit/gentoo/cloud-config b/sysvinit/gentoo/cloud-config
new file mode 100644
index 00000000..b0fa786d
--- /dev/null
+++ b/sysvinit/gentoo/cloud-config
@@ -0,0 +1,13 @@
+#!/sbin/runscript
+
+depend() {
+ after cloud-init-local
+ after cloud-init
+ before cloud-final
+ provide cloud-config
+}
+
+start() {
+ cloud-init modules --mode config
+ eend 0
+}
diff --git a/sysvinit/gentoo/cloud-final b/sysvinit/gentoo/cloud-final
new file mode 100644
index 00000000..b457a354
--- /dev/null
+++ b/sysvinit/gentoo/cloud-final
@@ -0,0 +1,11 @@
+#!/sbin/runscript
+
+depend() {
+ after cloud-config
+ provide cloud-final
+}
+
+start() {
+ cloud-init modules --mode final
+ eend 0
+}
diff --git a/sysvinit/gentoo/cloud-init b/sysvinit/gentoo/cloud-init
new file mode 100644
index 00000000..9ab64ad8
--- /dev/null
+++ b/sysvinit/gentoo/cloud-init
@@ -0,0 +1,12 @@
+#!/sbin/runscript
+# add depends for network, dns, fs etc
+depend() {
+ after cloud-init-local
+ before cloud-config
+ provide cloud-init
+}
+
+start() {
+ cloud-init init
+ eend 0
+}
diff --git a/sysvinit/gentoo/cloud-init-local b/sysvinit/gentoo/cloud-init-local
new file mode 100644
index 00000000..8c9968d8
--- /dev/null
+++ b/sysvinit/gentoo/cloud-init-local
@@ -0,0 +1,11 @@
+#!/sbin/runscript
+
+depend() {
+ before cloud-init
+ provide cloud-init-local
+}
+
+start() {
+ cloud-init init --local
+ eend 0
+}
diff --git a/tests/unittests/test_distros/test_is_excluded.py b/tests/unittests/test_distros/test_is_excluded.py
new file mode 100644
index 00000000..53a4445c
--- /dev/null
+++ b/tests/unittests/test_distros/test_is_excluded.py
@@ -0,0 +1,15 @@
+from cloudinit.distros import gentoo
+import unittest
+
+
+class TestIsExcluded(unittest.TestCase):
+
+ def setUp(self):
+ self.distro = gentoo.Distro('gentoo', {}, None)
+ self.distro.exclude_modules = ['test-module']
+
+ def test_is_excluded_success(self):
+ self.assertEqual(self.distro.is_excluded('test-module'), True)
+
+ def test_is_excluded_fail(self):
+ self.assertEqual(self.distro.is_excluded('missing'), None)
diff --git a/tests/unittests/test_handler/test_handler_yum_add_repo.py b/tests/unittests/test_handler/test_handler_yum_add_repo.py
index 8df592f9..ddf0ef9c 100644
--- a/tests/unittests/test_handler/test_handler_yum_add_repo.py
+++ b/tests/unittests/test_handler/test_handler_yum_add_repo.py
@@ -2,6 +2,7 @@ from cloudinit import helpers
from cloudinit import util
from cloudinit.config import cc_yum_add_repo
+from cloudinit.distros import rhel
from tests.unittests import helpers
@@ -18,6 +19,8 @@ class TestConfig(helpers.FilesystemMockingTestCase):
def setUp(self):
super(TestConfig, self).setUp()
self.tmp = self.makeDir(prefix="unittest_")
+ self.cloud = type('', (), {})()
+ self.cloud.distro = rhel.Distro('test', {}, None)
def test_bad_config(self):
cfg = {
@@ -34,7 +37,7 @@ class TestConfig(helpers.FilesystemMockingTestCase):
},
}
self.patchUtils(self.tmp)
- cc_yum_add_repo.handle('yum_add_repo', cfg, None, LOG, [])
+ cc_yum_add_repo.handle('yum_add_repo', cfg, self.cloud, LOG, [])
self.assertRaises(IOError, util.load_file,
"/etc/yum.repos.d/epel_testing.repo")
@@ -52,7 +55,7 @@ class TestConfig(helpers.FilesystemMockingTestCase):
},
}
self.patchUtils(self.tmp)
- cc_yum_add_repo.handle('yum_add_repo', cfg, None, LOG, [])
+ cc_yum_add_repo.handle('yum_add_repo', cfg, self.cloud, LOG, [])
contents = util.load_file("/etc/yum.repos.d/epel_testing.repo")
contents = configobj.ConfigObj(StringIO(contents))
expected = {