Skip to content
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

Merged
merged 1 commit into from
Jul 11, 2018

Conversation

pgarg66
Copy link
Contributor

@pgarg66 pgarg66 commented Jul 10, 2018

  • This script outputs the IP address array that can be used
    with start_nodes script to launch multinode demo

- 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
@pgarg66 pgarg66 force-pushed the pankaj-remote-multinode-env branch from 6559818 to b93d0ee Compare July 10, 2018 19:16

Creates a GCE multinode network

-c create/delete - Create or delete the network
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me try

@pgarg66 pgarg66 force-pushed the pankaj-remote-multinode-env branch 2 times, most recently from 98b9f11 to a17ac0f Compare July 10, 2018 20:23
Copy link
Member

@mvines mvines left a 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 :)

nodes+=("$prefix$i")
done

if [ "$command" = "create" ]; then
Copy link
Member

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
Copy link
Member

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?)

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer shift

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


set -e

if [[ -z "$command" ]]; then
Copy link
Member

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 [[)

elif [ "$command" = "delete" ]; then
gcloud beta compute instances delete "${nodes[@]}"
else
usage
Copy link
Member

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"

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"
Copy link
Member

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 >"

Copy link
Contributor Author

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.

Copy link
Member

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.

echo "Error: $*"
fi
cat <<EOF
usage: $0 <create/delete> <-p prefix> <-n num_nodes> <-o file> [-i image-name]
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

--image="$image_name" | grep "RUNNING" | tr -s ' ' | cut -f 5 -d ' ')

echo "ip_addr_array=($ip_addr_list)" >"$out_file"
elif [ "$command" = "delete" ]; then
Copy link
Contributor

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

exit 0
;;
p)
prefix="$OPTARG"
Copy link
Contributor

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

case $opt in
h | \?)
usage
exit 0
Copy link
Contributor

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?

fi

if [[ -z "$prefix" ]]; then
usage
Copy link
Contributor

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

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 ' ')
Copy link
Contributor

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}'

usage
fi

ip_addr_list=$(gcloud beta compute instances create "${nodes[@]}" --zone=us-west1-b --tags=testnet \
Copy link
Contributor

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"

Copy link
Contributor Author

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.

Copy link
Contributor

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

@pgarg66 pgarg66 force-pushed the pankaj-remote-multinode-env branch from a17ac0f to cf1019b Compare July 10, 2018 23:09
@garious garious changed the title Script to create/delete multiple GCE instances Add script to create/delete multiple GCE instances Jul 10, 2018
@pgarg66 pgarg66 force-pushed the pankaj-remote-multinode-env branch from cf1019b to e096f16 Compare July 10, 2018 23:28
@pgarg66
Copy link
Contributor Author

pgarg66 commented Jul 10, 2018

The script outputs the list of GCE instances that gets created. For delete, it prompts the user to confirm the delete operation.

@garious garious merged commit d7d9853 into master Jul 11, 2018
@pgarg66 pgarg66 deleted the pankaj-remote-multinode-env branch July 11, 2018 00:17
vkomenda pushed a commit to vkomenda/solana that referenced this pull request Aug 29, 2021
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>
behzadnouri pushed a commit to behzadnouri/solana that referenced this pull request Apr 4, 2024
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants