11#! /bin/bash
22set -e
33
4- # Function that prints out the help message, describing the script
4+ # Function that prints out the help message, describing the script
55print_help ()
66{
77 echo " $SCRIPT - generates input yaml files for Cluster API on openstack"
@@ -85,6 +85,11 @@ if test -z "$SUPPORTED_PROVIDER_OS"; then
8585 exit 1
8686fi
8787
88+ if [ -z " $OS_CLOUD " ]; then
89+ echo " OS_CLOUD environment variable is not set. Please set OS_CLOUD before running this script."
90+ exit 1
91+ fi
92+
8893if ! hash yq 2> /dev/null; then
8994 echo " 'yq' is not available, please install it. (https://github.com/mikefarah/yq)"
9095 print_help
@@ -125,7 +130,7 @@ MACHINE_CONTROLLER_SSH_HOME=${HOME}/.ssh/
125130
126131OVERWRITE=${OVERWRITE:- 0}
127132CLOUDS_PATH=${CLOUDS_PATH:- " " }
128- CLOUD= " ${OS_CLOUD} "
133+
129134
130135if [ $OVERWRITE -ne 1 ] && [ -f " $MACHINE_GENERATED_FILE " ]; then
131136 echo " File $MACHINE_GENERATED_FILE already exists. Delete it manually before running this script."
@@ -142,14 +147,10 @@ if [ $OVERWRITE -ne 1 ] && [ -f "$PROVIDERCOMPONENT_GENERATED_FILE" ]; then
142147 exit 1
143148fi
144149
145- if [ -z " $CLOUD " ]; then
146- CLOUD=openstack
147- fi
148-
149150mkdir -p " ${OUTPUT_DIR} "
150151
151152if [ -n " $CLOUDS_PATH " ]; then
152- # Read clouds.yaml from file if a path is provided
153+ # Read clouds.yaml from file if a path is provided
153154 OPENSTACK_CLOUD_CONFIG_PLAIN=$( cat " $CLOUDS_PATH " )
154155else
155156 # Collect user input to generate a clouds.yaml file
@@ -173,12 +174,12 @@ else
173174fi
174175
175176# Just blindly parse the cloud.conf here, overwriting old vars.
176- AUTH_URL=$( echo " $OPENSTACK_CLOUD_CONFIG_PLAIN " | yq r - clouds.$CLOUD .auth.auth_url)
177- USERNAME=$( echo " $OPENSTACK_CLOUD_CONFIG_PLAIN " | yq r - clouds.$CLOUD .auth.username)
178- PASSWORD=$( echo " $OPENSTACK_CLOUD_CONFIG_PLAIN " | yq r - clouds.$CLOUD .auth.password)
179- REGION=$( echo " $OPENSTACK_CLOUD_CONFIG_PLAIN " | yq r - clouds.$CLOUD .region_name)
180- PROJECT_ID=$( echo " $OPENSTACK_CLOUD_CONFIG_PLAIN " | yq r - clouds.$CLOUD .auth.project_id)
181- DOMAIN_NAME=$( echo " $OPENSTACK_CLOUD_CONFIG_PLAIN " | yq r - clouds.$CLOUD .auth.user_domain_name)
177+ AUTH_URL=$( echo " $OPENSTACK_CLOUD_CONFIG_PLAIN " | yq -r . clouds.$OS_CLOUD .auth.auth_url)
178+ USERNAME=$( echo " $OPENSTACK_CLOUD_CONFIG_PLAIN " | yq -r . clouds.$OS_CLOUD .auth.username)
179+ PASSWORD=$( echo " $OPENSTACK_CLOUD_CONFIG_PLAIN " | yq -r . clouds.$OS_CLOUD .auth.password)
180+ REGION=$( echo " $OPENSTACK_CLOUD_CONFIG_PLAIN " | yq -r . clouds.$OS_CLOUD .region_name)
181+ PROJECT_ID=$( echo " $OPENSTACK_CLOUD_CONFIG_PLAIN " | yq -r . clouds.$OS_CLOUD .auth.project_id)
182+ DOMAIN_NAME=$( echo " $OPENSTACK_CLOUD_CONFIG_PLAIN " | yq -r . clouds.$OS_CLOUD .auth.user_domain_name)
182183
183184
184185# Basic cloud.conf, no LB configuration as that data is not known yet.
230231done
231232for file in ` ls " ${PROVIDER_MANAGER_DIR} " `
232233do
233- sed " s/{OS_CLOUD}/$CLOUD /g" " ${PROVIDER_MANAGER_DIR} /${file} " >> " $PROVIDERCOMPONENT_GENERATED_FILE "
234+ sed " s/{OS_CLOUD}/$OS_CLOUD /g" " ${PROVIDER_MANAGER_DIR} /${file} " >> " $PROVIDERCOMPONENT_GENERATED_FILE "
234235 echo " ---" >> " $PROVIDERCOMPONENT_GENERATED_FILE "
235236done
236237for file in ` ls " ${CLUSTER_MANAGER_DIR} " `
@@ -275,4 +276,3 @@ cat "$CLUSTER_TEMPLATE_FILE" \
275276
276277echo " Done generating $PROVIDERCOMPONENT_GENERATED_FILE $MACHINE_GENERATED_FILE $CLUSTER_GENERATED_FILE "
277278echo " You should now manually change your cluster configuration by editing the generated files."
278-
0 commit comments