From ee38a5e536570c73f72cd9cb45a9a6c42f84f041 Mon Sep 17 00:00:00 2001
From: Attila Farkas <ati@mail.muni.cz>
Date: Thu, 20 Feb 2020 13:43:18 +0100
Subject: [PATCH] finalize create

---
 create.py                 | 20 ++++++++++++--------
 modules/file_generator.py | 37 ++++++++++++++++++++++++++-----------
 2 files changed, 38 insertions(+), 19 deletions(-)

diff --git a/create.py b/create.py
index 7d22f65..1b6c65f 100644
--- a/create.py
+++ b/create.py
@@ -43,12 +43,16 @@ except Exception:
     print("Preprocessing was not successful.")
     sys.exit(1)
 
+""" Generating Vagrantfile. """
+try:
+    generate_vagrantfile(device_definitions, flags)
+except Exception:
+    print("Vagrantfile was not created.")
+    sys.exit(1)
 
-# TODO
-
-if "ansible_local" in flags and flags["ansible_local"]:
-    generate_vagrantfile(device_definitions, True)
-else:
-    generate_vagrantfile(device_definitions, False)
-
-generate_ansible_files(device_definitions)
+""" Generating ansible playbooks. """
+try:
+    generate_ansible_files(device_definitions, flags)
+except Exception:
+    print("Playbooks could not be created.")
+    sys.exit(1)
diff --git a/modules/file_generator.py b/modules/file_generator.py
index 0a415bf..dc5c932 100644
--- a/modules/file_generator.py
+++ b/modules/file_generator.py
@@ -54,9 +54,19 @@ def _find_user_ansible_files(definitions):
 
     return host_names
 
-def generate_vagrantfile(definitions, ansible_local):
-    """ Writes the prepared output to a Vagrantfile. """
-   
+def generate_vagrantfile(definitions, flags):
+    """
+    Creates Vagrantfile from definitions.
+
+    :param definitions: device definitions structure
+    :param flags: command line input flags
+    """
+    
+    if "ansible_local" in flags and flags["ansible_local"]:
+        ansible_local = True
+    else:
+        ansible_local = False
+
     device_definitions = create_devices(definitions, ansible_local)
     user_ansible_files = _find_user_ansible_files(definitions)
     template = _load_template("vagrantfile")
@@ -204,14 +214,19 @@ def _generate_br_role(definitions):
     _generate_file("./base_provisioning/roles/br/tasks/main.yml", output)
 
 
-def generate_ansible_files(device_definitions):
-    """ Generates files for ansible. """
+def generate_ansible_files(definitions, flags):
+    """
+    Generates ansible playbooks.
+
+    :param definitions: device definitions structure
+    :param flags: command line input flags
+    """ 
     
-    _generate_playbook(device_definitions)
-    _generate_device_configuration(device_definitions)
-    _generate_hosts_role(device_definitions)
-    _generate_separate_hosts_role(device_definitions)
-    _generate_routers_role(device_definitions)
-    _generate_br_role(device_definitions)
+    _generate_playbook(definitions)
+    _generate_device_configuration(definitions)
+    _generate_hosts_role(definitions)
+    _generate_separate_hosts_role(definitions)
+    _generate_routers_role(definitions)
+    _generate_br_role(definitions)
 
     print("Info: Ansible files successfully created.")
-- 
GitLab