2
# Reset maas fabrics and vlans to 0, the defaults.
8
# Learn all the system_id and hostnames to lookup later.
10
maas $ENV machines read |
11
grep -P 'system_id|hostname' |
12
sed -r ' N;s/\n/ /; s/( +"system_id": .[^,]+,)(.*)/\2 \1/; s, +"(system_id|hostname)": ,,g; s/"//g; s/,/@/; s/,//')
13
# Find the unwanted fabric, which is most likely the one with a number
16
maas $ENV fabrics read |
17
sed -r '/\/fabrics\/[0-9][0-9]+/!d; s,.*/fabrics/([0-9][0-9]+)/.*,\1,')
18
if [[ $FABRIC == "" ]]; then
21
# Find the vlan id of the default fabric.
23
maas $ENV fabric read 0 |
24
sed -r '/vlans/,/}/!d; /"id"/!d; s,[^0-9],,g' |
26
# Learn the misconfigured interfaces by attempting to delete
27
# the unwanted fabric.
29
maas $ENV fabric delete $FABRIC 2>&1 |
30
sed -r 's,(^.*:|\([^\)]*\)) ,,g; s, on ,@,g; s/,//g' ||
32
# Reset the fabric and vlan of each machine on the unwanted fabric.
33
for iface_machine in $INTERFACES; do
34
iface=$(echo $iface_machine | cut -d @ -f1)
35
machine=$(echo $iface_machine | cut -d @ -f2)
37
echo "$ALL_SYSTEM_HOSTS" |
38
grep $machine@ | cut -d @ -f2)
39
maas $ENV machine release $system_id
41
maas $ENV interface update $system_id $iface fabric=0 vlan=$VLAN
43
# Delete the unwanted fabric.
44
maas $ENV fabric delete $FABRIC