re-factor of interface config compile process
This commit is contained in:
parent
4a89aa2c93
commit
347291d1a9
|
@ -22,7 +22,11 @@ case "$1" in
|
|||
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 LOOPBACKv6=$(dig aaaa +short ${HOSTNAME})
|
||||
|
@ -36,34 +40,33 @@ case "$1" in
|
|||
exit 2
|
||||
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
|
||||
|
||||
|
||||
## START writing config files
|
||||
|
||||
## START nic config compile
|
||||
|
||||
|
||||
# write udev rules for device names
|
||||
for if in ${!MACS[@]}
|
||||
# gathering supported interfaces
|
||||
declare -A MACS
|
||||
MACS["mgmt1"]=$(dig txt +short mac.mgmt.${HOSTNAME})
|
||||
for if in feth up ibgp
|
||||
do
|
||||
ifmac=${MACS[$if]}
|
||||
[ "$if" == "mgmt" ] && if=mgmt1
|
||||
[ -z "$ifmac" ] || echo 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=='$ifmac', ATTR{type}=="1", NAME="'${if}'"'
|
||||
done >/etc/udev/rules.d/70-persistent-net.rules
|
||||
for i in {1..9}
|
||||
do
|
||||
MACS["${if}${i}"]=$(dig txt +short mac.${if}${i}.${HOSTNAME})
|
||||
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
|
||||
cat <<-EOF >/etc/network/interfaces
|
||||
source-directory /etc/network/interfaces.d
|
||||
EOF
|
||||
|
||||
cat <<-EOF >/etc/network/interfaces.d/lo
|
||||
# write loopback config
|
||||
cat <<-EOF >/etc/network/interfaces
|
||||
auto lo
|
||||
iface lo inet loopback
|
||||
|
||||
|
@ -74,27 +77,74 @@ case "$1" in
|
|||
address ${LOOPBACKv6}/128
|
||||
EOF
|
||||
|
||||
cat <<-"EOF" >/etc/network/interfaces.d/mgmt1
|
||||
auto mgmt1
|
||||
iface mgmt1 inet dhcp
|
||||
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 master mgmt dev mgmt1
|
||||
post-down /bin/ip link del dev mgmt
|
||||
iface mgmt1 inet6 auto
|
||||
EOF
|
||||
|
||||
cat <<-"EOF" >/etc/network/interfaces.d/feth
|
||||
auto feth1
|
||||
iface feth1 inet manual
|
||||
mtu 9000
|
||||
for if in ${!MACS[@]}
|
||||
do
|
||||
[ -z ${MACS[$if]} ] && continue ## skip undefined interfaces
|
||||
|
||||
auto feth2
|
||||
iface feth2 inet manual
|
||||
mtu 9000
|
||||
EOF
|
||||
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 set up dev mgmt
|
||||
pre-up /bin/ip link set master mgmt dev $if
|
||||
post-down /bin/ip link del dev mgmt
|
||||
|
||||
|
||||
EOF
|
||||
fi
|
||||
|
||||
|
||||
if [[ $if = ibgp? ]]; then
|
||||
cat <<-EOF >>$IFCONFIG
|
||||
auto $if
|
||||
iface $if inet manual
|
||||
mtu 9000
|
||||
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue