summaryrefslogtreecommitdiff
path: root/cloudinit/config/cc_chef.py
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit/config/cc_chef.py')
-rw-r--r--cloudinit/config/cc_chef.py40
1 files changed, 20 insertions, 20 deletions
diff --git a/cloudinit/config/cc_chef.py b/cloudinit/config/cc_chef.py
index 5a809230..940aa5f7 100644
--- a/cloudinit/config/cc_chef.py
+++ b/cloudinit/config/cc_chef.py
@@ -10,8 +10,8 @@
import itertools
import json
+import logging
import os
-from logging import Logger
from textwrap import dedent
from cloudinit import subp, temp_utils, templater, url_helper, util
@@ -97,6 +97,8 @@ CHEF_EXEC_DEF_ARGS = tuple(["-d", "-i", "1800", "-s", "20"])
frequency = PER_ALWAYS
distros = ["all"]
+LOG = logging.getLogger(__name__)
+
meta: MetaSchema = {
"id": "cc_chef",
"name": "Chef",
@@ -146,7 +148,7 @@ meta: MetaSchema = {
__doc__ = get_meta_doc(meta)
-def post_run_chef(chef_cfg, log):
+def post_run_chef(chef_cfg):
delete_pem = util.get_cfg_option_bool(
chef_cfg, "delete_validation_post_exec", default=False
)
@@ -154,14 +156,14 @@ def post_run_chef(chef_cfg, log):
os.unlink(CHEF_VALIDATION_PEM_PATH)
-def get_template_params(iid, chef_cfg, log):
+def get_template_params(iid, chef_cfg):
params = CHEF_RB_TPL_DEFAULTS.copy()
# Allow users to overwrite any of the keys they want (if they so choose),
# when a value is None, then the value will be set to None and no boolean
# or string version will be populated...
for (k, v) in chef_cfg.items():
if k not in CHEF_RB_TPL_KEYS:
- log.debug("Skipping unknown chef template key '%s'", k)
+ LOG.debug("Skipping unknown chef template key '%s'", k)
continue
if v is None:
params[k] = None
@@ -189,14 +191,12 @@ def get_template_params(iid, chef_cfg, log):
return params
-def handle(
- name: str, cfg: Config, cloud: Cloud, log: Logger, args: list
-) -> None:
+def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None:
"""Handler method activated by cloud-init."""
# If there isn't a chef key in the configuration don't do anything
if "chef" not in cfg:
- log.debug(
+ LOG.debug(
"Skipping module named %s, no 'chef' key in configuration", name
)
return
@@ -218,7 +218,7 @@ def handle(
if vcert != "system":
util.write_file(vkey_path, vcert)
elif not os.path.isfile(vkey_path):
- log.warning(
+ LOG.warning(
"chef validation_cert provided as 'system', but "
"validation_key path '%s' does not exist.",
vkey_path,
@@ -228,7 +228,7 @@ def handle(
template_fn = cloud.get_template_filename("chef_client.rb")
if template_fn:
iid = str(cloud.datasource.get_instance_id())
- params = get_template_params(iid, chef_cfg, log)
+ params = get_template_params(iid, chef_cfg)
# Do a best effort attempt to ensure that the template values that
# are associated with paths have their parent directory created
# before they are used by the chef-client itself.
@@ -239,14 +239,14 @@ def handle(
util.ensure_dirs(param_paths)
templater.render_to_file(template_fn, CHEF_RB_PATH, params)
else:
- log.warning("No template found, not rendering to %s", CHEF_RB_PATH)
+ LOG.warning("No template found, not rendering to %s", CHEF_RB_PATH)
# Set the firstboot json
fb_filename = util.get_cfg_option_str(
chef_cfg, "firstboot_path", default=CHEF_FB_PATH
)
if not fb_filename:
- log.info("First boot path empty, not writing first boot json file")
+ LOG.info("First boot path empty, not writing first boot json file")
else:
initial_json = {}
if "run_list" in chef_cfg:
@@ -263,18 +263,18 @@ def handle(
)
installed = subp.is_exe(CHEF_EXEC_PATH)
if not installed or force_install:
- run = install_chef(cloud, chef_cfg, log)
+ run = install_chef(cloud, chef_cfg)
elif installed:
run = util.get_cfg_option_bool(chef_cfg, "exec", default=False)
else:
run = False
if run:
- run_chef(chef_cfg, log)
- post_run_chef(chef_cfg, log)
+ run_chef(chef_cfg)
+ post_run_chef(chef_cfg)
-def run_chef(chef_cfg, log):
- log.debug("Running chef-client")
+def run_chef(chef_cfg):
+ LOG.debug("Running chef-client")
cmd = [CHEF_EXEC_PATH]
if "exec_arguments" in chef_cfg:
cmd_args = chef_cfg["exec_arguments"]
@@ -283,7 +283,7 @@ def run_chef(chef_cfg, log):
elif isinstance(cmd_args, str):
cmd.append(cmd_args)
else:
- log.warning(
+ LOG.warning(
"Unknown type %s provided for chef"
" 'exec_arguments' expected list, tuple,"
" or string",
@@ -345,7 +345,7 @@ def install_chef_from_omnibus(
)
-def install_chef(cloud: Cloud, chef_cfg, log):
+def install_chef(cloud: Cloud, chef_cfg):
# If chef is not installed, we install chef based on 'install_type'
install_type = util.get_cfg_option_str(
chef_cfg, "install_type", "packages"
@@ -373,7 +373,7 @@ def install_chef(cloud: Cloud, chef_cfg, log):
omnibus_version=omnibus_version,
)
else:
- log.warning("Unknown chef install type '%s'", install_type)
+ LOG.warning("Unknown chef install type '%s'", install_type)
run = False
return run