-
Notifications
You must be signed in to change notification settings - Fork 1
/
import-boot-resources
executable file
·51 lines (45 loc) · 1.72 KB
/
import-boot-resources
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source $SCRIPT_DIR/config.sh
echo "Importing boot resources..."
aoi-ssh $INSTANCE maas $PROFILE boot-resources import
function get_boot_resource_ids {
while [ 1 ]; do
BOOT_RESOURCE_IDS=$(aoi-ssh $INSTANCE "maas $PROFILE boot-resources read | jq '.[].id'")
if [ "$BOOT_RESOURCE_IDS" != "null" -o "$BOOT_RESOURCE_ID" == "" ]; then
echo "$BOOT_RESOURCE_IDS"
return
fi
sleep 0.5
done
}
echo ""
echo ""
echo "Waiting for region to import boot resources..."
while [ 1 ]; do
BOOT_RESOURCE_IDS=$(get_boot_resource_ids)
# Transform $BOOT_RESOURCE_IDS to clean up linefeeds.
BOOT_RESOURCE_IDS=$(echo $BOOT_RESOURCE_IDS)
RESULT=$(aoi-ssh $INSTANCE "for id in $BOOT_RESOURCE_IDS; do maas $PROFILE boot-resource read \$id | jq '.[] | .[]? | .complete'; done" | sort -u)
if [ "$RESULT" = "true" ]; then
break
fi
sleep 5
# Try importing again. (It seems there might be a race condition that
# prevents it from working the first time.)
aoi-ssh $INSTANCE maas $PROFILE boot-resources import > /dev/null 2>&1
done
# Shortcut: The rack ID is the same as the region ID for the first rack.
# So just read the rack ID from the file.
function get_rack_id {
aoi-ssh $INSTANCE sudo cat /var/lib/maas/maas_id
}
echo ""
echo "Waiting for rack to import boot resources..."
RACK_ID=$(get_rack_id)
if [ "$RACK_ID" == "" ]; then
echo "Error: could not determine MAAS rack ID."
exit 1
fi
aoi config set maas_rack_id "$RACK_ID"
aoi-ssh $INSTANCE "while [ \"\$(maas $PROFILE rack-controller list-boot-images $RACK_ID | jq --raw-output '.status' 2> /dev/null)\" != \"synced\" ]; do sleep 5; done"