Add bond support during initial network config

This commit is contained in:
Joshua Boniface 2023-09-01 15:42:00 -04:00
parent 12e316fd3e
commit 48a35c8d60
1 changed files with 84 additions and 6 deletions

View File

@ -394,13 +394,16 @@ interactive_config() {
interfaces="$( interfaces="$(
ip address | grep '^[0-9]' | grep 'eno\|enp\|ens\|wlp' | awk '{ print $2"\t"$3 }' | tr -d ':' ip address | grep '^[0-9]' | grep 'eno\|enp\|ens\|wlp' | awk '{ print $2"\t"$3 }' | tr -d ':'
)" )"
echo "Available interfaces:"
echo
echo -e "$( sed 's/\(.*\)/ \1/' <<<"${interfaces[@]}" )"
echo
echo "3a) Please enter the primary network interface for external connectivity. If" echo "3a) Please enter the primary network interface for external connectivity. If"
echo "no entries are shown here, ensure a cable is connected, then restart the" echo "no entries are shown here, ensure a cable is connected, then restart the"
echo "installer with ^C and '/install.sh'." echo "installer with ^C and '/install.sh'."
echo echo
echo "Available interfaces:" echo "If you want a bonding interface, please enter 'bond' here."
echo echo
echo -e "$( sed 's/\(.*\)/ \1/' <<<"${interfaces[@]}" )"
while [[ -z ${target_interface} ]]; do while [[ -z ${target_interface} ]]; do
echo echo
echo -n "> " echo -n "> "
@ -410,7 +413,7 @@ interactive_config() {
echo "Please enter a valid interface." echo "Please enter a valid interface."
continue continue
fi fi
if ! grep -qw "${target_interface}" <<<"${interfaces[@]}"; then if [[ ${target_interface} != "bond" ]] && ! grep -qw "${target_interface}" <<<"${interfaces[@]}"; then
target_interface="" target_interface=""
echo echo
echo "Please enter a valid interface." echo "Please enter a valid interface."
@ -419,7 +422,73 @@ interactive_config() {
echo echo
done done
echo -n "3b) Is a tagged vLAN required for the primary network interface? [y/N] " if [[ ${target_interace} == "bond" ]]; then
target_interface=""
echo "3b) Please enter the name of the bonding interface (e.g. 'bond0'). This"
echo "should match the interface you will use in the pvc-ansible configuration if"
echo "applicable and MUST start with 'bond'."
echo
while [[ -z ${target_interface} ]]; do
echo -n "> "
read target_interface
if [[ -z ${target_interface} ]]; then
echo
echo "Please enter a valid interface."
continue
fi
if ! grep -q '^bond' <<<"${target_interface}"; then
echo
echo "Please enter a valid interface."
continue
fi
done
echo
echo "3c) Please enter the bonding mode for the interface (e.g. '802.3ad' or"
echo "'active-backup'). This mode must be valid or the networking will fail."
echo
while [[ -z ${bonding_mode} ]]; do
echo -n "> "
read bonding_mode
if [[ -z ${bonding_mode} ]]; then
echo
echo "Please enter a valid bonding mode."
continue
fi
done
echo
echo "3d) Please enter the space-separated slave interfaces from the list above."
echo
while [[ -z ${slave_interfaces} ]]; do
echo -n "> "
read slave_interfaces
if [[ -z ${slave_interfaces} ]]; then
echo
echo "Please enter a valid list of slave interfaces."
continue
fi
done
echo
echo -n "Bringing up bond interface... "
ip link add ${target_interface} type bond
ip link set ${target_interface} type bond mode ${bonding_mode}
for slave_interface in ${slave_interfaces}; do
ip link set ${slave_interface} down
ip link set ${slave_interface} master ${target_interface}
done
ip link set ${target_interface} up
echo "done."
next_prompt_1="3e"
next_prompt_2="3f"
else
next_prompt_1="3b"
next_prompt_2="3c"
fi
echo -n "${next_prompt_1}) Is a tagged vLAN required for the primary network interface? [y/N] "
read vlans_req read vlans_req
if [[ ${vlans_req} == 'y' || ${vlans_req} == 'Y' ]]; then if [[ ${vlans_req} == 'y' || ${vlans_req} == 'Y' ]]; then
echo echo
@ -440,7 +509,7 @@ interactive_config() {
echo echo
fi fi
echo "3c) Please enter the IP address, in CIDR format [X.X.X.X/YY], of the primary" echo "${next_prompt_2}) Please enter the IP address, in CIDR format [X.X.X.X/YY], of the primary"
echo "network interface. Leave blank for DHCP configuration of the interface on boot." echo "network interface. Leave blank for DHCP configuration of the interface on boot."
echo echo
echo -n "> " echo -n "> "
@ -827,17 +896,26 @@ interactive_interfaces_segment() {
case ${target_interfaces_is} in case ${target_interfaces_is} in
static-vlan) static-vlan)
target_interfaces_block="auto ${vlan_interface}\niface ${vlan_interface} inet ${target_netformat}\n\tvlan_raw_device ${target_interface}\n\taddress ${formatted_ipaddr}\n\tnetmask ${formatted_netmask}\n\tgateway ${target_defgw}" target_interfaces_block="auto ${vlan_interface}\niface ${vlan_interface} inet ${target_netformat}\n\tvlan_raw_device ${target_interface}\n\taddress ${formatted_ipaddr}\n\tnetmask ${formatted_netmask}\n\tgateway ${target_defgw}"
if [[ -n ${slave_interfaces} ]]; then
target_interfaces_block="${target_interfaces_block}\n\nauto ${target_interface}\niface ${target_interface} inet manual"
fi
;; ;;
static-raw) static-raw)
target_interfaces_block="auto ${target_interface}\niface ${target_interface} inet ${target_netformat}\n\taddress ${formatted_ipaddr}\n\tnetmask ${formatted_netmask}\n\tgateway ${target_defgw}" target_interfaces_block="auto ${target_interface}\niface ${target_interface} inet ${target_netformat}\n\taddress ${formatted_ipaddr}\n\tnetmask ${formatted_netmask}\n\tgateway ${target_defgw}"
;; ;;
dhcp-vlan) dhcp-vlan)
target_interfaces_block="auto ${vlan_interface}\niface ${vlan_interface} inet ${target_netformat}\n\tvlan_raw_device${target_interface}" target_interfaces_block="auto ${vlan_interface}\niface ${vlan_interface} inet ${target_netformat}\n\tvlan_raw_device${target_interface}"
if [[ -n ${slave_interfaces} ]]; then
target_interfaces_block="${target_interfaces_block}\n\nauto ${target_interface}\niface ${target_interface} inet manual"
fi
;; ;;
dhcp-raw) dhcp-raw)
target_interfaces_block="auto ${target_interface}\niface ${target_interface} inet ${target_netformat}" target_interfaces_block="auto ${target_interface}\niface ${target_interface} inet ${target_netformat}"
;; ;;
esac esac
if [[ -n ${slave_interfaces} ]]; then
target_interfaces_block="${target_interfaces_block}\n\tbond-mode ${bonding_mode}\n\tbond-slaves ${slave_interfaces}"
fi
} }
echo -n "Creating bootstrap interface segment... " echo -n "Creating bootstrap interface segment... "
@ -1014,7 +1092,7 @@ seed_postinst() {
interactive_postinst() { interactive_postinst() {
set +o errexit set +o errexit
echo echo
echo -n "Launch a chroot shell in the target environment? [y/N] " echo -n "Launch a chroot shell in the target environment? (NOTE: no shell prompt) [y/N] "
read launch_chroot read launch_chroot
if [[ ${launch_chroot} == 'y' || ${launch_chroot} == 'Y' ]]; then if [[ ${launch_chroot} == 'y' || ${launch_chroot} == 'Y' ]]; then
echo "Type 'exit' or Ctrl+D to exit chroot." echo "Type 'exit' or Ctrl+D to exit chroot."