4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
19 #0. Get values for the environment variables
21 # The following must be provided.
26 # The next set may be modified if necessary but are best left as-is
29 # Max time (in minutes) to wait for the remote-installer to return completed
34 # The rest should probably not be changed
40 # these will come from the Blueprint file and are available in "INPUT.yaml"
41 tr , '\012' < $WORKDIR/INPUT.yaml |tr -d '{}'|sed -e 's/^ *//' -e 's/: /=/' >/tmp/env
43 REC_ISO_IMAGE_NAME=$iso_primary
44 REC_PROVISIONING_ISO_NAME=$iso_secondary
45 INPUT_YAML_URL=$input_yaml
47 --------------------------------------------
50 EXTERNALROOT is $EXTERNALROOT
51 REC_ISO_IMAGE_NAME is $REC_ISO_IMAGE_NAME
52 REC_PROVISIONING_ISO_NAME is $REC_PROVISIONING_ISO_NAME
53 INPUT_YAML_URL is $INPUT_YAML_URL
54 --------------------------------------------
57 #1. Create a new directory to be used for holding the installation artifacts.
59 #create the base directory
63 mkdir -p $BASEDIR/images
65 #certificates sub-directory
66 mkdir -p $BASEDIR/certificates
68 #user configuration and cloud admin information
69 mkdir -p $BASEDIR/user-configs
71 #installation logs directory
72 mkdir -p $BASEDIR/installations
74 #2. Get REC golden image from REC Nexus artifacts and copy it to the images sub-directory under the directory created in (1).
77 FILENAME=$(echo "${REC_ISO_IMAGE_NAME##*/}")
78 curl $REC_ISO_IMAGE_NAME > $FILENAME
80 #3. Get REC booting image from REC Nexus artifacts and copy it to the images sub-directory under the directory created in (1).
83 FILENAME=$(echo "${REC_PROVISIONING_ISO_NAME##*/}")
84 curl $REC_PROVISIONING_ISO_NAME > $FILENAME
86 #4. Get the user-config.yaml file and admin_password file for the CD environment from the
87 # cd-environments repo and copy it to the user-configs sub-directory under the directory
88 # created in (1). Copy the files to a cloud-specific directory identified by the cloudname.
90 cd $BASEDIR/user-configs/
93 curl $INPUT_YAML_URL > user_config.yaml
94 ln user_config.yaml user_config.yml
95 echo $ADMIN_PASSWD > admin_passwd
97 #5. Checkout the remote-installer repo from LF
101 git clone https://gerrit.akraino.org/r/ta/remote-installer
103 #6. Copy the sever certificates, the client certificates in addition to CA certificate to
104 # the certificates sub-directory under the directory created in (1).
105 # The following certificates are expected to be available in the directory:
107 # cacert.pem: The CA certificate
108 # servercert.pem: The server certificate signed by the CA
109 # serverkey.pem: The server key
110 # clientcert.pem: The client certificate signed by the CA
111 # clientkey.pem: The client key
114 cd $BASEDIR/git/remote-installer/test/certificates
116 cp *.pem $BASEDIR/certificates
118 #7. Build the remote installer docker-image.
119 cd $BASEDIR/git/remote-installer/scripts/
120 echo $0: ./build.sh "$HTTPS_PORT" "$API_PORT"
121 ./build.sh "$HTTPS_PORT" "$API_PORT"
123 #8. Start the remote installer
125 cd $BASEDIR/git/remote-installer/scripts/
126 echo $0: ./start.sh -b "$EXTERNALROOT$BASEDIR" -e "$HOST_IP" -s "$HTTPS_PORT" -a "$API_PORT" -p "$ADMIN_PASSWD"
127 if ! ./start.sh -b "$EXTERNALROOT$BASEDIR" -e "$HOST_IP" -s "$HTTPS_PORT" -a "$API_PORT" -p "$ADMIN_PASSWD"
129 echo Failed to run workflow
133 #9. Wait for the remote installer to become running.
134 # check every 30 seconds to see if it has it has a status of "running"
138 while [ ${#DOCKER_STATUS} -eq 0 ]; do
141 DOCKER_ID=$(docker ps | grep remote-installer | awk ' {print $1}')
142 DOCKER_STATUS=$(docker ps -f status=running | grep $DOCKER_ID)
145 #10. Start the installation by sending the following http request to the installer API
147 # POST url: https://localhost:$API_PORT/v1/installations
148 # REQ body json- encoded
150 # 'cloudname': $CLOUDNAME,
151 # 'iso': $REC_ISO_IMAGE_NAME,
152 # 'provisioning-iso': $REC_PROVISIONING_ISO_NAME
154 # REP body json-encoded
156 # 'uuid': $INSTALLATION_UUID
159 rec=$(basename $REC_ISO_IMAGE_NAME)
160 boot=$(basename $REC_PROVISIONING_ISO_NAME)
163 "cloud-name": "$CLOUDNAME",
165 "provisioning-iso": "$boot"
169 # Get the IP address of the remote installer container
170 # RI_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' remote-installer)
173 echo "$0: Posting to https://$RI_IP:$API_PORT/v1/installations"
176 --header "Content-Type: application/json" \
178 --cert $BASEDIR/certificates/clientcert.pem \
179 --key $BASEDIR/certificates/clientkey.pem \
180 https://$RI_IP:$API_PORT/v1/installations)
181 echo "$0: RESPONSE IS $RESPONSE"
183 INSTALLATION_UUID=$(echo $RESPONSE | jq -r ".uuid")
185 #11. Follow the progress of the installation by sending the following http request to the installer API
187 # GET url: https://localhost:$API_PORT/v1/installations/$INSTALLATION_UUID
189 # REP body json-encoded
191 # 'status': <ongoing|completed|failed>,
192 # 'description': <description>,
193 # 'percentage': <the progess precentage>
198 # check the status every minute until it has become "completed"
199 # (for a maximum of MAX_TIME minutes)
203 while [ "$STATUS" == "ongoing" -a $NTIMES -gt 0 ]; do
205 NTIMES=$((NTIMES - 1))
206 RESPONSE=$(curl -k --silent \
207 --cert $BASEDIR/certificates/clientcert.pem \
208 --key $BASEDIR/certificates/clientkey.pem \
209 https://$RI_IP:$API_PORT/v1/installations/$INSTALLATION_UUID/state)
210 STATUS=$(echo $RESPONSE | jq -r ".status")
211 PCT=$( echo $RESPONSE | jq -r ".percentage")
212 DESCR=$( echo $RESPONSE | jq -r ".description")
213 echo "$(date): Status is $STATUS ($PCT) $DESCR"
215 if [ "$STATUS" == "ongoing" -a $NTIMES -eq 0 ]
217 echo "Installation failed after $MAX_TIME minutes."
220 echo "Installation complete!"
222 #12. When installation is completed stop the remote installer.
224 cd $BASEDIR/git/remote-installer/scripts/