gce instance types are now configurable

This commit is contained in:
Michael Vines
2018-08-29 08:13:35 -07:00
parent 8e39465700
commit 7e2b65374d
2 changed files with 42 additions and 13 deletions

View File

@ -75,7 +75,7 @@ gcloud_ForEachInstance() {
}
#
# gcloud_CreateInstances [namePrefix] [numNodes] [zone] [imageName]
# gcloud_CreateInstances [namePrefix] [numNodes] [zone] [imageName] [machineType] [accelerator]
#
# Creates one more identical instances.
#
@ -83,6 +83,9 @@ gcloud_ForEachInstance() {
# numNodes - number of instances to create
# zone - zone to create the instances in
# imageName - Disk image for the instances
# machineType - GCE machine type
# accelerator - Optional accelerator to attach to the instance(s), see
# eg, request 4 K80 GPUs with "count=4,type=nvidia-tesla-k80"
#
# Tip: use gcloud_FindInstances to locate the instances once this function
# returns
@ -91,6 +94,8 @@ gcloud_CreateInstances() {
declare numNodes="$2"
declare zone="$3"
declare imageName="$4"
declare machineType="$5"
declare optionalAccelerator="$6"
declare nodes
if [[ $numNodes = 1 ]]; then
@ -99,12 +104,20 @@ gcloud_CreateInstances() {
read -ra nodes <<<$(seq -f "${namePrefix}%g" 1 "$numNodes")
fi
declare -a args
args=(
"--zone=$zone"
"--tags=testnet"
"--image=$imageName"
"--machine-type=$machineType"
)
if [[ -n $optionalAccelerator ]]; then
args+=("--accelerator=$optionalAccelerator")
fi
(
set -x
gcloud beta compute instances create "${nodes[@]}" \
--zone="$zone" \
--tags=testnet \
--image="$imageName"
gcloud beta compute instances create "${nodes[@]}" "${args[@]}" \
)
}