-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add script to create/delete multiple GCE instances #573
Conversation
- This script outputs the IP address array that can be used with start_nodes script to launch multinode demo - Changes to start_nodes to compress files for rsync
6559818
to
b93d0ee
Compare
multinode-demo/gce_multinode.sh
Outdated
|
||
Creates a GCE multinode network | ||
|
||
-c create/delete - Create or delete the network |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make the command an argument instead of an option? So you'd write gce_multinode.sh create
instead of gce_multinode.sh -c create
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me try
98b9f11
to
a17ac0f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like on create
, there won't be much stdout output? It could be useful to report the number of VMs created or something, to let the user know machines are now running and 💸 is happening :)
multinode-demo/gce_multinode.sh
Outdated
nodes+=("$prefix$i") | ||
done | ||
|
||
if [ "$command" = "create" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[[
instead of [
please, same for elif
@@ -0,0 +1,89 @@ | |||
#!/bin/bash | |||
|
|||
command=$1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you'll want a shift
after command=$1
so that the getopts
below won't see $1
(or is that what OPTIND=$OPTIND+1
is doing?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, OPTIND+1 is doing the same. If shift is the better form, I can use that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer shift
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
multinode-demo/gce_multinode.sh
Outdated
|
||
set -e | ||
|
||
if [[ -z "$command" ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm partial to this one-liner: [[ -n $command ]] || usage
(same for the rest below)
(also note the lack of double quotes, which are unnecessary for [[
)
multinode-demo/gce_multinode.sh
Outdated
elif [ "$command" = "delete" ]; then | ||
gcloud beta compute instances delete "${nodes[@]}" | ||
else | ||
usage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: usage "Unknown command: $command"
multinode-demo/gce_multinode.sh
Outdated
ip_addr_list=$(gcloud beta compute instances create "${nodes[@]}" --zone=us-west1-b --tags=testnet \ | ||
--image="$image_name" | grep "RUNNING" | tr -s ' ' | cut -f 5 -d ' ') | ||
|
||
echo "ip_addr_array=($ip_addr_list)" >"$out_file" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add one space between >"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My shell format plugin (for VSCode) removes the space if I add it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vim
:)
oh well, I guess we have no canonical bash formatter right now.
multinode-demo/gce_multinode.sh
Outdated
echo "Error: $*" | ||
fi | ||
cat <<EOF | ||
usage: $0 <create/delete> <-p prefix> <-n num_nodes> <-o file> [-i image-name] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: create/delete
-> create|delete
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
multinode-demo/gce_multinode.sh
Outdated
--image="$image_name" | grep "RUNNING" | tr -s ' ' | cut -f 5 -d ' ') | ||
|
||
echo "ip_addr_array=($ip_addr_list)" >"$out_file" | ||
elif [ "$command" = "delete" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer [[ to [
if you use [[, you can also use ==, and skip quotes
multinode-demo/gce_multinode.sh
Outdated
exit 0 | ||
;; | ||
p) | ||
prefix="$OPTARG" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quotes unnecessary when command is only assignment
multinode-demo/gce_multinode.sh
Outdated
case $opt in | ||
h | \?) | ||
usage | ||
exit 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't usage always exit?
multinode-demo/gce_multinode.sh
Outdated
fi | ||
|
||
if [[ -z "$prefix" ]]; then | ||
usage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have usage throw an error for these cases, i.e. supply an error string
multinode-demo/gce_multinode.sh
Outdated
fi | ||
|
||
ip_addr_list=$(gcloud beta compute instances create "${nodes[@]}" --zone=us-west1-b --tags=testnet \ | ||
--image="$image_name" | grep "RUNNING" | tr -s ' ' | cut -f 5 -d ' ') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
grep "RUNNING" | tr -s ' ' | cut -f 5 -d ' '
is the same as
awk '/RUNNING/ {print $5}'
multinode-demo/gce_multinode.sh
Outdated
usage | ||
fi | ||
|
||
ip_addr_list=$(gcloud beta compute instances create "${nodes[@]}" --zone=us-west1-b --tags=testnet \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could instead do:
ip_addr_array=( $(gcloud beta compute instances create "${nodes[@]}" --zone=us-west1 ... )
declare -p ip_addr_array > "$out_file"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is giving me shellcheck errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
directive it away, shellcheck is sometimes dumb
a17ac0f
to
cf1019b
Compare
cf1019b
to
e096f16
Compare
The script outputs the list of GCE instances that gets created. For delete, it prompts the user to confirm the delete operation. |
Bumps [thiserror](https://github.com/dtolnay/thiserror) from 1.0.20 to 1.0.21. - [Release notes](https://github.com/dtolnay/thiserror/releases) - [Commits](dtolnay/thiserror@1.0.20...1.0.21) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* build(deps): bump thiserror from 1.0.57 to 1.0.58 Bumps [thiserror](https://github.com/dtolnay/thiserror) from 1.0.57 to 1.0.58. - [Release notes](https://github.com/dtolnay/thiserror/releases) - [Commits](dtolnay/thiserror@1.0.57...1.0.58) --- updated-dependencies: - dependency-name: thiserror dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * [auto-commit] Update all Cargo lock files --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot-buildkite <[email protected]>
with start_nodes script to launch multinode demo