-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to create/delete multiple GCE instances
- 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
- Loading branch information
Showing
2 changed files
with
85 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/bin/bash | ||
|
||
command=$1 | ||
prefix= | ||
num_nodes= | ||
out_file= | ||
image_name="ubuntu-16-04-cuda-9-2-new" | ||
|
||
shift | ||
|
||
usage() { | ||
exitcode=0 | ||
if [[ -n "$1" ]]; then | ||
exitcode=1 | ||
echo "Error: $*" | ||
fi | ||
cat <<EOF | ||
usage: $0 <create|delete> <-p prefix> <-n num_nodes> <-o file> [-i image-name] | ||
Manage a GCE multinode network | ||
create|delete - Create or delete the network | ||
-p prefix - A common prefix for node names, to avoid collision | ||
-n num_nodes - Number of nodes | ||
-o out_file - Used for create option. Outputs an array of IP addresses | ||
of new nodes to the file | ||
-i image_name - Existing image on GCE (default $image_name) | ||
EOF | ||
exit $exitcode | ||
} | ||
|
||
while getopts "h?p:i:n:o:" opt; do | ||
case $opt in | ||
h | \?) | ||
usage | ||
;; | ||
p) | ||
prefix=$OPTARG | ||
;; | ||
i) | ||
image_name=$OPTARG | ||
;; | ||
o) | ||
out_file=$OPTARG | ||
;; | ||
n) | ||
num_nodes=$OPTARG | ||
;; | ||
*) | ||
usage "Error: unhandled option: $opt" | ||
;; | ||
esac | ||
done | ||
|
||
set -e | ||
|
||
[[ -n $command ]] || usage "Need a command (create|delete)" | ||
|
||
[[ -n $prefix ]] || usage "Need a prefix for GCE instance names" | ||
|
||
[[ -n $num_nodes ]] || usage "Need number of nodes" | ||
|
||
nodes=() | ||
for i in $(seq 1 "$num_nodes"); do | ||
nodes+=("$prefix$i") | ||
done | ||
|
||
if [[ $command == "create" ]]; then | ||
[[ -n $out_file ]] || usage "Need an outfile to store IP Addresses" | ||
|
||
ip_addr_list=$(gcloud beta compute instances create "${nodes[@]}" --zone=us-west1-b --tags=testnet \ | ||
--image="$image_name" | awk '/RUNNING/ {print $5}') | ||
|
||
echo "ip_addr_array=($ip_addr_list)" >"$out_file" | ||
elif [[ $command == "delete" ]]; then | ||
gcloud beta compute instances delete "${nodes[@]}" | ||
else | ||
usage "Unknown command: $command" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters