Optionally suppress delete confirmation

This commit is contained in:
Michael Vines 2018-09-06 10:28:26 -07:00
parent eaef9be710
commit aa07bdfbaa
2 changed files with 16 additions and 5 deletions

View File

@ -20,6 +20,7 @@ imageName="ubuntu-16-04-cuda-9-2-new"
publicNetwork=false publicNetwork=false
zone="us-west1-b" zone="us-west1-b"
leaderAddress= leaderAddress=
yes=false
usage() { usage() {
exitcode=0 exitcode=0
@ -53,7 +54,7 @@ Configure a GCE-based testnet
none none
delete-specific options: delete-specific options:
none -y - Skip delete confirmation, assume yes
EOF EOF
exit $exitcode exit $exitcode
@ -65,7 +66,7 @@ command=$1
shift shift
[[ $command = create || $command = config || $command = delete ]] || usage "Invalid command: $command" [[ $command = create || $command = config || $command = delete ]] || usage "Invalid command: $command"
while getopts "h?p:Pi:n:c:z:ga:" opt; do while getopts "h?p:Pi:n:c:z:ga:y" opt; do
case $opt in case $opt in
h | \?) h | \?)
usage usage
@ -80,6 +81,9 @@ while getopts "h?p:Pi:n:c:z:ga:" opt; do
i) i)
imageName=$OPTARG imageName=$OPTARG
;; ;;
y)
yes=true
;;
n) n)
validatorNodeCount=$OPTARG validatorNodeCount=$OPTARG
;; ;;
@ -180,7 +184,7 @@ delete)
echo "No instances found matching '^$prefix-'" echo "No instances found matching '^$prefix-'"
exit 0 exit 0
fi fi
gcloud_DeleteInstances gcloud_DeleteInstances "$yes"
rm -f "$configFile" rm -f "$configFile"
;; ;;

View File

@ -149,11 +149,18 @@ gcloud_CreateInstances() {
} }
# #
# gcloud_DeleteInstances # gcloud_DeleteInstances [yes]
# #
# Deletes all the instances listed in the `instances` array # Deletes all the instances listed in the `instances` array
# #
# If yes = "true", skip the delete confirmation
#
gcloud_DeleteInstances() { gcloud_DeleteInstances() {
declare maybeQuiet=
if [[ $1 = true ]]; then
maybeQuiet=--quiet
fi
if [[ ${#instances[0]} -eq 0 ]]; then if [[ ${#instances[0]} -eq 0 ]]; then
echo No instances to delete echo No instances to delete
return return
@ -167,7 +174,7 @@ gcloud_DeleteInstances() {
( (
set -x set -x
gcloud beta compute instances delete --zone "$zone" "${names[@]}" gcloud beta compute instances delete --zone "$zone" $maybeQuiet "${names[@]}"
) )
} }