re-factor of interface config compile process
This commit is contained in:
parent
4a89aa2c93
commit
347291d1a9
|
@ -22,7 +22,11 @@ case "$1" in
|
||||||
configure)
|
configure)
|
||||||
|
|
||||||
|
|
||||||
### START gather all the info from the box and generate the variabels
|
## START gather all the info from the box and generate the variabels
|
||||||
|
|
||||||
|
|
||||||
|
IFCONFIG="/etc/network/interfaces"
|
||||||
|
UDEVCONFIG="/etc/udev/rules.d/70-persistent-net.rules"
|
||||||
|
|
||||||
export LOOPBACKv4=$(dig a +short ${HOSTNAME})
|
export LOOPBACKv4=$(dig a +short ${HOSTNAME})
|
||||||
export LOOPBACKv6=$(dig aaaa +short ${HOSTNAME})
|
export LOOPBACKv6=$(dig aaaa +short ${HOSTNAME})
|
||||||
|
@ -36,34 +40,33 @@ case "$1" in
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
declare -A MACS
|
|
||||||
for if in mgmt feth1 feth2 feth3 fet4 up1 up2 up3 up4 ibgp1 ibgp2 ibgp3 ibgp4
|
|
||||||
do
|
|
||||||
MACS["$if"]=$(dig txt +short mac.$if.$HOSTNAME) ## careful mac will be wrapped in quotes, but we don't care since we'll need it again wrapped in quotes (so far)
|
|
||||||
done
|
|
||||||
|
|
||||||
## END variables
|
## END variables
|
||||||
|
|
||||||
|
|
||||||
## START writing config files
|
|
||||||
|
## START nic config compile
|
||||||
|
|
||||||
|
|
||||||
# write udev rules for device names
|
# gathering supported interfaces
|
||||||
for if in ${!MACS[@]}
|
declare -A MACS
|
||||||
|
MACS["mgmt1"]=$(dig txt +short mac.mgmt.${HOSTNAME})
|
||||||
|
for if in feth up ibgp
|
||||||
do
|
do
|
||||||
ifmac=${MACS[$if]}
|
for i in {1..9}
|
||||||
[ "$if" == "mgmt" ] && if=mgmt1
|
do
|
||||||
[ -z "$ifmac" ] || echo 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=='$ifmac', ATTR{type}=="1", NAME="'${if}'"'
|
MACS["${if}${i}"]=$(dig txt +short mac.${if}${i}.${HOSTNAME})
|
||||||
done >/etc/udev/rules.d/70-persistent-net.rules
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
# wiping existing config in prep for de-deploying it
|
||||||
|
mv -f ${IFCONFIG} ${IFCONFIG}.dpkg-old || true
|
||||||
|
mv -f ${UDEVCONFIG} ${UDEVCONFIG}.dpkg-old || true
|
||||||
|
|
||||||
# set network interface configurations
|
|
||||||
|
# write loopback config
|
||||||
cat <<-EOF >/etc/network/interfaces
|
cat <<-EOF >/etc/network/interfaces
|
||||||
source-directory /etc/network/interfaces.d
|
|
||||||
EOF
|
|
||||||
|
|
||||||
cat <<-EOF >/etc/network/interfaces.d/lo
|
|
||||||
auto lo
|
auto lo
|
||||||
iface lo inet loopback
|
iface lo inet loopback
|
||||||
|
|
||||||
|
@ -74,27 +77,74 @@ case "$1" in
|
||||||
address ${LOOPBACKv6}/128
|
address ${LOOPBACKv6}/128
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
cat <<-"EOF" >/etc/network/interfaces.d/mgmt1
|
|
||||||
auto mgmt1
|
for if in ${!MACS[@]}
|
||||||
iface mgmt1 inet dhcp
|
do
|
||||||
|
[ -z ${MACS[$if]} ] && continue ## skip undefined interfaces
|
||||||
|
|
||||||
|
echo 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=='${MACS[$if]}', ATTR{type}=="1", NAME="'${if}'"' >>$UDEVCONFIG
|
||||||
|
|
||||||
|
|
||||||
|
if [[ $if = feth? ]]; then
|
||||||
|
cat <<-EOF >>$IFCONFIG
|
||||||
|
auto $if
|
||||||
|
iface $if inet manual
|
||||||
|
mtu 9000
|
||||||
|
|
||||||
|
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
if [[ $if = mgmt? ]]; then
|
||||||
|
cat <<-EOF >>$IFCONFIG
|
||||||
|
auto $if
|
||||||
|
iface $if inet6 auto
|
||||||
|
iface $if inet dhcp
|
||||||
pre-up /bin/ip link add mgmt type vrf table mgmt
|
pre-up /bin/ip link add mgmt type vrf table mgmt
|
||||||
pre-up /bin/ip link set up dev mgmt
|
pre-up /bin/ip link set up dev mgmt
|
||||||
pre-up /bin/ip link set master mgmt dev mgmt1
|
pre-up /bin/ip link set master mgmt dev $if
|
||||||
post-down /bin/ip link del dev mgmt
|
post-down /bin/ip link del dev mgmt
|
||||||
iface mgmt1 inet6 auto
|
|
||||||
EOF
|
|
||||||
|
|
||||||
cat <<-"EOF" >/etc/network/interfaces.d/feth
|
|
||||||
auto feth1
|
EOF
|
||||||
iface feth1 inet manual
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
if [[ $if = ibgp? ]]; then
|
||||||
|
cat <<-EOF >>$IFCONFIG
|
||||||
|
auto $if
|
||||||
|
iface $if inet manual
|
||||||
mtu 9000
|
mtu 9000
|
||||||
|
|
||||||
auto feth2
|
|
||||||
iface feth2 inet manual
|
|
||||||
mtu 9000
|
|
||||||
EOF
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
if [[ $if = up? ]]; then
|
||||||
|
cat <<-EOF >>$IFCONFIG
|
||||||
|
auto $if
|
||||||
|
iface $if inet static
|
||||||
|
address $(dig txt +short ipv4.$if.$HOSTNAME)
|
||||||
|
mtu 9000
|
||||||
|
iface $if inet6 static
|
||||||
|
address $(dig txt +short ipv6.$if.$HOSTNAME)
|
||||||
|
|
||||||
|
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
## START nic config compile
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## START writing config files
|
||||||
|
|
||||||
|
|
||||||
# set frr config
|
# set frr config
|
||||||
|
|
Loading…
Reference in New Issue