-
-
Save ThinGuy/a3fedb79a0c8180d4b1c3dab833a4618 to your computer and use it in GitHub Desktop.
#!/bin/bash | |
[[ -z ${1} || ${1} =~ -h ]] && { printf "\n\e[2GUsage: ${0##*/} <ip_address>\n\n";exit 2; } || { export STUCK_IP=${1}; } | |
# MAAS IP Address Allocation | |
# Type Name | |
# ━━━━ ━━━━ | |
# 0 AUTO | |
# 1 STICKY | |
# 4 USER_RESERVED | |
# 5 DHCP | |
# 6 OBSERVED | |
# Regex string to test IPv4 address | |
export IPV4REGEX='(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]?)' | |
# Test that argument given was an IP Address | |
[[ -z $(/bin/grep -oE ${IPV4REGEX} <<< "${{STUCK_IP}") ]] && { printf "Please enter a valid a IP address\n\n";exit 1; } | |
export STUCK_IP=${1};printf "Attempting to unstick IP Address ${STUCK_IP}\n"; | |
# Change Allocation type from observed | |
sudo -iu postgres psql -P pager=off ${MAASDB:-maasdb} -Atc "UPDATE maasserver_staticipaddress SET alloc_type = 5 where ip = '$STUCK_IP' AND alloc_type = 6;" | |
# Delete IP from MAAS | |
maas ${PROFILE:-admin} ipaddresses release ip=${STUCK_IP} force=true |
@superbrothers You're very welcome!
Nice. I wrote a simpler version of this a couple of months ago. This would have saved me time.
Thanks for this! It's really super annoying all the random hoops that we have to jump through for IP assignment. It's perfectly reasonable to keep the same IP address throughout that interface's lifetime, isn't it? Why all the drama? Limitations of MAAS' use of ISC-DHCP or some kind of design decision, I don't know.
Reference launchpad bugs, for people stumbling on this:
https://bugs.launchpad.net/maas/+bug/1896292
https://bugs.launchpad.net/maas/+bug/1898122
@ThinGuy given that https://bugs.launchpad.net/maas/+bug/1898122 has been fixed, this should be simply
maas ${PROFILE:-admin} ipaddresses release ip=${STUCK_IP} force=true discovered=true
We also faced a problem with Observed "stuck" IP, and we were able to solve with the help of this script of yours. Thank you very much. We changed to STICKY instead of DHCP and that solved the problem.