Skip to content

Commit

Permalink
Optionally suppress delete confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Sep 7, 2018
1 parent eaef9be commit aa07bdf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 7 additions & 3 deletions net/gce.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ imageName="ubuntu-16-04-cuda-9-2-new"
publicNetwork=false
zone="us-west1-b"
leaderAddress=
yes=false

usage() {
exitcode=0
Expand Down Expand Up @@ -53,7 +54,7 @@ Configure a GCE-based testnet
none
delete-specific options:
none
-y - Skip delete confirmation, assume yes
EOF
exit $exitcode
Expand All @@ -65,7 +66,7 @@ command=$1
shift
[[ $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
h | \?)
usage
Expand All @@ -80,6 +81,9 @@ while getopts "h?p:Pi:n:c:z:ga:" opt; do
i)
imageName=$OPTARG
;;
y)
yes=true
;;
n)
validatorNodeCount=$OPTARG
;;
Expand Down Expand Up @@ -180,7 +184,7 @@ delete)
echo "No instances found matching '^$prefix-'"
exit 0
fi
gcloud_DeleteInstances
gcloud_DeleteInstances "$yes"
rm -f "$configFile"
;;

Expand Down
11 changes: 9 additions & 2 deletions scripts/gcloud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,18 @@ gcloud_CreateInstances() {
}

#
# gcloud_DeleteInstances
# gcloud_DeleteInstances [yes]
#
# Deletes all the instances listed in the `instances` array
#
# If yes = "true", skip the delete confirmation
#
gcloud_DeleteInstances() {
declare maybeQuiet=
if [[ $1 = true ]]; then
maybeQuiet=--quiet
fi

if [[ ${#instances[0]} -eq 0 ]]; then
echo No instances to delete
return
Expand All @@ -167,7 +174,7 @@ gcloud_DeleteInstances() {

(
set -x
gcloud beta compute instances delete --zone "$zone" "${names[@]}"
gcloud beta compute instances delete --zone "$zone" $maybeQuiet "${names[@]}"
)
}

Expand Down

0 comments on commit aa07bdf

Please sign in to comment.