Skip to content

Instantly share code, notes, and snippets.

@ThinGuy
Created June 11, 2021 22:00
Show Gist options
  • Select an option

  • Save ThinGuy/a3fedb79a0c8180d4b1c3dab833a4618 to your computer and use it in GitHub Desktop.

Select an option

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
@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