Skip to content

Instantly share code, notes, and snippets.

@mastier
Last active June 5, 2026 08:58
Show Gist options
  • Select an option

  • Save mastier/50d49732f663e7c22ca9be4b74311c7f to your computer and use it in GitHub Desktop.

Select an option

Save mastier/50d49732f663e7c22ca9be4b74311c7f to your computer and use it in GitHub Desktop.
#!/bin/bash
# Fetch machines
echo "=== Fetching machines (excluding vms) ==="
ALL_MACHINES=$(maas root machines read | jq -r '.[] | select(.virtualmachine_id==null) | .system_id')
echo "====================================="
# Check what is the current default route
echo "=== Printing the current gateways before change ==="
maas root machines read | jq -r '.[] | select(.virtualmachine_id==null) | [.hostname,.default_gateways.ipv4.gateway_ip] | join(" ")';
echo "====================================="
## Iterate over all machines and update default route to OAM
echo "=== Interating over the machines and updating default route ==="
for SYSTEM_ID in $ALL_MACHINES; do
BOND_OAM_LINK=$(maas root machine read $SYSTEM_ID | jq '.interface_set[] | select(.type=="bond" and .name=="bondM") | .id')
echo -n "machine ${SYSTEM_ID} setting the gateway by interface id ${BOND_OAM_LINK}: "
RESULT="$(maas root interface set-default-gateway $SYSTEM_ID ${BOND_OAM_LINK})"
[[ "$?" == "0" ]] && echo OK || echo "FAIL $RESULT"
done
echo "====================================="
# Check what is the current default route
echo "=== Printing the current gateways after change ==="
maas root machines read | jq -r '.[] | select(.virtualmachine_id==null) | [.hostname,.default_gateways.ipv4.gateway_ip] | join(" ")';
echo "====================================="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment