Merge gentoo branch and updated set-password to support systemctl
This commit is contained in:
commit
b3143042d3
@ -51,6 +51,8 @@ EXPORT_GPG_KEYID = """
|
|||||||
|
|
||||||
|
|
||||||
def handle(name, cfg, cloud, log, _args):
|
def handle(name, cfg, cloud, log, _args):
|
||||||
|
if cloud.distro.is_excluded(name):
|
||||||
|
return
|
||||||
release = get_release()
|
release = get_release()
|
||||||
mirrors = find_apt_mirror_info(cloud, cfg)
|
mirrors = find_apt_mirror_info(cloud, cfg)
|
||||||
if not mirrors or "primary" not in mirrors:
|
if not mirrors or "primary" not in mirrors:
|
||||||
|
@ -35,7 +35,8 @@ APT_PIPE_TPL = ("//Written by cloud-init per 'apt_pipelining'\n"
|
|||||||
|
|
||||||
|
|
||||||
def handle(_name, cfg, _cloud, log, _args):
|
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 = util.get_cfg_option_str(cfg, "apt_pipelining", False)
|
||||||
apt_pipe_value_s = str(apt_pipe_value).lower().strip()
|
apt_pipe_value_s = str(apt_pipe_value).lower().strip()
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ distros = ['ubuntu', 'debian']
|
|||||||
|
|
||||||
|
|
||||||
def handle(name, cfg, cloud, log, args):
|
def handle(name, cfg, cloud, log, args):
|
||||||
|
|
||||||
if len(args) != 0:
|
if len(args) != 0:
|
||||||
value = args[0]
|
value = args[0]
|
||||||
else:
|
else:
|
||||||
|
@ -79,6 +79,7 @@ def handle(name, cfg, _cloud, log, _args):
|
|||||||
@param args: Any module arguments from cloud.cfg
|
@param args: Any module arguments from cloud.cfg
|
||||||
"""
|
"""
|
||||||
# If there isn't a ca-certs section in the configuration don't do anything
|
# If there isn't a ca-certs section in the configuration don't do anything
|
||||||
|
|
||||||
if "ca-certs" not in cfg:
|
if "ca-certs" not in cfg:
|
||||||
log.debug(("Skipping module named %s,"
|
log.debug(("Skipping module named %s,"
|
||||||
" no 'ca-certs' key in configuration"), name)
|
" no 'ca-certs' key in configuration"), name)
|
||||||
|
@ -40,6 +40,7 @@ def handle(_name, cfg, cloud, log, _args):
|
|||||||
See doc/examples/cloud-config_disk-setup.txt for documentation on the
|
See doc/examples/cloud-config_disk-setup.txt for documentation on the
|
||||||
format.
|
format.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
disk_setup = cfg.get("disk_setup")
|
disk_setup = cfg.get("disk_setup")
|
||||||
if isinstance(disk_setup, dict):
|
if isinstance(disk_setup, dict):
|
||||||
update_disk_setup_devices(disk_setup, cloud.device_name_to_device)
|
update_disk_setup_devices(disk_setup, cloud.device_name_to_device)
|
||||||
|
@ -29,6 +29,8 @@ distros = ['ubuntu', 'debian']
|
|||||||
|
|
||||||
|
|
||||||
def handle(name, _cfg, cloud, log, args):
|
def handle(name, _cfg, cloud, log, args):
|
||||||
|
if cloud.distro.is_excluded(name):
|
||||||
|
return
|
||||||
event_names = args
|
event_names = args
|
||||||
if not event_names:
|
if not event_names:
|
||||||
# Default to the 'cloud-config'
|
# Default to the 'cloud-config'
|
||||||
|
@ -255,6 +255,7 @@ def resize_devices(resizer, devices):
|
|||||||
|
|
||||||
|
|
||||||
def handle(_name, cfg, _cloud, log, _args):
|
def handle(_name, cfg, _cloud, log, _args):
|
||||||
|
|
||||||
if 'growpart' not in cfg:
|
if 'growpart' not in cfg:
|
||||||
log.debug("No 'growpart' entry in cfg. Using default: %s" %
|
log.debug("No 'growpart' entry in cfg. Using default: %s" %
|
||||||
DEFAULT_CONFIG)
|
DEFAULT_CONFIG)
|
||||||
|
@ -26,9 +26,12 @@ distros = ['ubuntu', 'debian']
|
|||||||
|
|
||||||
|
|
||||||
def handle(_name, cfg, _cloud, log, _args):
|
def handle(_name, cfg, _cloud, log, _args):
|
||||||
|
|
||||||
idevs = None
|
idevs = None
|
||||||
idevs_empty = None
|
idevs_empty = None
|
||||||
|
|
||||||
|
if _cloud.distro.is_excluded(_name):
|
||||||
|
return
|
||||||
if "grub-dpkg" in cfg:
|
if "grub-dpkg" in cfg:
|
||||||
idevs = util.get_cfg_option_str(cfg["grub-dpkg"],
|
idevs = util.get_cfg_option_str(cfg["grub-dpkg"],
|
||||||
"grub-pc/install_devices", None)
|
"grub-pc/install_devices", None)
|
||||||
|
@ -30,6 +30,8 @@ HELPER_TOOL = '/usr/lib/cloud-init/write-ssh-key-fingerprints'
|
|||||||
|
|
||||||
|
|
||||||
def handle(name, cfg, _cloud, log, _args):
|
def handle(name, cfg, _cloud, log, _args):
|
||||||
|
if _cloud.distro.is_excluded(name):
|
||||||
|
return
|
||||||
if not os.path.exists(HELPER_TOOL):
|
if not os.path.exists(HELPER_TOOL):
|
||||||
log.warn(("Unable to activate module %s,"
|
log.warn(("Unable to activate module %s,"
|
||||||
" helper tool not found at %s"), name, HELPER_TOOL)
|
" helper tool not found at %s"), name, HELPER_TOOL)
|
||||||
|
@ -22,6 +22,7 @@ from cloudinit import util
|
|||||||
|
|
||||||
|
|
||||||
def handle(name, cfg, cloud, log, args):
|
def handle(name, cfg, cloud, log, args):
|
||||||
|
|
||||||
if len(args) != 0:
|
if len(args) != 0:
|
||||||
locale = args[0]
|
locale = args[0]
|
||||||
else:
|
else:
|
||||||
|
@ -75,6 +75,7 @@ def _migrate_legacy_sems(cloud, log):
|
|||||||
|
|
||||||
|
|
||||||
def handle(name, cfg, cloud, log, _args):
|
def handle(name, cfg, cloud, log, _args):
|
||||||
|
|
||||||
do_migrate = util.get_cfg_option_str(cfg, "migrate", True)
|
do_migrate = util.get_cfg_option_str(cfg, "migrate", True)
|
||||||
if not util.translate_bool(do_migrate):
|
if not util.translate_bool(do_migrate):
|
||||||
log.debug("Skipping module named %s, migration disabled", name)
|
log.debug("Skipping module named %s, migration disabled", name)
|
||||||
|
@ -76,6 +76,7 @@ def sanitize_devname(startname, transformer, log):
|
|||||||
|
|
||||||
|
|
||||||
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
|
# fs_spec, fs_file, fs_vfstype, fs_mntops, fs-freq, fs_passno
|
||||||
defvals = [None, None, "auto", "defaults,nobootwait", "0", "2"]
|
defvals = [None, None, "auto", "defaults,nobootwait", "0", "2"]
|
||||||
defvals = cfg.get("mount_default_fields", defvals)
|
defvals = cfg.get("mount_default_fields", defvals)
|
||||||
|
@ -49,6 +49,7 @@ def _fire_reboot(log, wait_attempts=6, initial_sleep=1, backoff=2):
|
|||||||
|
|
||||||
|
|
||||||
def handle(_name, cfg, cloud, log, _args):
|
def handle(_name, cfg, cloud, log, _args):
|
||||||
|
|
||||||
# Handle the old style + new config names
|
# Handle the old style + new config names
|
||||||
update = _multi_cfg_bool_get(cfg, 'apt_update', 'package_update')
|
update = _multi_cfg_bool_get(cfg, 'apt_update', 'package_update')
|
||||||
upgrade = _multi_cfg_bool_get(cfg, 'package_upgrade', 'apt_upgrade')
|
upgrade = _multi_cfg_bool_get(cfg, 'package_upgrade', 'apt_upgrade')
|
||||||
|
@ -44,6 +44,7 @@ POST_LIST_ALL = [
|
|||||||
# post: [ pub_key_dsa, pub_key_rsa, pub_key_ecdsa, 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:
|
if len(args) != 0:
|
||||||
ph_cfg = util.read_conf(args[0])
|
ph_cfg = util.read_conf(args[0])
|
||||||
else:
|
else:
|
||||||
|
@ -49,6 +49,7 @@ def _autostart_puppet(log):
|
|||||||
|
|
||||||
|
|
||||||
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 there isn't a puppet key in the configuration don't do anything
|
||||||
if 'puppet' not in cfg:
|
if 'puppet' not in cfg:
|
||||||
log.debug(("Skipping module named %s,"
|
log.debug(("Skipping module named %s,"
|
||||||
|
@ -76,6 +76,7 @@ def rootdev_from_cmdline(cmdline):
|
|||||||
|
|
||||||
|
|
||||||
def handle(name, cfg, _cloud, log, args):
|
def handle(name, cfg, _cloud, log, args):
|
||||||
|
|
||||||
if len(args) != 0:
|
if len(args) != 0:
|
||||||
resize_root = args[0]
|
resize_root = args[0]
|
||||||
else:
|
else:
|
||||||
|
@ -92,6 +92,7 @@ def handle(name, cfg, _cloud, log, _args):
|
|||||||
@param log: Pre-initialized Python logger object to use for logging.
|
@param log: Pre-initialized Python logger object to use for logging.
|
||||||
@param args: Any module arguments from cloud.cfg
|
@param args: Any module arguments from cloud.cfg
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if "manage_resolv_conf" not in cfg:
|
if "manage_resolv_conf" not in cfg:
|
||||||
log.debug(("Skipping module named %s,"
|
log.debug(("Skipping module named %s,"
|
||||||
" no 'manage_resolv_conf' key in configuration"), name)
|
" no 'manage_resolv_conf' key in configuration"), name)
|
||||||
|
@ -50,6 +50,7 @@ MY_HOOKNAME = 'CLOUD_INIT_REMOTE_HOOK'
|
|||||||
|
|
||||||
|
|
||||||
def handle(name, _cfg, cloud, log, _args):
|
def handle(name, _cfg, cloud, log, _args):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ud = cloud.get_userdata_raw()
|
ud = cloud.get_userdata_raw()
|
||||||
except:
|
except:
|
||||||
|
@ -35,6 +35,7 @@ def handle(name, cfg, cloud, log, _args):
|
|||||||
# *.* @@syslogd.example.com
|
# *.* @@syslogd.example.com
|
||||||
|
|
||||||
# process 'rsyslog'
|
# process 'rsyslog'
|
||||||
|
|
||||||
if not 'rsyslog' in cfg:
|
if not 'rsyslog' in cfg:
|
||||||
log.debug(("Skipping module named %s,"
|
log.debug(("Skipping module named %s,"
|
||||||
" no 'rsyslog' key in configuration"), name)
|
" no 'rsyslog' key in configuration"), name)
|
||||||
|
@ -22,6 +22,7 @@ from cloudinit import util
|
|||||||
|
|
||||||
|
|
||||||
def handle(name, cfg, cloud, log, _args):
|
def handle(name, cfg, cloud, log, _args):
|
||||||
|
|
||||||
# If there isn't a salt key in the configuration don't do anything
|
# If there isn't a salt key in the configuration don't do anything
|
||||||
if 'salt_minion' not in cfg:
|
if 'salt_minion' not in cfg:
|
||||||
log.debug(("Skipping module named %s,"
|
log.debug(("Skipping module named %s,"
|
||||||
|
@ -39,6 +39,7 @@ def _decode(data, encoding=None):
|
|||||||
|
|
||||||
|
|
||||||
def handle(name, cfg, cloud, log, _args):
|
def handle(name, cfg, cloud, log, _args):
|
||||||
|
|
||||||
if not cfg or "random_seed" not in cfg:
|
if not cfg or "random_seed" not in cfg:
|
||||||
log.debug(("Skipping module named %s, "
|
log.debug(("Skipping module named %s, "
|
||||||
"no 'random_seed' configuration found"), name)
|
"no 'random_seed' configuration found"), name)
|
||||||
|
@ -22,6 +22,7 @@ from cloudinit import util
|
|||||||
|
|
||||||
|
|
||||||
def handle(name, cfg, cloud, log, _args):
|
def handle(name, cfg, cloud, log, _args):
|
||||||
|
|
||||||
if util.get_cfg_option_bool(cfg, "preserve_hostname", False):
|
if util.get_cfg_option_bool(cfg, "preserve_hostname", False):
|
||||||
log.debug(("Configuration option 'preserve_hostname' is set,"
|
log.debug(("Configuration option 'preserve_hostname' is set,"
|
||||||
" not setting the hostname in module %s"), name)
|
" not setting the hostname in module %s"), name)
|
||||||
|
@ -36,6 +36,7 @@ PW_SET = (letters.translate(None, 'loLOI') +
|
|||||||
|
|
||||||
|
|
||||||
def handle(_name, cfg, cloud, log, args):
|
def handle(_name, cfg, cloud, log, args):
|
||||||
|
|
||||||
if len(args) != 0:
|
if len(args) != 0:
|
||||||
# if run from command line, and give args, wipe the chpasswd['list']
|
# if run from command line, and give args, wipe the chpasswd['list']
|
||||||
password = args[0]
|
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))
|
util.write_file(ssh_util.DEF_SSHD_CFG, "\n".join(lines))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cmd = ['service']
|
cmd = cloud.distro.init_cmd # Default service
|
||||||
cmd.append(cloud.distro.get_option('ssh_svcname', 'ssh'))
|
cmd.append(cloud.distro.get_option('ssh_svcname', 'ssh'))
|
||||||
cmd.append('restart')
|
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)
|
util.subp(cmd)
|
||||||
log.debug("Restarted the ssh daemon")
|
log.debug("Restarted the ssh daemon")
|
||||||
except:
|
except:
|
||||||
|
@ -92,6 +92,7 @@ def _pprint_key_entries(user, key_fn, key_entries, hash_meth='md5',
|
|||||||
|
|
||||||
|
|
||||||
def handle(name, cfg, cloud, log, _args):
|
def handle(name, cfg, cloud, log, _args):
|
||||||
|
|
||||||
if 'no_ssh_fingerprints' in cfg:
|
if 'no_ssh_fingerprints' in cfg:
|
||||||
log.debug(("Skipping module named %s, "
|
log.debug(("Skipping module named %s, "
|
||||||
"logging of ssh fingerprints disabled"), name)
|
"logging of ssh fingerprints disabled"), name)
|
||||||
|
@ -26,6 +26,7 @@ frequency = PER_INSTANCE
|
|||||||
|
|
||||||
|
|
||||||
def handle(name, cfg, cloud, log, args):
|
def handle(name, cfg, cloud, log, args):
|
||||||
|
|
||||||
if len(args) != 0:
|
if len(args) != 0:
|
||||||
timezone = args[0]
|
timezone = args[0]
|
||||||
else:
|
else:
|
||||||
|
@ -27,6 +27,7 @@ frequency = PER_ALWAYS
|
|||||||
|
|
||||||
|
|
||||||
def handle(name, cfg, cloud, log, _args):
|
def handle(name, cfg, cloud, log, _args):
|
||||||
|
|
||||||
manage_hosts = util.get_cfg_option_str(cfg, "manage_etc_hosts", False)
|
manage_hosts = util.get_cfg_option_str(cfg, "manage_etc_hosts", False)
|
||||||
if util.translate_bool(manage_hosts, addons=['template']):
|
if util.translate_bool(manage_hosts, addons=['template']):
|
||||||
(hostname, fqdn) = util.get_hostname_fqdn(cfg, cloud)
|
(hostname, fqdn) = util.get_hostname_fqdn(cfg, cloud)
|
||||||
|
@ -27,6 +27,7 @@ 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):
|
if util.get_cfg_option_bool(cfg, "preserve_hostname", False):
|
||||||
log.debug(("Configuration option 'preserve_hostname' is set,"
|
log.debug(("Configuration option 'preserve_hostname' is set,"
|
||||||
" not updating the hostname in module %s"), name)
|
" not updating the hostname in module %s"), name)
|
||||||
|
@ -27,6 +27,7 @@ frequency = PER_INSTANCE
|
|||||||
|
|
||||||
|
|
||||||
def handle(name, cfg, cloud, _log, _args):
|
def handle(name, cfg, cloud, _log, _args):
|
||||||
|
|
||||||
(users, groups) = ds.normalize_users_groups(cfg, cloud.distro)
|
(users, groups) = ds.normalize_users_groups(cfg, cloud.distro)
|
||||||
for (name, members) in groups.items():
|
for (name, members) in groups.items():
|
||||||
cloud.distro.create_group(name, members)
|
cloud.distro.create_group(name, members)
|
||||||
|
@ -58,6 +58,8 @@ def _format_repository_config(repo_id, repo_config):
|
|||||||
|
|
||||||
|
|
||||||
def handle(name, cfg, _cloud, log, _args):
|
def handle(name, cfg, _cloud, log, _args):
|
||||||
|
if _cloud.distro.is_excluded(name):
|
||||||
|
return
|
||||||
repos = cfg.get('yum_repos')
|
repos = cfg.get('yum_repos')
|
||||||
if not repos:
|
if not repos:
|
||||||
log.debug(("Skipping module named %s,"
|
log.debug(("Skipping module named %s,"
|
||||||
|
@ -39,6 +39,7 @@ from cloudinit.distros.parsers import hosts
|
|||||||
OSFAMILIES = {
|
OSFAMILIES = {
|
||||||
'debian': ['debian', 'ubuntu'],
|
'debian': ['debian', 'ubuntu'],
|
||||||
'redhat': ['fedora', 'rhel'],
|
'redhat': ['fedora', 'rhel'],
|
||||||
|
'gentoo': ['gentoo'],
|
||||||
'freebsd': ['freebsd'],
|
'freebsd': ['freebsd'],
|
||||||
'suse': ['sles'],
|
'suse': ['sles'],
|
||||||
'arch': ['arch'],
|
'arch': ['arch'],
|
||||||
@ -54,12 +55,21 @@ class Distro(object):
|
|||||||
ci_sudoers_fn = "/etc/sudoers.d/90-cloud-init-users"
|
ci_sudoers_fn = "/etc/sudoers.d/90-cloud-init-users"
|
||||||
hostname_conf_fn = "/etc/hostname"
|
hostname_conf_fn = "/etc/hostname"
|
||||||
tz_zone_dir = "/usr/share/zoneinfo"
|
tz_zone_dir = "/usr/share/zoneinfo"
|
||||||
|
init_cmd = ['service'] # systemctl, service etc
|
||||||
|
exclude_modules = []
|
||||||
|
|
||||||
def __init__(self, name, cfg, paths):
|
def __init__(self, name, cfg, paths):
|
||||||
self._paths = paths
|
self._paths = paths
|
||||||
self._cfg = cfg
|
self._cfg = cfg
|
||||||
self.name = name
|
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
|
@abc.abstractmethod
|
||||||
def install_packages(self, pkglist):
|
def install_packages(self, pkglist):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
184
cloudinit/distros/gentoo.py
Normal file
184
cloudinit/distros/gentoo.py
Normal file
@ -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)
|
13
sysvinit/gentoo/cloud-config
Normal file
13
sysvinit/gentoo/cloud-config
Normal file
@ -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
|
||||||
|
}
|
11
sysvinit/gentoo/cloud-final
Normal file
11
sysvinit/gentoo/cloud-final
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#!/sbin/runscript
|
||||||
|
|
||||||
|
depend() {
|
||||||
|
after cloud-config
|
||||||
|
provide cloud-final
|
||||||
|
}
|
||||||
|
|
||||||
|
start() {
|
||||||
|
cloud-init modules --mode final
|
||||||
|
eend 0
|
||||||
|
}
|
12
sysvinit/gentoo/cloud-init
Normal file
12
sysvinit/gentoo/cloud-init
Normal file
@ -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
|
||||||
|
}
|
11
sysvinit/gentoo/cloud-init-local
Normal file
11
sysvinit/gentoo/cloud-init-local
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#!/sbin/runscript
|
||||||
|
|
||||||
|
depend() {
|
||||||
|
before cloud-init
|
||||||
|
provide cloud-init-local
|
||||||
|
}
|
||||||
|
|
||||||
|
start() {
|
||||||
|
cloud-init init --local
|
||||||
|
eend 0
|
||||||
|
}
|
15
tests/unittests/test_distros/test_is_excluded.py
Normal file
15
tests/unittests/test_distros/test_is_excluded.py
Normal file
@ -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)
|
@ -2,6 +2,7 @@ from cloudinit import helpers
|
|||||||
from cloudinit import util
|
from cloudinit import util
|
||||||
|
|
||||||
from cloudinit.config import cc_yum_add_repo
|
from cloudinit.config import cc_yum_add_repo
|
||||||
|
from cloudinit.distros import rhel
|
||||||
|
|
||||||
from tests.unittests import helpers
|
from tests.unittests import helpers
|
||||||
|
|
||||||
@ -18,6 +19,8 @@ class TestConfig(helpers.FilesystemMockingTestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestConfig, self).setUp()
|
super(TestConfig, self).setUp()
|
||||||
self.tmp = self.makeDir(prefix="unittest_")
|
self.tmp = self.makeDir(prefix="unittest_")
|
||||||
|
self.cloud = type('', (), {})()
|
||||||
|
self.cloud.distro = rhel.Distro('test', {}, None)
|
||||||
|
|
||||||
def test_bad_config(self):
|
def test_bad_config(self):
|
||||||
cfg = {
|
cfg = {
|
||||||
@ -34,7 +37,7 @@ class TestConfig(helpers.FilesystemMockingTestCase):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
self.patchUtils(self.tmp)
|
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,
|
self.assertRaises(IOError, util.load_file,
|
||||||
"/etc/yum.repos.d/epel_testing.repo")
|
"/etc/yum.repos.d/epel_testing.repo")
|
||||||
|
|
||||||
@ -52,7 +55,7 @@ class TestConfig(helpers.FilesystemMockingTestCase):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
self.patchUtils(self.tmp)
|
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 = util.load_file("/etc/yum.repos.d/epel_testing.repo")
|
||||||
contents = configobj.ConfigObj(StringIO(contents))
|
contents = configobj.ConfigObj(StringIO(contents))
|
||||||
expected = {
|
expected = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user