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

add interface naming

parent a3bd9a96
No related branches found
No related tags found
No related merge requests found
...@@ -64,6 +64,10 @@ Flavors provide a quick way to choose hardware specs (like number of cpus and me ...@@ -64,6 +64,10 @@ Flavors provide a quick way to choose hardware specs (like number of cpus and me
| csirtmu.jumbo16x32 | 16 | 32768 | | csirtmu.jumbo16x32 | 16 | 32768 |
| csirtmu.jumbo16x64 | 16 | 65536 | | 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: ### Implemented attribute types:
- all simple vagrant attributes - all simple vagrant attributes
- flavors, memory, cpus - flavors, memory, cpus
......
...@@ -15,3 +15,4 @@ device_definitions = open_file(str(sys.argv[1])) ...@@ -15,3 +15,4 @@ device_definitions = open_file(str(sys.argv[1]))
generate_vagrantfile(device_definitions) generate_vagrantfile(device_definitions)
generate_ansible_files(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): def create_network_map(net_mappings, router_mappings):
""" Creates a structure with network topology for Jinja2 template. """ """ Creates a structure with network topology for Jinja2 template. """
...@@ -18,7 +22,18 @@ def _find_router_ip(network_name, router_mappings): ...@@ -18,7 +22,18 @@ def _find_router_ip(network_name, router_mappings):
return router_mapping["ip"] 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 """ """ Creates a structure with hosts and their primary routers ip """
hosts = [] hosts = []
...@@ -29,5 +44,6 @@ def create_host_map(net_mappings, router_mappings): ...@@ -29,5 +44,6 @@ def create_host_map(net_mappings, router_mappings):
host["host_ip"] = net_mapping["ip"] host["host_ip"] = net_mapping["ip"]
host["router_ip"] = _find_router_ip( host["router_ip"] = _find_router_ip(
net_mapping["network"], router_mappings) net_mapping["network"], router_mappings)
host["interface"] = _find_interface(net_mapping["host"], host_list)
hosts.append(host) hosts.append(host)
return hosts return hosts
...@@ -72,7 +72,7 @@ def _generate_playbook(): ...@@ -72,7 +72,7 @@ def _generate_playbook():
def _generate_device_configuration(definitions): def _generate_device_configuration(definitions):
""" Generates a playbook with basic device configutarion. """ """ 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( network = create_network_map(
definitions["net_mappings"], definitions["router_mappings"]) definitions["net_mappings"], definitions["router_mappings"])
...@@ -90,7 +90,7 @@ def _generate_device_configuration(definitions): ...@@ -90,7 +90,7 @@ def _generate_device_configuration(definitions):
def _generate_hosts_role(definitions): def _generate_hosts_role(definitions):
""" Generates hosts role. """ """ 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( network = create_network_map(
definitions["net_mappings"], definitions["router_mappings"]) definitions["net_mappings"], definitions["router_mappings"])
...@@ -109,7 +109,7 @@ def _generate_routers_role(definitions): ...@@ -109,7 +109,7 @@ def _generate_routers_role(definitions):
print("Info: No router definition was found. Skipping router creation.") print("Info: No router definition was found. Skipping router creation.")
return 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( network = create_network_map(
definitions["net_mappings"], definitions["router_mappings"]) definitions["net_mappings"], definitions["router_mappings"])
......
kalilinux/rolling-light: eth1
xubuntu-16.04-desktop-amd64: eth1
ubuntu/xenial64: enp0s8
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
become: yes become: yes
tasks: tasks:
- name: Change default gateway - name: Change default gateway
command: route add default gw {{ host.router_ip }} eth1 command: route add default gw {{ host.router_ip }} {{ host.interface }}
{% endfor %} {% endfor %}
- name: Configuring all routers - name: Configuring all routers
......
name: small-sandbox name: small-sandbox
hosts: hosts:
- name: server - name: server
base_box: kalilinux/rolling-light base_box: ubuntu/xenial64
flavor: csirtmu.tiny1x4 flavor: csirtmu.tiny1x4
cpus: 2 cpus: 2
- name: home - name: home
base_box: kalilinux/rolling-light base_box: ubuntu/xenial64
boot_timeout: 1000 boot_timeout: 1000
box_check_update: false box_check_update: false
......
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