Skip to content

Instantly share code, notes, and snippets.

@ThinGuy
Created June 11, 2021 22:00
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThinGuy/a3fedb79a0c8180d4b1c3dab833a4618 to your computer and use it in GitHub Desktop.
Save ThinGuy/a3fedb79a0c8180d4b1c3dab833a4618 to your computer and use it in GitHub Desktop.
Delete Observed "stuck" IP from MAAS
#!/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
Copy link

superbrothers commented Jan 28, 2022

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.

@ThinGuy
Copy link
Author

ThinGuy commented Feb 8, 2022

@superbrothers You're very welcome!

@vernhart
Copy link

vernhart commented Feb 8, 2022

Nice. I wrote a simpler version of this a couple of months ago. This would have saved me time.

@ajf
Copy link

ajf commented Apr 12, 2022

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

@sparkiegeek
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment