Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
""" This module generates a Vagrantfile from input device definitions. """
def _create_commands(device_name, device_type, input_definitions, flags):
""" This function creates basic vagrant definition commands for a device. """
# TODO create vagrant commands
def _build_vagrant_definitions(input_definitions, flags):
"""
Creates a definition structure that is more suitable for Vagrantfile
generation than input definitions.
"""
vagrant_definitions = []
for router in input_definitions["routers"]:
device = dict()
device["device_name"] = router["name"]
device["device_type"] = "router"
device["commands"] = _create_commands(router["name"], "router", input_definitions, flags)
vagrant_definitions.append(device)
for host in input_definitons["hosts"]:
device = dict()
device["device_name"] = host["name"]
device["device_type"] = "host"
device["commands"] = _create_commands(host["name"], "host", input_definitions, flags)
vagrant_definitions.append(device)
return vagrant_definitions
def generate_vagrantfile(input_definitions, flags):
"""
This method is responsible for Vagrantfile generation.
:param input_definitions: device definitions from the input file
:param flags: command line flags
"""
try:
vagrant_definitions = _build_vagrant_definitions(input_definitions, flags)
except Exception:
print("Could not create definitions for Vagrantfile.")
raise
# TODO build Vagrantfile using a template