GCE leader nodes can now be provisioned with a static IP address

This commit is contained in:
Michael Vines
2018-09-05 09:31:50 -07:00
parent d9e4bce6ad
commit ec38dba209
2 changed files with 36 additions and 12 deletions

View File

@ -75,7 +75,8 @@ gcloud_ForEachInstance() {
}
#
# gcloud_CreateInstances [namePrefix] [numNodes] [zone] [imageName] [machineType] [accelerator] [startupScript]
# gcloud_CreateInstances [namePrefix] [numNodes] [zone] [imageName]
# [machineType] [accelerator] [startupScript] [address]
#
# Creates one more identical instances.
#
@ -87,6 +88,9 @@ gcloud_ForEachInstance() {
# accelerator - Optional accelerator to attach to the instance(s), see
# eg, request 4 K80 GPUs with "count=4,type=nvidia-tesla-k80"
# startupScript - Optional startup script to execute when the instance boots
# address - Optional name of the GCE static IP address to attach to the
# instance. Requires that |numNodes| = 1 and that addressName
# has been provisioned in the GCE region that is hosting |zone|
#
# Tip: use gcloud_FindInstances to locate the instances once this function
# returns
@ -98,6 +102,7 @@ gcloud_CreateInstances() {
declare machineType="$5"
declare optionalAccelerator="$6"
declare optionalStartupScript="$7"
declare optionalAddress="$8"
declare nodes
if [[ $numNodes = 1 ]]; then
@ -127,6 +132,16 @@ gcloud_CreateInstances() {
)
fi
if [[ -n $optionalAddress ]]; then
[[ $numNodes = 1 ]] || {
echo "Error: address may not be supplied when provisioning multiple nodes: $optionalAddress"
exit 1
}
args+=(
"--address=$optionalAddress"
)
fi
(
set -x
gcloud beta compute instances create "${nodes[@]}" "${args[@]}"