diff --git a/README.md b/README.md index 59013688a6de972f9375b44408b07df36db9fa0f..0863232a32cea9ab367602e043966f424f326ed1 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ generate.py is a python program that generates a vagrant source file from a defi ### Usage: 1. Clone the project. 2. Navigate to the project folder. -3. Type `$ python generate.py yaml_file.yaml > Vagrantfile`. There is a test yaml file in the repository called test.yaml. +3. Type `$ python generate.py yaml_file.yaml`. There is a test yaml file in the repository called test.yaml. 4. Run `$ vagrant up` ### Implemented attribute types: diff --git a/generate.py b/generate.py index 58c5be94d6555015164fed234ef3b4d1fa7d98af..99a0a6af88d29d4274a65a8703c49b11ec68897d 100644 --- a/generate.py +++ b/generate.py @@ -4,7 +4,7 @@ import sys import jinja2 -from modules.device_creator import create_devices +from modules.device_creator import create_devices, create_vagrantfile if len(sys.argv) != 2: print("Error: Expecting 1 argument (yml file).") @@ -19,4 +19,4 @@ TEMPLATE_ENV = jinja2.Environment(loader=TEMPLATE_LOADER, trim_blocks=True) BASE_TEMPLATE = TEMPLATE_ENV.get_template("base") OUTPUT = BASE_TEMPLATE.render(devices=DEVICES) -print(OUTPUT) +create_vagrantfile(OUTPUT) diff --git a/modules/device_creator.py b/modules/device_creator.py index ae7e9362df4d1bee460befc77530aa3b43ee9e10..c34937dadfcaf5e05ed72064d10449210ea908eb 100644 --- a/modules/device_creator.py +++ b/modules/device_creator.py @@ -57,3 +57,16 @@ def create_devices(yml_file_name): return { **_create_hosts(yml, mappings, flavors), **_create_routers(yml)} + + +def create_vagrantfile(output): + """ Writes the prepared output to a Vagrantfile. """ + filename = "Vagrantfile" + + try: + vagrantfile = open(filename, "w") + vagrantfile.write(output) + except IOError: + print("Error: cannot write to this location.") + + print("Vagrantfile successfully created.")