delete potentially conflicting dhcp configs before adding a new one

This commit is contained in:
forest 2021-12-09 17:34:39 -06:00
parent c7469f2acb
commit 8bcdc99664

View File

@ -12,4 +12,13 @@ ipv4_address="$4"
[ "$mac_address" = '' ] && printf 'you must set $mac_address (3rd arg)\n' && exit 1
[ "$ipv4_address" = '' ] && printf 'you must set $ipv4_address (4th arg)\n' && exit 1
# for some reason libvirt appears to remember every dhcp lease even after it has expired.
# adding a new ip-dhcp-host will fail if there already is one with the same ip address.
# so we will try to delete any that already exist with that IP address just in case!
if [ "$action" == 'add' ]; then
printf "trying to delete any existing (probably expired) dhcp associations for $ipv4_address..."
virsh net-update "$network_name" delete ip-dhcp-host "<host ip='$ipv4_address' />" --live --config || true
fi
printf "adding $mac_address --> $ipv4_address to $network_name"
virsh net-update "$network_name" "$action" ip-dhcp-host "<host mac='$mac_address' ip='$ipv4_address' />" --live --config