forked from gcloudrig/gcloudrig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus.sh
executable file
·61 lines (51 loc) · 2 KB
/
status.sh
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
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bash
#
#
# exit on error
set -e
[ -n "$GCLOUDRIG_DEBUG" ] && set -x
# full path to script dir
DIR="$( cd "$( dirname -- "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
# load globals
# shellcheck source=globals.sh
source "$DIR/globals.sh"
init_gcloudrig;
echo
echo "Project ID: $PROJECT_ID"
echo "Region: $REGION"
echo
# get the number of instances currently running
groupsize=$(gcloud compute instance-groups list --filter "name=$INSTANCEGROUP region:($REGION)" --format "value(size)" --quiet || echo "0")
if [ "${groupsize:-0}" -gt 0 ]; then
gcloudrig_get_instance_from_group "$INSTANCEGROUP"
INSTANCE="$(gcloudrig_get_instance_from_group "$INSTANCEGROUP")"
ZONE="$(gcloudrig_get_instance_zone_from_group "$INSTANCEGROUP")"
BOOTDISK="$(gcloudrig_get_bootdisk_from_instance "$ZONE" "$INSTANCE")"
# TODO check for attached games disk
echo "$INSTANCE is running in $ZONE, booting from $BOOTDISK"
else
echo "no running instance"
instanceTemplate="$(gcloud compute instance-groups managed describe "$INSTANCEGROUP" --region "$REGION" --format="value(instanceTemplate)" --quiet)"
if [ -n "$instanceTemplate" ] ; then
templateProps="$(gcloud compute instance-templates describe \
"$instanceTemplate" --quiet \
--format="csv[no-heading](properties.disks.initializeParams.sourceImage,properties.guestAccelerators.acceleratorType)")"
tmplBootImage="${templateProps%%,*}"
tmplBootImage="${tmplBootImage##*/}"
tmplGPU="${templateProps##*,}"
echo "current configuration is:"
echo
echo "Instance group: $INSTANCEGROUP"
echo " template: ${instanceTemplate##*/}"
echo
echo " boot image: $tmplBootImage"
echo " GPU: $tmplGPU"
echo
fi
# check for games disk snapshots
gamesDiskSnapshot="$(gcloud compute snapshots list --format "value(name)" --filter "labels.$GCRLABEL=true labels.latest=true" --quiet)"
if [ -n "$gamesDiskSnapshot" ] ; then
echo " Games disk"
echo " snapshot: $gamesDiskSnapshot"
fi
fi