From 5a301c48160bf8fe62112dfef2e3338497cb9fe5 Mon Sep 17 00:00:00 2001 From: Attila Farkas <394097@mail.muni.cz> Date: Tue, 30 Jun 2020 07:40:50 +0000 Subject: [PATCH] Revert "add usage graphics" This reverts commit 73516ffbc9a35bf580ced1f4d6e35154b5ad5e4c --- create.py | 2 +- modules/ansible_generator.py | 19 +++++++++++++++---- modules/file_manager.py | 16 +++++++++++----- modules/input_argument_parser.py | 4 ++++ 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/create.py b/create.py index 19ba767..1cdec4d 100644 --- a/create.py +++ b/create.py @@ -18,7 +18,7 @@ device_definitions = open_yaml(INPUT_FILE_NAME) validate_device_definitions(device_definitions) preprocess(device_definitions, FLAGS) -prepare_directories(device_definitions) +prepare_directories(device_definitions, FLAGS) generate_vagrantfile(device_definitions, FLAGS) generate_playbooks(device_definitions, FLAGS) diff --git a/modules/ansible_generator.py b/modules/ansible_generator.py index 182456d..74fd818 100644 --- a/modules/ansible_generator.py +++ b/modules/ansible_generator.py @@ -1,6 +1,7 @@ """Contain functions for ansible file generation.""" -from modules.file_manager import generate_file, copy_template_file +from modules.file_manager import generate_file, copy_template_file,\ + copy_user_provisioning_dir from modules.ansible_vars_generator import generate_ansible_vars from conf.border_router import BORDER_ROUTER_NAME @@ -27,8 +28,9 @@ def _create_config_playbooks(input_definitions, flags): device["name"] + "/tasks/main.yml") -def _create_user_playbooks(input_definitions): - """Generate template playbooks and roles for users.""" +def _generate_user_playbooks(input_definitions): + """Generate example user playbooks.""" + copy_template_file("playbook", "provisioning/playbook.yml") if input_definitions["hosts"]: copy_template_file("user_hosts", @@ -48,6 +50,15 @@ def _create_user_playbooks(input_definitions): "/tasks/main.yml", router_name=router["name"]) +def _create_user_playbooks(input_definitions, flags): + """Copy or generate template playbooks and roles for users.""" + + if "provisioning_dir" in flags and flags["provisioning_dir"]: + copy_user_provisioning_dir(flags["provisioning_dir"]) + else: + _generate_user_playbooks(input_definitions) + + def generate_playbooks(input_definitions, flags): """Generate ansible vars and playbooks. @@ -56,4 +67,4 @@ def generate_playbooks(input_definitions, flags): """ generate_ansible_vars(input_definitions, flags) _create_config_playbooks(input_definitions, flags) - _create_user_playbooks(input_definitions) + _create_user_playbooks(input_definitions, flags) diff --git a/modules/file_manager.py b/modules/file_manager.py index 8b4a8b5..913c47e 100644 --- a/modules/file_manager.py +++ b/modules/file_manager.py @@ -81,7 +81,7 @@ def _load_template(template_name): def _copy_directory(source, destination): """Copy directory recursively form templates dir to the destination.""" try: - shutil.copytree("./templates/" + source, destination) + shutil.copytree(source, destination) except OSError: cleanup_and_exit("Could not copy directory " + str(source) + ".") @@ -124,7 +124,7 @@ def _create_provisioning_directories(directory, device_definitions): cleanup_and_exit("Could not create directories for provisioning.") -def prepare_directories(device_definitions): +def prepare_directories(device_definitions, flags): """Prepare the necessary directory structure.""" _remove_sandbox() @@ -135,14 +135,20 @@ def prepare_directories(device_definitions): ".") _create_provisioning_directories("base_provisioning", device_definitions) - _create_provisioning_directories("provisioning", device_definitions) + if "provisioning_dir" not in flags or not flags["provisioning_dir"]: + _create_provisioning_directories("provisioning", device_definitions) - _copy_directory("interface", OUTPUT_DIRECTORY + + _copy_directory("./templates/interface", OUTPUT_DIRECTORY + "/base_provisioning/roles/interface") - _copy_directory("common", OUTPUT_DIRECTORY + + _copy_directory("./templates/common", OUTPUT_DIRECTORY + "/base_provisioning/roles/common") +def copy_user_provisioning_dir(path): + """Copy provisioning files provided by the user to the correct dir.""" + _copy_directory(path, OUTPUT_DIRECTORY + "/provisioning") + + def _remove_sandbox(): """Remove the existing sandbox.""" shutil.rmtree(OUTPUT_DIRECTORY, True) diff --git a/modules/input_argument_parser.py b/modules/input_argument_parser.py index 7d5c43f..1964d8b 100644 --- a/modules/input_argument_parser.py +++ b/modules/input_argument_parser.py @@ -24,11 +24,15 @@ def parse_input_args(): parser.add_argument("--border_router", help="creates a border router with connection to " "all routers", action="store_true") + parser.add_argument("--provisioning_dir", + help="path to directory with user provisioning files", + action="store") args = parser.parse_args() input_file_name = args.definition_file flags["ansible_local"] = args.ansible_local flags["verbose_ansible"] = args.verbose_ansible flags["border_router"] = args.border_router + flags["provisioning_dir"] = args.provisioning_dir return input_file_name, flags -- GitLab