From 8ea040c86cd61f7fe91ea8e8e9b091a4291db35d Mon Sep 17 00:00:00 2001 From: Jack Date: Fri, 23 Nov 2018 08:05:16 +0000 Subject: [PATCH] Use --filter to target instance (#79) Fixing a bug that was re-introduced with 5.0.0 --- gcloud-snapshot.sh | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/gcloud-snapshot.sh b/gcloud-snapshot.sh index 05bf584..b6ed402 100755 --- a/gcloud-snapshot.sh +++ b/gcloud-snapshot.sh @@ -167,7 +167,27 @@ getInstanceName() getDeviceList() { - echo -e "$(gcloud $OPT_ACCOUNT compute disks list $1 --filter "$FILTER_CLAUSE" --format='value(name,zone,id)' $OPT_PROJECT)" + # echo -e "$(gcloud $OPT_INSTANCE_SERVICE_ACCOUNT compute disks list --filter "users~instances/$1\$ $FILTER_CLAUSE" --format='value(name)')" + + local filter="" + + # if using remote instances (-r), then no name filter is required + if [ "$REMOTE_CLAUSE" = true ]; then + + # check if $FILTER_CLAUSE exists + if [[ ! -z $FILTER_CLAUSE ]]; then + filter="${FILTER_CLAUSE}" + fi + else + # check if $FILTER_CLAUSE exists + if [[ ! -z $FILTER_CLAUSE ]]; then + filter="name:$1 AND ${FILTER_CLAUSE}" + else + filter="name:$1" + fi + fi + + echo -e "$(gcloud $OPT_ACCOUNT compute disks list --filter "${filter}" --format='value(name,zone,id)' $OPT_PROJECT)" }