From 13fbc9d5724af1ac0e80a1d093a105f863f3b70d Mon Sep 17 00:00:00 2001 From: root Date: Thu, 9 Aug 2018 10:18:19 +0000 Subject: [PATCH] I may come close to the full support finally --- debian/control | 2 +- debian/wit-network-config.install | 1 + debian/wit-network-config.postinst | 25 +++++++++---------------- debian/wit-network-config.preinst | 9 +++++++++ debian/wit-network-config.transform | 2 +- files/dhcp-loopback | 6 +++--- 6 files changed, 24 insertions(+), 21 deletions(-) diff --git a/debian/control b/debian/control index 2549ae0..7ceaadf 100644 --- a/debian/control +++ b/debian/control @@ -9,7 +9,7 @@ Vcs-Git: https://git.wit.com/netops/wit-network-config Package: wit-network-config Architecture: all -Depends: ${misc:Depends}, frr (>= 4.0-wit), sed, tcpdump, mtr-tiny, iproute2, ifupdown, ipmitool, iptables, lldpd, strongswan, telnet, netcat, fping, curl, wget, ifstat, rsyslog, ncurses-term, net-tools, bridge-utils, vlan, gnupg, sudo, isc-dhcp-client +Depends: ${misc:Depends}, sed, tcpdump, mtr-tiny, iproute2, ifupdown, ipmitool, iptables, lldpd, strongswan, telnet, netcat, fping, curl, wget, ifstat, rsyslog, ncurses-term, net-tools, bridge-utils, vlan, gnupg, sudo, isc-dhcp-client Provides: ${diverted-files} Conflicts: ${diverted-files}, dhcpcd5 Description: configure network for a standard wit compute and/or data node diff --git a/debian/wit-network-config.install b/debian/wit-network-config.install index 2473510..c3e0ef5 100644 --- a/debian/wit-network-config.install +++ b/debian/wit-network-config.install @@ -2,6 +2,7 @@ files/vrf.conf etc/iproute2/rt_tables.d files/vrf-dhcp-enter etc/dhcp/dhclient-enter-hooks.d files/vrf-dhcp-exit etc/dhcp/dhclient-exit-hooks.d files/dhcp-sethostname etc/dhcp/dhclient-exit-hooks.d +files/dhcp-loopback etc/dhcp/dhclient-exit-hooks.d files/rc.local etc files/10-frr.conf etc/sysctl.d files/11-mgmt1.conf etc/sysctl.d diff --git a/debian/wit-network-config.postinst b/debian/wit-network-config.postinst index 5b9eb6e..40bdd87 100755 --- a/debian/wit-network-config.postinst +++ b/debian/wit-network-config.postinst @@ -24,24 +24,16 @@ case "$1" in ### START gather all the info from the box and generate the variabels + source /etc/wit-net.conf + if [ -z $LOOPBACKv4 ]; then + echo "LOOPBACK not provided by DHCP" + exit 2 + fi - - [ -z $NODE_ID ] && export NODE_ID=$(ip -4 -br addr | grep 10.0. | awk '{ print $3 }' | awk 'BEGIN{FS="[./]"} { print $4 }') + export TIER_ID=$(echo $LOOPBACKv4 | cut -d . -f 3) + export NODE_ID=$(echo $LOOPBACKv4 | cut -d . -f 4) export DOMAINNAME=${HOSTNAME#*.} - export MGMT_MAC=$(ip -br link show dev $(ip -4 -br addr | grep 10.0. | awk '{ print $1 }') | awk '{ print $3 }') - - - [ ${HOSTNAME:0:4} = vtep ] && export HOSTTYPE=hypervisor - [ ${HOSTNAME:0:1} = h ] && export HOSTTYPE=hypervisor - [ ${HOSTNAME:0:1} = d ] && export HOSTTYPE=datanode - - [ $HOSTTYPE = hypervisor -a $DOMAINNAME = usw1.wit.com ] && export TIER_ID=2 - [ $HOSTTYPE = datanode -a $DOMAINNAME = usw1.wit.com ] && export TIER_ID=4 - [ $HOSTTYPE = hypervisor -a $DOMAINNAME = usw2.wit.com ] && export TIER_ID=18 - [ $HOSTTYPE = datanode -a $DOMAINNAME = usw2.wit.com ] && export TIER_ID=20 - - [ $HOSTTYPE != hypervisor -a $HOSTTYPE != datanode ] && sed -ie "s/^TIER_ID.*/TIER_ID=$TIER_ID/; t; $ s/$/\nTIER_ID=$TIER_ID/" /etc/environment if [ -z "$TIER_ID" ]; then echo "Unable to autodetect TIER_ID, looks like we deal with a special node, please set in environment" @@ -53,9 +45,10 @@ case "$1" in fi export NODE_ASN="4200$(printf "%03d" $TIER_ID)$(printf "%03d" $NODE_ID)" - export LOOPBACKv4="10.1.$TIER_ID.$NODE_ID" export LOOPBACKv6="2604:bbc0::$TIER_ID:$NODE_ID" + MGMT_MAC=$(ip -br link show dev $(ip -4 -br addr | grep 10.0. | awk '{ print $1 }') | awk '{ print $3 }') + ## END variables diff --git a/debian/wit-network-config.preinst b/debian/wit-network-config.preinst index 8d116d0..af5be85 100755 --- a/debian/wit-network-config.preinst +++ b/debian/wit-network-config.preinst @@ -16,6 +16,15 @@ set -e case "$1" in install|upgrade) + source /etc/wit-net.conf + if [ -z $LOOPBACKv4 ]; then + echo "LOOPBACK NOT CONFIGURED, aborting..." + exit 2 + fi + if [[ $LOOPBACKv4 = "10.1."* ]]; then + echo "only 10.1.x.y loopbacks supported at the moment" + exit 3 + fi systemctl stop systemd-networkd.socket systemctl stop systemd-networkd.service systemctl stop systemd-networkd-wait-online diff --git a/debian/wit-network-config.transform b/debian/wit-network-config.transform index 111baac..76809bf 100644 --- a/debian/wit-network-config.transform +++ b/debian/wit-network-config.transform @@ -1,4 +1,4 @@ /etc/systemd/timesyncd.conf.wit sed -e 's/#NTP=.*/NTP=ipv6.ntp.ubuntu.com/g' /etc/frr/daemons.wit sed -e 's/bgpd=no/bgpd=yes/' -e 's/zebra=no/zebra=yes/' /etc/bash.bashrc.wit sed -e 's/.*witaddon/source \/etc\/bashrc-witaddon/; t; $ s/$/\nsource \/etc\/bashrc-witaddon/' -/etc/dhcp/dhclient.conf.wit sed -e '/option.*tier-id/d;t;1s/^/option tier-id code 225 = unsigned integer 8;\n/' +/etc/dhcp/dhclient.conf.wit sed -e '/^option.*loopbackv4/d;' | sed -e '1s/^/option loopbackv4 code 225 = ip-address;\n/;' diff --git a/files/dhcp-loopback b/files/dhcp-loopback index a08ea0f..e683149 100755 --- a/files/dhcp-loopback +++ b/files/dhcp-loopback @@ -1,6 +1,6 @@ #!/bin/bash +sed -ie '/^LOOPBACKv4.*/d' /etc/wit-net.conf -if [ ! -z $new_tier_id ]; then - sed -ie '/^TIER_ID=.*/d' /etc/environment - echo "TIER_ID=$new_tier_id" >>/etc/environment +if [ ! -z $new_loopbackv4 ]; then + echo "LOOPBACKv4=$new_loopbackv4" >>/etc/wit-net.conf fi