From 7e5088a7edd5cf6c588fa90ba5c60b82acc02f9e Mon Sep 17 00:00:00 2001 From: Attila Farkas <x394097@fi.muni.cz> Date: Wed, 22 Apr 2020 10:36:37 +0200 Subject: [PATCH] change verbosity level to vvvv --- modules/input_argument_parser.py | 2 +- modules/vagrant_generator.py | 39 ++++++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/modules/input_argument_parser.py b/modules/input_argument_parser.py index f4eabad..800fba0 100644 --- a/modules/input_argument_parser.py +++ b/modules/input_argument_parser.py @@ -16,7 +16,7 @@ def parse_input_args(argv, flags): parser.add_argument("definition_file", help="path to the input yaml definition") parser.add_argument("--ansible_local", help="uses ansible_local for provisioning instead of ansible", action="store_true") - parser.add_argument("--verbose_ansible", help="sets verbose output for ansible", action="store_true") + parser.add_argument("--verbose_ansible", help="sets verbose output for ansible (-vvvv)", action="store_true") parser.add_argument("--border_router", help="creates a border router with connection to all routers", action="store_true") args = parser.parse_args() diff --git a/modules/vagrant_generator.py b/modules/vagrant_generator.py index fd01571..00801b5 100644 --- a/modules/vagrant_generator.py +++ b/modules/vagrant_generator.py @@ -21,6 +21,22 @@ def _create_simple_attribute(key, value, attribute_type): return attribute +def _create_complex_attribute(key, value): + """ Creates complex vagrant attributes that are not string, integer or + boolean. + """ + + SEPARATORS = {VAGRANT_MAPPING["other"]["synced_folder"]: ""} + + attribute = dict() + attribute["type"] = "other" + attribute["command"] = key + attribute["separator"] = SEPARATORS[key] + attribute["value"] = value + + return attribute + + def _create_commands(device_attributes, device_type, input_definitions, flags): """ This function creates basic vagrant definition commands for a device. """ @@ -34,6 +50,8 @@ def _create_commands(device_attributes, device_type, input_definitions, flags): commands.append(_create_simple_attribute(VAGRANT_MAPPING["boolean"][attribute], value, "boolean")) elif attribute in VAGRANT_MAPPING["integer"]: commands.append(_create_simple_attribute(VAGRANT_MAPPING["integer"][attribute], value, "integer")) + elif attribute in VAGRANT_MAPPING["other"]: + commands.append(_create_complex_attribute(VAGRANT_MAPPING["other"][attribute], value)) elif attribute in VIRTUALBOX_MAPPING["integer"]: vb_commands.append(_create_simple_attribute(VIRTUALBOX_MAPPING["integer"][attribute], value, "integer")) @@ -60,25 +78,32 @@ def _create_ansible_commands(playbook_location, input_definitions, flags): if "verbose_ansible" in flags and flags["verbose_ansible"]: verbosity = dict() - verbosity["type"] = "boolean" + verbosity["type"] = "string" verbosity["command"] = "verbose" - verbosity["value"] = True + verbosity["value"] = "vvvv" commands.append(verbosity) groups = dict() - groups["type"] = "dictionary" - groups["command"] = "groups" - groups["dictionary"] = dict() + groups["type"] = "groups" + groups["groups"] = dict() host_names = [] for host in input_definitions["hosts"]: host_names.append(host["name"]) - groups["dictionary"]["hosts"] = host_names + groups["groups"]["hosts"] = host_names router_names = [] for router in input_definitions["routers"]: router_names.append(router["name"]) - groups["dictionary"]["routers"] = router_names + groups["groups"]["routers"] = router_names commands.append(groups) + if "ansible_local" in flags and flags["ansible_local"]: + extravars = dict() + extravars["type"] = "dictionary" + extravars["command"] = "extra_vars" + extravars["dictionary"] = dict() + extravars["dictionary"]["ansible_python_interpreter"] = "\"/usr/bin/python3\"" + commands.append(extravars) + return commands -- GitLab