2 ##############################################################################
3 # Copyright (c) 2015 Ericsson AB and others.
4 # stefan.k.berg@ericsson.com
5 # jonas.bjurel@ericsson.com
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
21 if [ -z $env_id ]; then
22 local n_envs=$(fuel env --list | grep -v -E "^id|^--|^ *$" | wc -l)
23 if [ $n_envs -ne 1 ]; then
24 echo "Usage: $0 [<env-id>]" >&2
25 error_exit "If only a single environment is present it can be left" \
26 "out. Otherwise the environment must be selected"
28 env_id=$(fuel env --list | grep -v -E "^id|^--" | awk '{print $1}')
30 if ! fuel --env $env_id environment 2>/dev/null grep -v -E "^id|^--" | \
31 grep -q ^$env_id; then
32 error_exit "No such environment ID: $env_id"
39 cat $1 | grep "^uid: " | sed "s/^uid: '//" | sed "s/'$//"
43 cat $1 | grep "^role: " | sed "s/^role: //"
49 last=`cat $file | sed 's/.*://' | grep "cic-" | sed 's/cic\-.*sl//' | sort -n | tail -1`
50 if [ -z "$last" ]; then
61 last=`cat $file | sed 's/.*://' | grep "cmp-" | sed 's/cmp\-.*sl//' | sort -n | tail -1`
62 if [ -z "$last" ]; then
73 for line in `cat $file`
75 old=`echo $line | sed 's/:.*//'`
76 new=`echo $line | sed 's/.*://'`
77 echo "Applying: $old -> $new"
79 for dfile in deployment_$env/*.yaml
81 sed -i "s/$old/$new/g" $dfile
84 for pfile in provisioning_$env/*.yaml
86 sed -i "s/$old/$new/g" $pfile
96 for dfile in deployment_$ENV/*.yaml
98 uid=`get_node_uid $dfile`
99 hostname=`grep "^node-$uid:" hostnames.$ENV | sed 's/.*://'`
100 if [ -z $hostname ]; then
102 pfile=provisioning_$ENV/node-$uid.yaml
103 role=`get_node_role $dfile`
107 hostname="cic-pod0-sh0-sl`get_next_cic hostnames.$ENV`"
110 hostname="cic-pod0-sh0-sl`get_next_cic hostnames.$ENV`"
113 hostname="cmp-pod0-sh0-sl`get_next_compute hostnames.$ENV`"
116 echo "Unknown node type for UID $uid"
121 echo "node-$uid:$hostname" >> hostnames.$ENV
123 echo "Already got hostname $hostname for node-$uid"
128 rm -f hostnames.$ENV.old
129 mv hostnames.$ENV hostnames.$ENV.old
130 sort hostnames.$ENV.old | uniq > hostnames.$ENV
131 modify_hostnames $ENV hostnames.$ENV
136 get_provisioning_info () {
138 mkdir -p ${CONFIGDIR}
140 rm -Rf provisioning_$ENV
141 echo "Getting provisioning info..."
142 fuel --env $ENV provisioning --default
143 if [ $? -ne 0 ]; then
144 echo "Error: Could not get provisioning info for env $ENV">&2
149 get_deployment_info () {
151 mkdir -p ${CONFIGDIR}
153 rm -Rf deployment_$ENV
154 echo "Getting deployment info..."
155 fuel --env $ENV deployment --default
156 if [ $? -ne 0 ]; then
157 echo "Error: Could not get deployment info for env $ENV">&2
165 for dfile in deployment_$ENV/*.yaml
167 /opt/opnfv/transform_yaml.py $dfile
175 fuel --env $ENV deployment --upload
176 fuel --env $ENV provisioning --upload
179 add_yaml_fragment () {
181 FRAGMENT=${CONFIGDIR}/fragment.yaml.$ENV
184 for dfile in deployment_$ENV/*.yaml
186 cnt=`grep "^opnfv:" $dfile | wc -l `
187 if [ $cnt -eq 0 ]; then
188 echo "Adding fragment to $dfile"
189 cat $FRAGMENT >> $dfile
191 echo "Already have fragment in $dfile"
199 # Check if the format looks right_
200 echo "$IP_ADDRESS" | egrep -qE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' || return 1
201 #check that each octect is less than or equal to 255:
202 echo $IP_ADDRESS | awk -F'.' '$1 <=255 && $2 <= 255 && $3 <=255 && $4 <= 255 {print "Y" } ' | grep -q Y || return 1
207 generate_ntp_entry() {
209 read -p "NTP server:" NTP_SERVER
210 if [ -z "$NTP_SERVER" ]; then
212 elif confirm_yes "Are you sure you want to add this entry (y/n): "; then
214 echo " server $NTP_SERVER" >> $FILE
218 generate_hostfile_entry() {
220 read -p "Name:" HOST_NAME
221 if [ -z "$HOST_NAME" ]; then
224 read -p "FQDN:" HOST_FQDN
225 read -p "IP: " HOST_IP
226 while ! ip_valid "$HOST_IP"
228 echo "This is not a valid IP! Try again."
229 read -p "IP: " HOST_IP
232 if confirm_yes "Are you sure you want to add this entry (y/n): "; then
234 echo " - name: $HOST_NAME" >> $FILE
235 echo " address: $HOST_IP" >> $FILE
236 echo " fqdn: $HOST_FQDN" >> $FILE
243 generate_dns_entry() {
246 read -p "${PROMPT}:" DNS_IP
247 if [ -z "$DNS_IP" ]; then
250 while ! ip_valid "$DNS_IP"
252 echo "This is not a valid IP! Try again."
253 read -p "${PROMPT}: " DNS_IP
256 if confirm_yes "Are you sure you want to add this entry (y/n): "; then
258 echo " - $DNS_IP" >> $FILE
269 read -p "$prompt" YESNO
281 generate_yaml_fragment() {
283 FRAGMENT=${CONFIGDIR}/fragment.yaml.$ENV
285 if [ -f $FRAGMENT ]; then
286 echo "Manual configuration already performed, reusing previous data from $FRAGMENT."
287 echo "Press return to continue or ^C to stop."
292 echo "opnfv:" > ${FRAGMENT}
295 echo -e "\n\nPre-deployment configuration\n\n"
297 echo -e "\n\nIPs for the DNS servers to go into /etc/resolv.conf. You will be"
298 echo -e "prompted for one IP at the time. Press return on an empty line"
299 echo -e "to complete your input. If no DNS server is specified, the IP of"
300 echo -e "the Fuel master will be used instead.\n"
302 DNSCICYAML=${CONFIGDIR}/cicdns.yaml.$ENV
307 while generate_dns_entry $DNSCICYAML "IP for CIC name servers"
312 if [ -f $DNSCICYAML ]; then
313 echo " dns:" >> $FRAGMENT
314 echo " controller:" >> $FRAGMENT
315 cat $DNSCICYAML >> $FRAGMENT
319 DNSCMPYAML=${CONFIGDIR}/cmpdns.yaml.$ENV
324 while generate_dns_entry $DNSCMPYAML "IP for compute node name servers"
330 if [ -f $DNSCMPYAML ]; then
331 if [ ! -f $DNSCICYAML ]; then
332 echo " dns:" >> $FRAGMENT
334 echo " compute:" >> $FRAGMENT
335 cat $DNSCMPYAML >> $FRAGMENT
338 echo -e "\n\nHosts file additions for controllers and compute nodes. You will be"
339 echo -e "prompted for name, FQDN and IP for each entry. Press return when prompted"
340 echo -e "for a name when you have completed your input.\n"
343 HOSTYAML=${CONFIGDIR}/hosts.yaml.$ENV
345 while generate_hostfile_entry $HOSTYAML
350 if [ -f $HOSTYAML ]; then
351 echo " hosts:" >> $FRAGMENT
352 cat $HOSTYAML >> $FRAGMENT
355 echo -e "\n\nNTP upstream configuration for controllers.You will be"
356 echo -e "prompted for a NTP server each entry. Press return when prompted"
357 echo -e "for a NTP serverwhen you have completed your input.\n"
360 NTPYAML=${CONFIGDIR}/ntp.yaml.$ENV
362 while generate_ntp_entry $NTPYAML
367 if [ -f $NTPYAML ]; then
368 echo " ntp:" >> $FRAGMENT
369 echo " controller: |" >> $FRAGMENT
370 cat $NTPYAML >> $FRAGMENT
372 echo " compute: |" >> $FRAGMENT
373 for ctl in `find $CONFIGDIR/deployment_$ENV -name '*controller*.yaml'`
375 fqdn=`grep "^fqdn:" $ctl | sed 's/fqdn: *//'`
376 echo " server $fqdn" >> $FRAGMENT
380 # If nothing added make sure we get an empty opnfv hash
381 # instead of a NULL hash.
382 if [ $(wc -l $FRAGMENT | awk '{print $1}') -le 1 ]; then
383 echo "opnfv: {}" >$FRAGMENT
389 CONFIGDIR="/var/lib/opnfv"
392 get_deployment_info $ENV
393 # Uncomment the below to enable the control_bond example
395 get_provisioning_info $ENV
396 generate_yaml_fragment $ENV
397 # The feature to change hostnames from node-<n> to cmp- or cic- is disabled.
398 # To turn it on, uncomment the following line.
399 #setup_hostnames $ENV
400 add_yaml_fragment $ENV