Apply Pimox worker static IP at runtime
This commit is contained in:
parent
dca90ad3aa
commit
1b97cc1404
18
jeannie
18
jeannie
|
|
@ -1184,14 +1184,20 @@ configure_pimox_worker_guest_network() {
|
||||||
local script
|
local script
|
||||||
local encoded_script
|
local encoded_script
|
||||||
local network_output
|
local network_output
|
||||||
|
local worker_address
|
||||||
|
|
||||||
if ! validate_ipv4_cidr_or_host "${worker_ip}"; then
|
if ! validate_ipv4_cidr_or_host "${worker_ip}"; then
|
||||||
echo "Invalid LAB_PIMOX_WORKER_STATIC_IPS entry '${worker_ip}' for VM ${vmid}." >&2
|
echo "Invalid LAB_PIMOX_WORKER_STATIC_IPS entry '${worker_ip}' for VM ${vmid}." >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
if [[ "${worker_ip}" == */* && "${worker_ip}" != */24 ]]; then
|
||||||
|
echo "LAB_PIMOX_WORKER_STATIC_IPS currently supports host IPv4 values or /24 CIDRs, got '${worker_ip}'." >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
if [[ "${worker_ip}" != */* ]]; then
|
if [[ "${worker_ip}" != */* ]]; then
|
||||||
worker_ip="${worker_ip}/24"
|
worker_ip="${worker_ip}/24"
|
||||||
fi
|
fi
|
||||||
|
worker_address="${worker_ip%%/*}"
|
||||||
if ! [[ "${gateway}" =~ ^[0-9]{1,3}(\.[0-9]{1,3}){3}$ ]]; then
|
if ! [[ "${gateway}" =~ ^[0-9]{1,3}(\.[0-9]{1,3}){3}$ ]]; then
|
||||||
echo "Invalid LAB_PIMOX_WORKER_GATEWAY '${gateway}'." >&2
|
echo "Invalid LAB_PIMOX_WORKER_GATEWAY '${gateway}'." >&2
|
||||||
return 1
|
return 1
|
||||||
|
|
@ -1213,19 +1219,25 @@ iface lo inet loopback
|
||||||
|
|
||||||
auto ${interface_name}
|
auto ${interface_name}
|
||||||
iface ${interface_name} inet static
|
iface ${interface_name} inet static
|
||||||
address ${worker_ip}
|
address ${worker_address}
|
||||||
|
netmask 255.255.255.0
|
||||||
gateway ${gateway}
|
gateway ${gateway}
|
||||||
dns-nameservers ${dns_servers}
|
dns-nameservers ${dns_servers}
|
||||||
INTERFACES
|
INTERFACES
|
||||||
sudo cp /tmp/homelab-interfaces /etc/network/interfaces
|
sudo cp /tmp/homelab-interfaces /etc/network/interfaces
|
||||||
sudo systemctl disable --now systemd-networkd NetworkManager 2>/dev/null || true
|
sudo systemctl disable --now systemd-networkd NetworkManager 2>/dev/null || true
|
||||||
sudo systemctl enable networking >/dev/null 2>&1 || true
|
sudo systemctl enable networking >/dev/null 2>&1 || true
|
||||||
sudo systemctl restart networking || true
|
sudo ifdown --force ${interface_name} 2>/dev/null || true
|
||||||
sudo ip addr flush dev ${interface_name} || true
|
sudo ip addr flush dev ${interface_name} || true
|
||||||
sudo ifup ${interface_name} || true
|
sudo ip link set ${interface_name} up
|
||||||
|
sudo ip addr add ${worker_ip} dev ${interface_name}
|
||||||
|
sudo ip route replace default via ${gateway} dev ${interface_name}
|
||||||
|
printf '%s\n' ${dns_servers} | awk '{ for (i = 1; i <= NF; i++) print "nameserver " \$i }' | sudo tee /etc/resolv.conf >/dev/null
|
||||||
|
sudo ifup --force ${interface_name} 2>/dev/null || true
|
||||||
sudo systemctl restart ssh 2>/dev/null || true
|
sudo systemctl restart ssh 2>/dev/null || true
|
||||||
ip -br addr show ${interface_name}
|
ip -br addr show ${interface_name}
|
||||||
ip route
|
ip route
|
||||||
|
ip -4 addr show dev ${interface_name} | grep -q '${worker_address}/'
|
||||||
EOF
|
EOF
|
||||||
)"
|
)"
|
||||||
encoded_script="$(printf '%s' "${script}" | base64 | tr -d '\n')"
|
encoded_script="$(printf '%s' "${script}" | base64 | tr -d '\n')"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue