diff options
author | Lucendio <github+dev@lucendio.com> | 2021-10-25 21:31:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-25 14:31:07 -0500 |
commit | a4236c375ddf78258a8f9252c1d79c665aa4f88b (patch) | |
tree | a092882639d27965c2fe6fd7d3faa232c37f5d22 /cloudinit/config/cc_write_files_deferred.py | |
parent | 81f6aa1653936e324bba69e51439aa8894aaf170 (diff) | |
download | vyos-cloud-init-a4236c375ddf78258a8f9252c1d79c665aa4f88b.tar.gz vyos-cloud-init-a4236c375ddf78258a8f9252c1d79c665aa4f88b.zip |
Add module 'write-files-deferred' executed in stage 'final' (#916)
The main idea is to introduce a second module that takes care of
writing files, but in the 'final' stage.
While the introduction of a second module would allow for choosing
the appropriate place withing the order of modules (and stages),
there is no addition top-level directive being added to the cloud
configuration schema. Instead, 'write-files' schema is being extended
to include a 'defer' attribute used only by the 'write-deffered-files'
modules.
The new module 'write-deferred-files' reuses as much as
possible of the 'write-files' functionality.
Diffstat (limited to 'cloudinit/config/cc_write_files_deferred.py')
-rw-r--r-- | cloudinit/config/cc_write_files_deferred.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/cloudinit/config/cc_write_files_deferred.py b/cloudinit/config/cc_write_files_deferred.py new file mode 100644 index 00000000..0c75aa22 --- /dev/null +++ b/cloudinit/config/cc_write_files_deferred.py @@ -0,0 +1,55 @@ +# Copyright (C) 2021 Canonical Ltd. +# +# This file is part of cloud-init. See LICENSE file for license information. + +"""Defer writing certain files""" + +from textwrap import dedent + +from cloudinit.config.schema import validate_cloudconfig_schema +from cloudinit import util +from cloudinit.config.cc_write_files import ( + schema as write_files_schema, write_files, DEFAULT_DEFER) + + +schema = util.mergemanydict([ + { + 'id': 'cc_write_files_deferred', + 'name': 'Write Deferred Files', + 'title': dedent("""\ + write certain files, whose creation as been deferred, during + final stage + """), + 'description': dedent("""\ + This module is based on `'Write Files' <write-files>`__, and + will handle all files from the write_files list, that have been + marked as deferred and thus are not being processed by the + write-files module. + + *Please note that his module is not exposed to the user through + its own dedicated top-level directive.* + """) + }, + write_files_schema +]) + +# Not exposed, because related modules should document this behaviour +__doc__ = None + + +def handle(name, cfg, _cloud, log, _args): + validate_cloudconfig_schema(cfg, schema) + file_list = cfg.get('write_files', []) + filtered_files = [ + f for f in file_list if util.get_cfg_option_bool(f, + 'defer', + DEFAULT_DEFER) + ] + if not filtered_files: + log.debug(("Skipping module named %s," + " no deferred file defined in configuration"), name) + return + write_files(name, filtered_files) + + +# vi: ts=4 expandtab |