1. Renames for debug message from 'transform' to 'module'

2. Fixing up more cloud.path.joins found to use the right ro/rw filename
This commit is contained in:
harlowja 2012-06-21 09:12:16 -07:00
parent 5b112badba
commit e6e6f84fd9
31 changed files with 59 additions and 47 deletions

View File

@ -29,7 +29,7 @@ LOG = logging.getLogger(__name__)
# This class is the high level wrapper that provides
# access to cloud-init objects without exposing the stage objects
# to handler and or transform manipulation. It allows for cloud
# to handler and or module manipulation. It allows for cloud
# init to restrict what those types of user facing code may see
# and or adjust (which helps avoid code messing with each other)
#
@ -47,7 +47,7 @@ class Cloud(object):
self._cfg = cfg
self._runners = runners
# If a transform manipulates logging or logging services
# If a 'user' manipulates logging or logging services
# it is typically useful to cause the logging to be
# setup again.
def cycle_logging(self):

View File

@ -25,6 +25,9 @@ distros = ['ubuntu', 'debian']
DEFAULT_FILE = "/etc/apt/apt.conf.d/90cloud-init-pipelining"
APT_PIPE_TPL = ("//Written by cloud-init per 'apt_pipelining'\n"
'Acquire::http::Pipeline-Depth "%s";\n')
# Acquire::http::Pipeline-Depth can be a value
# from 0 to 5 indicating how many outstanding requests APT should send.
# A value of zero MUST be specified if the remote host does not properly linger
@ -49,8 +52,7 @@ def handle(_name, cfg, cloud, log, _args):
def write_apt_snippet(cloud, setting, log, f_name):
""" Writes f_name with apt pipeline depth 'setting' """
file_contents = ("//Written by cloud-init per 'apt_pipelining'\n"
'Acquire::http::Pipeline-Depth "%s";\n') % (setting)
file_contents = APT_PIPE_TPL % (setting)
util.write_file(cloud.paths.join(False, f_name), file_contents)

View File

@ -30,7 +30,7 @@ frequency = PER_ALWAYS
def handle(name, cfg, cloud, log, _args):
if "bootcmd" not in cfg:
log.debug(("Skipping transform named %s,"
log.debug(("Skipping module named %s,"
" no 'bootcmd' key in configuration"), name)
return
@ -52,5 +52,5 @@ def handle(name, cfg, cloud, log, _args):
util.subp(cmd, env=env, capture=False)
except:
util.logexc(log,
("Failed to run bootcmd transform %s"), name)
("Failed to run bootcmd module %s"), name)
raise

View File

@ -30,7 +30,7 @@ def handle(name, cfg, _cloud, log, args):
value = util.get_cfg_option_str(cfg, "byobu_by_default", "")
if not value:
log.debug("Skipping transform named %s, no 'byobu' values found", name)
log.debug("Skipping module named %s, no 'byobu' values found", name)
return
if value == "user" or value == "system":

View File

@ -75,7 +75,7 @@ def handle(name, cfg, cloud, log, _args):
"""
# If there isn't a ca-certs section in the configuration don't do anything
if "ca-certs" not in cfg:
log.debug(("Skipping transform named %s,"
log.debug(("Skipping module named %s,"
" no 'ca-certs' key in configuration"), name)
return

View File

@ -31,7 +31,7 @@ def handle(name, cfg, cloud, log, _args):
# If there isn't a chef key in the configuration don't do anything
if 'chef' not in cfg:
log.debug(("Skipping transform named %s,"
log.debug(("Skipping module named %s,"
" no 'chef' key in configuration"), name)
return
chef_cfg = cfg['chef']

View File

@ -32,5 +32,5 @@ def handle(name, cfg, _cloud, log, _args):
if disabled:
util.subp(REJECT_CMD)
else:
log.debug(("Skipping transform named %s,"
log.debug(("Skipping module named %s,"
" disabling the ec2 route not enabled"), name)

View File

@ -49,4 +49,4 @@ frequency = PER_INSTANCE
def handle(name, _cfg, _cloud, log, _args):
log.debug("Hi from transform %s", name)
log.debug("Hi from module %s", name)

View File

@ -31,7 +31,7 @@ HELPER_TOOL = '/usr/lib/cloud-init/write-ssh-key-fingerprints'
def handle(name, cfg, cloud, log, _args):
if not os.path.exists(HELPER_TOOL):
log.warn(("Unable to activate transform %s,"
log.warn(("Unable to activate module %s,"
" helper tool not found at %s"), name, HELPER_TOOL)
return

View File

@ -56,7 +56,7 @@ def handle(name, cfg, cloud, log, _args):
"""
if not ConfigObj:
log.warn(("'ConfigObj' support not available,"
" running transform %s disabled"), name)
" running module %s disabled"), name)
return
ls_cloudcfg = cfg.get("landscape", {})
@ -66,9 +66,14 @@ def handle(name, cfg, cloud, log, _args):
" but not a dictionary type,"
" is a %s instead"), util.obj_name(ls_cloudcfg))
lsc_client_fn = cloud.paths.join(True, LSC_CLIENT_CFG_FILE)
merged = merge_together([LSC_BUILTIN_CFG, lsc_client_fn, ls_cloudcfg])
merge_data = [
LSC_BUILTIN_CFG,
cloud.paths.join(True, LSC_CLIENT_CFG_FILE),
ls_cloudcfg,
]
merged = merge_together(merge_data)
lsc_client_fn = cloud.paths.join(False, LSC_CLIENT_CFG_FILE)
lsc_dir = cloud.paths.join(False, os.path.dirname(lsc_client_fn))
if not os.path.isdir(lsc_dir):
util.ensure_dir(lsc_dir)

View File

@ -49,7 +49,7 @@ def handle(name, cfg, cloud, log, args):
"/etc/default/locale")
if not locale:
log.debug(("Skipping transform named %s, "
log.debug(("Skipping module named %s, "
"no 'locale' configuration found"), name)
return

View File

@ -32,7 +32,7 @@ def handle(name, cfg, cloud, log, _args):
# If there isn't a mcollective key in the configuration don't do anything
if 'mcollective' not in cfg:
log.debug(("Skipping transform named %s, "
log.debug(("Skipping module named %s, "
"no 'mcollective' key in configuration"), name)
return

View File

@ -188,8 +188,9 @@ def handle(_name, cfg, cloud, log, _args):
util.logexc(log, "Activating swap via 'swapon -a' failed")
for d in dirs:
real_dir = cloud.paths.join(False, d)
try:
util.ensure_dir(cloud.paths.join(False, d))
util.ensure_dir(real_dir)
except:
util.logexc(log, "Failed to make '%s' config-mount", d)

View File

@ -53,7 +53,7 @@ def handle(name, cfg, cloud, log, args):
ph_cfg = cfg['phone_home']
if 'url' not in ph_cfg:
log.warn(("Skipping transform named %s, "
log.warn(("Skipping module named %s, "
"no 'url' found in 'phone_home' configuration"), name)
return

View File

@ -31,7 +31,7 @@ from cloudinit import util
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 transform named %s,"
log.debug(("Skipping module named %s,"
" no 'puppet' configuration found"), name)
return
@ -43,7 +43,7 @@ def handle(name, cfg, cloud, log, _args):
# ... and then update the puppet configuration
if 'conf' in puppet_cfg:
# Add all sections from the conf object to puppet.conf
puppet_conf_fn = cloud.paths.join(False, '/etc/puppet/puppet.conf')
puppet_conf_fn = cloud.paths.join(True, '/etc/puppet/puppet.conf')
contents = util.load_file(puppet_conf_fn)
# Create object for reading puppet.conf values
puppet_config = helpers.DefaultingConfigParser()
@ -89,9 +89,11 @@ def handle(name, cfg, cloud, log, _args):
puppet_config.set(cfg_name, o, v)
# We got all our config as wanted we'll rename
# the previous puppet.conf and create our new one
puppet_conf_old_fn = "%s.old" % (puppet_conf_fn)
util.rename(puppet_conf_fn, puppet_conf_old_fn)
util.write_file(puppet_conf_fn, puppet_config.stringify())
conf_old_fn = cloud.paths.join(False,
'/etc/puppet/puppet.conf.old')
util.rename(puppet_conf_fn, conf_old_fn)
puppet_conf_rw = cloud.paths.join(False, '/etc/puppet/puppet.conf')
util.write_file(puppet_conf_rw, puppet_config.stringify())
# Set puppet to automatically start
if os.path.exists('/etc/default/puppet'):

View File

@ -69,7 +69,7 @@ def handle(name, cfg, cloud, log, args):
resize_root = util.get_cfg_option_str(cfg, "resize_rootfs", True)
if not util.translate_bool(resize_root):
log.debug("Skipping transform named %s, resizing disabled", name)
log.debug("Skipping module named %s, resizing disabled", name)
return
# TODO is the directory ok to be used??

View File

@ -53,13 +53,13 @@ def handle(name, _cfg, cloud, log, _args):
try:
ud = cloud.get_userdata_raw()
except:
log.warn("Failed to get raw userdata in transform %s", name)
log.warn("Failed to get raw userdata in module %s", name)
return
try:
mdict = parse_qs(ud)
if not mdict or not MY_HOOKNAME in mdict:
log.debug(("Skipping transform %s, "
log.debug(("Skipping module %s, "
"did not find %s in parsed"
" raw userdata"), name, MY_HOOKNAME)
return
@ -73,7 +73,7 @@ def handle(name, _cfg, cloud, log, _args):
# These will eventually be then ran by the cc_scripts_user
# TODO: maybe this should just be a new user data handler??
# Instead of a late transform that acts like a user data handler?
# Instead of a late module that acts like a user data handler?
scripts_d = cloud.get_ipath_cur('scripts')
urls = mdict[MY_HOOKNAME]
for (i, url) in enumerate(urls):

View File

@ -36,7 +36,7 @@ def handle(name, cfg, cloud, log, _args):
# process 'rsyslog'
if not 'rsyslog' in cfg:
log.debug(("Skipping transform named %s,"
log.debug(("Skipping module named %s,"
" no 'rsyslog' key in configuration"), name)
return

View File

@ -25,7 +25,7 @@ from cloudinit import util
def handle(name, cfg, cloud, log, _args):
if "runcmd" not in cfg:
log.debug(("Skipping transform named %s,"
log.debug(("Skipping module named %s,"
" no 'runcmd' key in configuration"), name)
return

View File

@ -24,7 +24,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 transform named %s,"
log.debug(("Skipping module named %s,"
" no 'salt_minion' key in configuration"), name)
return
@ -34,8 +34,8 @@ def handle(name, cfg, cloud, log, _args):
cloud.distro.install_packages(["salt"])
# Ensure we can configure files at the right dir
config_dir = salt_cfg.get("config_dir", '/etc/salt')
config_dir = cloud.paths.join(False, config_dir)
config_dir = cloud.paths.join(False, salt_cfg.get("config_dir",
'/etc/salt'))
util.ensure_dir(config_dir)
# ... and then update the salt configuration
@ -47,8 +47,8 @@ def handle(name, cfg, cloud, log, _args):
# ... copy the key pair if specified
if 'public_key' in salt_cfg and 'private_key' in salt_cfg:
pki_dir = salt_cfg.get('pki_dir', '/etc/salt/pki')
pki_dir = cloud.paths.join(pki_dir)
pki_dir = cloud.paths.join(False, salt_cfg.get('pki_dir',
'/etc/salt/pki'))
with util.umask(077):
util.ensure_dir(pki_dir)
pub_name = os.path.join(pki_dir, 'minion.pub')

View File

@ -36,6 +36,6 @@ def handle(name, _cfg, cloud, log, _args):
try:
util.runparts(runparts_path)
except:
log.warn("Failed to run transform %s (%s in %s)",
log.warn("Failed to run module %s (%s in %s)",
name, SCRIPT_SUBDIR, runparts_path)
raise

View File

@ -36,6 +36,6 @@ def handle(name, _cfg, cloud, log, _args):
try:
util.runparts(runparts_path)
except:
log.warn("Failed to run transform %s (%s in %s)",
log.warn("Failed to run module %s (%s in %s)",
name, SCRIPT_SUBDIR, runparts_path)
raise

View File

@ -36,6 +36,6 @@ def handle(name, _cfg, cloud, log, _args):
try:
util.runparts(runparts_path)
except:
log.warn("Failed to run transform %s (%s in %s)",
log.warn("Failed to run module %s (%s in %s)",
name, SCRIPT_SUBDIR, runparts_path)
raise

View File

@ -37,6 +37,6 @@ def handle(name, _cfg, cloud, log, _args):
try:
util.runparts(runparts_path)
except:
log.warn("Failed to run transform %s (%s in %s)",
log.warn("Failed to run module %s (%s in %s)",
name, SCRIPT_SUBDIR, runparts_path)
raise

View File

@ -24,7 +24,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 transform %s"), name)
" not setting the hostname in module %s"), name)
return
(hostname, _fqdn) = util.get_hostname_fqdn(cfg, cloud)

View File

@ -106,7 +106,9 @@ def handle(_name, cfg, cloud, log, args):
replacement = "PasswordAuthentication %s" % (pw_auth)
# See http://linux.die.net/man/5/sshd_config
old_lines = util.load_file('/etc/ssh/sshd_config').splitlines()
conf_fn = cloud.paths.join(True, '/etc/ssh/sshd_config')
# Todo: use the common ssh_util function for this parsing...
old_lines = util.load_file(conf_fn).splitlines()
for i, line in enumerate(old_lines):
if not line.strip() or line.startswith("#"):
new_lines.append(line)

View File

@ -36,11 +36,11 @@ def handle(name, cfg, _cloud, log, args):
ids = util.get_cfg_option_list(cfg, "ssh_import_id", [])
if len(ids) == 0:
log.debug("Skipping transform named %s, no ids found to import", name)
log.debug("Skipping module named %s, no ids found to import", name)
return
if not user:
log.debug("Skipping transform named %s, no user found to import", name)
log.debug("Skipping module named %s, no user found to import", name)
return
cmd = ["sudo", "-Hu", user, "ssh-import-id"] + ids

View File

@ -32,7 +32,7 @@ def handle(name, cfg, cloud, log, args):
timezone = util.get_cfg_option_str(cfg, "timezone", False)
if not timezone:
log.debug("Skipping transform named %s, no 'timezone' specified", name)
log.debug("Skipping module named %s, no 'timezone' specified", name)
return
# Let the distro handle settings its timezone

View File

@ -57,4 +57,4 @@ def handle(name, cfg, cloud, log, _args):
cloud.distro.update_etc_hosts(hostname, fqdn)
else:
log.debug(("Configuration option 'manage_etc_hosts' is not set,"
" not managing /etc/hosts in transform %s"), name)
" not managing /etc/hosts in module %s"), name)

View File

@ -29,7 +29,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 transform %s"), name)
" not updating the hostname in module %s"), name)
return
(hostname, _fqdn) = util.get_hostname_fqdn(cfg, cloud)

View File

@ -518,7 +518,7 @@ class Modules(object):
" but not on %s distro. It may or may not work"
" correctly."), name, worked_distros, d_name)
# Deep copy the config so that modules can't alter it
# Use the transforms logger and not our own
# Use the configs logger and not our own
func_args = [name, copy.deepcopy(self.cfg),
cc, config.LOG, args]
# Mark it as having started running