Updates docs for SR1 with final revision
[genesis.git] / fuel / prototypes / auto-deploy / create_templates / create_templates.sh
1 #!/bin/bash
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 ##############################################################################
11
12 cleanup () {
13     if [ -n "$tmpDir" ]; then
14         rm -Rf $tmpDir
15     fi
16 }
17
18 trap cleanup exit
19
20 error_exit () {
21     echo "Error: $@" >&2
22     exit 1
23 }
24
25 tmpDir=`mktemp -d /tmp/deaXXXX`
26
27 export PATH=`dirname $0`:$PATH
28
29 if [ $# -lt 2 ]; then
30     error_exit "`basename $0`: <deafile> <dhafile> <comment>"
31 fi
32
33 deafile=$1
34 dhafile=$2
35 shift 2
36
37 if [ $# -ne 0 ]; then
38     comment="$@"
39 else
40     comment=""
41 fi
42
43 if [ -f $deafile ]; then
44     error_exit "$deafile already exists"
45 elif [ -f $dhafile ]; then
46     error_exit "$dhafile already exists"
47 fi
48
49 # Create headers
50
51 cat >$deafile << EOF
52 title: Deployment Environment Adapter (DEA)
53 # DEA API version supported
54 version: 1.1
55 created: `date`
56 comment: $comment
57 EOF
58
59 cat >$dhafile << EOF
60 title: Deployment Hardware Adapter (DHA)
61 # DHA API version supported
62 version: 1.1
63 created: `date`
64 comment: $comment
65
66 # Adapter to use for this definition
67 adapter: 
68
69 # Node list.
70 # Mandatory properties are id and role.
71 # The MAC address of the PXE boot interface for Fuel is not
72 # mandatory to be defined.
73 # All other properties are adapter specific.
74
75 EOF
76
77 if [ `fuel env | tail -n +3 | grep -v '^$' | wc -l` -ne 1 ]; then
78     error_exit "Not exactly one environment"
79 fi
80 envId=`fuel env | tail -n +3 | grep -v '^$' | awk '{ print $1 }'`
81
82 computeId=`fuel node | grep compute | grep True | head -1 | awk '{ print $1}'`
83 controllerId=`fuel node | grep controller | grep True | head -1 | awk '{ print $1}'`
84
85 if [ -z "$computeId" ]; then
86     error_exit "Could not find any compute node"
87 elif [ -z "$controllerId" ]; then
88     error_exit "Could not find any controller node"
89 fi
90
91 fuel deployment --env $envId --download --dir $tmpDir > /dev/null || \
92     error_exit "Could not get deployment info"
93 fuel settings --env $envId --download --dir $tmpDir > /dev/null || \
94     error_exit "Could not get settings"
95 fuel network --env $envId --download --dir $tmpDir > /dev/null || \
96     error_exit "Could not get network settings"
97
98 # Create node structure for DEA mapping to the DHA
99 # Note! Nodes will be renumbered to always start with id 1
100 echo "nodes:" >> $deafile
101 echo "nodes:" >> $dhafile
102 minNode=`fuel node | tail -n +3 | sed 's/ .*//' | sort -n | head -1`
103 for realNodeId in `fuel node | tail -n +3 | sed 's/ .*//' | sort -n`
104 do
105     nodeId=$[realNodeId - minNode + 1]
106     role=`fuel node --node-id $realNodeId | tail -n +3 | cut -d "|" -f 7 | sed 's/ //g'` || \
107         error_exit "Could not get role for node $realNodeId"
108
109     if [ -z "$role" ]; then
110         error_exit "Node $realNodeId has no role - is this environment really deployed?"
111     fi
112
113     fuel node --node-id $realNodeId --network --download --dir $tmpDir > /dev/null || \
114         error_exit "Could not get network info for node $controllerId"
115
116     generate_node_info.py $nodeId $role $tmpDir/node_${realNodeId}/interfaces.yaml $dhafile | \
117         grep -v "^nodes:" >> $deafile || \
118         error_exit "Could not extract info for node $realNodeId"
119 done
120
121 cat >>$dhafile <<EOF
122 # Adding the Fuel node as node id $[nodeId + 1] which may not be correct - please
123 # adjust as needed.
124 EOF
125 generate_fuel_node_info.py $[nodeId +1] $dhafile || \
126     error_exit "Could not extract info for the Fuel node"
127
128 # Environment mode
129 echo "environment_mode: `fuel env | tail -n +3 | cut -d "|" -f 4 | sed 's/ //g' | sed 's/ha_compact/ha/'`" \
130     >>$deafile || error_exit "Could not get environment mode"
131
132 echo "environment_name: `fuel env | tail -n +3 | cut -d "|" -f 3 | sed 's/ //g'`" \
133     >>$deafile || error_exit "Could not get environment mode"
134
135 reap_fuel_settings.py $deafile fuel || \
136     error_exit "Could not extract Fuel node settings"
137
138 # TODO: Potentially move the network scheme into each node of the DEA nodes structure
139 # TODO: instead (this may be too generic to support all node types)
140 reap_network_scheme.py $tmpDir/deployment_${envId}/*controller_${controllerId}.yaml \
141     $deafile controller || error_exit "Could not extract network scheme for controller"
142
143 # TODO: Potentially move the network scheme into each node of the DEA nodes structure
144 # TODO: instead (this may be too generic to support all node types)
145 reap_network_scheme.py $tmpDir/deployment_${envId}/compute_${computeId}.yaml $deafile \
146     compute ||  error_exit "Could not extract network scheme for compute"
147
148 reap_opnfv_astute.py $tmpDir/deployment_${envId}/*controller_${controllerId}.yaml \
149     $tmpDir/deployment_${envId}/compute_${computeId}.yaml ${deafile} || \
150     error_exit "Could not extract opnfv info from astute"
151
152 reap_network_settings.py $tmpDir/network_${envId}.yaml $deafile network || \
153     error_exit "Could not extract network settings"
154
155
156 reap_settings.py $tmpDir/settings_${envId}.yaml $deafile settings || \
157     error_exit "Could not extract settings"
158
159 # Last part of the DHA file
160 cat >>$dhafile << EOF
161
162 # Deployment power on strategy
163 # all:      Turn on all nodes at once. There will be no correlation
164 #           between the DHA and DEA node numbering. MAC addresses
165 #           will be used to select the node roles though.
166 # sequence: Turn on the nodes in sequence starting with the lowest order
167 #           node and wait for the node to be detected by Fuel. Not until
168 #           the node has been detected and assigned a role will the next
169 #           node be turned on.
170 powerOnStrategy: sequence
171
172 # If fuelCustomInstall is set to true, Fuel is assumed to be installed by
173 # calling the DHA adapter function "dha_fuelCustomInstall()"  with two
174 # arguments: node ID and the ISO file name to deploy. The custom install
175 # function is then to handle all necessary logic to boot the Fuel master
176 # from the ISO and then return.
177 # Allowed values: true, false
178
179 fuelCustomInstall: false
180 EOF
181
182 # Cleanup due to a currently unknown Fuel behavior adding this
183 # output at certain stages, this information should not be present:
184 sed -i '/ management_vip: ' $deafile
185 sed -i '/ public_vip: ' $deafile
186
187
188 echo "DEA file is available at $deafile"
189 echo "DHA file is available at $dhafile (this is just a template)"