diff options
author | Scott Moser <smoser@brickies.net> | 2013-04-03 17:39:32 -0500 |
---|---|---|
committer | Scott Moser <smoser@brickies.net> | 2013-04-03 17:39:32 -0500 |
commit | 0d3c21c53369673529301f2c4e23bdb7bae7495b (patch) | |
tree | 79c4998ac3ca75f28258723d09eb1784a7943033 | |
parent | 3ed5f780fed21fb02b2c86b1f54650f92c941f36 (diff) | |
download | vyos-cloud-init-0d3c21c53369673529301f2c4e23bdb7bae7495b.tar.gz vyos-cloud-init-0d3c21c53369673529301f2c4e23bdb7bae7495b.zip |
add merge debug tool
-rwxr-xr-x | tools/ccfg-merge-debug | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/tools/ccfg-merge-debug b/tools/ccfg-merge-debug new file mode 100755 index 00000000..aac60528 --- /dev/null +++ b/tools/ccfg-merge-debug @@ -0,0 +1,81 @@ +#!/usr/bin/python + +from cloudinit import handlers +from cloudinit.handlers import cloud_config as cc_part +from cloudinit import helpers +from cloudinit.settings import PER_INSTANCE +from cloudinit import user_data as ud + +import argparse +import os +import shutil +import tempfile + + +def main(): + parser = argparse.ArgumentParser( + description='test cloud-config merging') + parser.add_argument("--output", "-o", metavar="file", + help="specify output file", default="-") + parser.add_argument('files', nargs='+') + + args = parser.parse_args() + outfile = args.output + if args.output == "-": + outfile = "/dev/stdout" + + tempd = tempfile.mkdtemp() + handler_dir = os.path.join(tempd, "hdir") + data = None # the 'init' object + frequency = PER_INSTANCE + + paths = helpers.Paths({}) + + # make a '#include <f1>' style + udproc = ud.UserDataProcessor(paths=paths) + user_data_msg = udproc.process("#include\n" + + '\n'.join([os.path.abspath(f) for f in args.files])) + + ccph = cc_part.CloudConfigPartHandler(paths=paths) + ccph.cloud_fn = outfile + + c_handlers = helpers.ContentHandlers() + c_handlers.register_defaults([ccph]) + + called = [] + for (_ctype, mod) in c_handlers.iteritems(): + if mod in called: + continue + handlers.call_begin(mod, data, frequency) + called.append(mod) + + # Walk the user data + part_data = { + 'handlers': c_handlers, + # Any new handlers that are encountered get writen here + 'handlerdir': handler_dir, + 'data': data, + # The default frequency if handlers don't have one + 'frequency': frequency, + # This will be used when new handlers are found + # to help write there contents to files with numbered + # names... + 'handlercount': 0, + } + + handlers.walk(user_data_msg, handlers.walker_callback, data=part_data) + + # Give callbacks opportunity to finalize + called = [] + for (_ctype, mod) in c_handlers.iteritems(): + if mod in called: + continue + handlers.call_end(mod, data, frequency) + called.append(mod) + + shutil.rmtree(tempd) + +if __name__ == "__main__": + main() + +# vi: ts=4 expandtab |