Commit f2ab0a0d authored by Attila Farkas's avatar Attila Farkas
Browse files

add interface naming

parent a3bd9a96
......@@ -64,6 +64,10 @@ Flavors provide a quick way to choose hardware specs (like number of cpus and me
| csirtmu.jumbo16x32 | 16 | 32768 |
| csirtmu.jumbo16x64 | 16 | 65536 |
### Interface names and supported boxes
The name of the correct network interface can be different for every box. The supported boxes are listed in the file name_mappings/interface.yml. If your box is not on the list, the most common "eth1" will be used. If you get an error during `$ vagrant up` about non-existing network interface, you can add the name of your box and the correct network interface to the list manually.
### Implemented attribute types:
- all simple vagrant attributes
- flavors, memory, cpus
......
......@@ -15,3 +15,4 @@ device_definitions = open_file(str(sys.argv[1]))
generate_vagrantfile(device_definitions)
generate_ansible_files(device_definitions)
from modules.device_creator import open_file
INTERFACE_FILE = "name_mapping/interface.yml"
def create_network_map(net_mappings, router_mappings):
""" Creates a structure with network topology for Jinja2 template. """
......@@ -18,7 +22,18 @@ def _find_router_ip(network_name, router_mappings):
return router_mapping["ip"]
def create_host_map(net_mappings, router_mappings):
def _find_interface(host_name, hosts):
for host in hosts:
if host["name"] == host_name:
interfaces = open_file(INTERFACE_FILE)
if host["base_box"] in interfaces:
return interfaces[host["base_box"]]
return "eth1"
def create_host_map(net_mappings, router_mappings, host_list):
""" Creates a structure with hosts and their primary routers ip """
hosts = []
......@@ -29,5 +44,6 @@ def create_host_map(net_mappings, router_mappings):
host["host_ip"] = net_mapping["ip"]
host["router_ip"] = _find_router_ip(
net_mapping["network"], router_mappings)
host["interface"] = _find_interface(net_mapping["host"], host_list)
hosts.append(host)
return hosts
......@@ -72,7 +72,7 @@ def _generate_playbook():
def _generate_device_configuration(definitions):
""" Generates a playbook with basic device configutarion. """
host_map = create_host_map(definitions["net_mappings"], definitions["router_mappings"])
host_map = create_host_map(definitions["net_mappings"], definitions["router_mappings"], definitions["hosts"])
network = create_network_map(
definitions["net_mappings"], definitions["router_mappings"])
......@@ -90,7 +90,7 @@ def _generate_device_configuration(definitions):
def _generate_hosts_role(definitions):
""" Generates hosts role. """
host_map = create_host_map(definitions["net_mappings"], definitions["router_mappings"])
host_map = create_host_map(definitions["net_mappings"], definitions["router_mappings"], definitions["hosts"])
network = create_network_map(
definitions["net_mappings"], definitions["router_mappings"])
......@@ -109,7 +109,7 @@ def _generate_routers_role(definitions):
print("Info: No router definition was found. Skipping router creation.")
return
host_map = create_host_map(definitions["net_mappings"], definitions["router_mappings"])
host_map = create_host_map(definitions["net_mappings"], definitions["router_mappings"], definitions["hosts"])
network = create_network_map(
definitions["net_mappings"], definitions["router_mappings"])
......
kalilinux/rolling-light: eth1
xubuntu-16.04-desktop-amd64: eth1
ubuntu/xenial64: enp0s8
......@@ -13,7 +13,7 @@
become: yes
tasks:
- name: Change default gateway
command: route add default gw {{ host.router_ip }} eth1
command: route add default gw {{ host.router_ip }} {{ host.interface }}
{% endfor %}
- name: Configuring all routers
......
name: small-sandbox
hosts:
- name: server
base_box: kalilinux/rolling-light
base_box: ubuntu/xenial64
flavor: csirtmu.tiny1x4
cpus: 2
- name: home
base_box: kalilinux/rolling-light
base_box: ubuntu/xenial64
boot_timeout: 1000
box_check_update: false
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment