Skip to content
Snippets Groups Projects
Commit a247e4a0 authored by Attila Farkas's avatar Attila Farkas
Browse files

Vagrantfile is created directly

parent 71b758f4
No related branches found
No related tags found
1 merge request!2Resolve "Add routing"
......@@ -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:
......
......@@ -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)
......@@ -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.")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment