From c0f9174ab69269696ad6a9f697d5be9071bf4d66 Mon Sep 17 00:00:00 2001 From: Pavel 'LEdoian' Turinsky Date: Tue, 22 Mar 2022 02:04:12 +0100 Subject: [PATCH] Add initial version of template files --- templates/bird.conf | 29 ++++++++++++++++++++++++++++ templates/interfaces | 19 ++++++++++++++++++ templates/qemu.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 templates/bird.conf create mode 100644 templates/interfaces create mode 100755 templates/qemu.sh diff --git a/templates/bird.conf b/templates/bird.conf new file mode 100644 index 0000000..ce77243 --- /dev/null +++ b/templates/bird.conf @@ -0,0 +1,29 @@ +log syslog all; +debug protocols all; +router id 172.23.100.{{c.num}}; +protocol device { } +protocol direct { disabled; } +protocol kernel { + ipv4 { + preference 100; + import none; + export all; + }; +} + +protocol ospf v3 { + ipv4 { + preference 10; + import all; + export all; + }; + area 0 { + {% for br in c.bridges %} + interface "net_{{br.num}}" { + cost 10; + type broadcast; + }; + {% endfor %} + }; +} + diff --git a/templates/interfaces b/templates/interfaces new file mode 100644 index 0000000..cf2bb48 --- /dev/null +++ b/templates/interfaces @@ -0,0 +1,19 @@ +auto lo +iface lo inet loopback + +{# auto {% for x in range(len(c.bridges)) %} eth{{x}} {% endfor %} #} +auto /eth* +mapping eth* + script TODO/get-mac-address.sh + {% for br in c.bridges %} + map 52:54:00:17:{{ '%02x:%02x' % (c.num, br.num) }} net_{{br.num}} + {% endfor %} + +{% for br in c.bridges %} +iface net_{{br.num}} inet static + address 172.23.{{ br.num }}.{{ c.num }}/24 + +{% endfor %} + + + diff --git a/templates/qemu.sh b/templates/qemu.sh new file mode 100755 index 0000000..7cfeec4 --- /dev/null +++ b/templates/qemu.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +# This is my QEMU starting script, copied over and over. + +set -euo pipefail + +# KNOWN BUG: We cannot override options from command line +# -> Easy fix would be to disallow spaces OR single quotes in options, but IMHO not worth + +CONFIG=' + +# Basics: +name {{ c.name }} +m 20M +{# enable-kvm #} + +# Boot drive (BIOS) +drive media=disk,file=./disk.img,format=raw + +# Monitor on dedicated socket +monitor unix:./monitor.sock,server,nowait + +spice unix=on,addr=./spice.sock,disable-copy-paste=on,seamless-migration=off,disable-ticketing=on +display none # Already handled by SPICE + +# NIC: attach to bridges: +{% for br in c.bridges %} +nic bridge,br={{ br.name }},model=virtio-net-pci,mac=52:54:00:17:{{ '%02x%02x' % (c.num, br.num) }} +{% endfor %} +' + + +strip() { + sed -e ' +s/^[ ]*// +s/[ ]*$// + +s/[ ]*#.*$// + +/^$/d + +' +} + +# Now QEMU is in foreground +strip <<<"$CONFIG" | while read option params; do echo "-$option"; test -n "$params" && echo "$params"; done | xargs qemu-system-x86_64 "$@"