3 # Copyright 2018 Huawei Technologies Co., Ltd.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
13 portal_hostname="portal.api.simpledemo.onap.org"
16 # default branch for cloning integration repo
17 integration_gerrit_branch=$(git rev-parse --abbrev-ref HEAD)
18 # default branch for cloning oom repo
19 # by default, assume oom branch is the same as integration branch
20 oom_gerrit_branch=$(git rev-parse --abbrev-ref HEAD)
22 if [ -z "$WORKSPACE" ]; then
23 export WORKSPACE=$(git rev-parse --show-toplevel)
28 echo "Usage: $0 [ -n <number of VMs {2-15}> ][ -s <stack name> ][ -d <domain> ][ -i <integration_branch> ][ -o <oom_branch> ][ -r ][ -q ] <env>" 1>&2;
30 echo "n: Number of worker VMs to deploy. This number must be between 2 and 15." 1>&2;
31 echo "s: Stack name. This name will be used for naming of resources." 1>&2;
32 echo "d: Base domain name to be used in portal UI URLs." 1>&2;
33 echo "i: Branch of integration repo to clone." 1>&2;
34 echo "o: Branch of oom repo to clone." 1>&2;
35 echo "r: Delete all ONAP resource within tenant." 1>&2;
36 echo "q: Quiet delete of all ONAP resources within tenant." 1>&2;
42 while getopts ":n:s:d:i:o:rq" o; do
45 if [[ ${OPTARG} =~ ^[0-9]+$ ]];then
46 if [ ${OPTARG} -ge 2 -a ${OPTARG} -le 15 ]; then
56 if [[ ! ${OPTARG} =~ ^[0-9]+$ ]];then
63 if [[ ! ${OPTARG} =~ ^[0-9]+$ ]];then
64 portal_hostname=${OPTARG}
70 integration_gerrit_branch=${OPTARG}
73 oom_gerrit_branch=${OPTARG}
76 echo "The following command will delete all information relating to onap within your enviroment"
77 read -p "Are you certain this is what you want? (type y to confirm):" answer
79 if [ $answer = "y" ] || [ $answer = "Y" ] || [ $answer = "yes" ] || [ $answer = "Yes"]; then
80 echo "This may delete the work of other colleages within the same enviroment"
81 read -p "Are you certain this is what you want? (type y to confirm):" answer2
83 if [ $answer2 = "y" ] || [ $answer2 = "Y" ] || [ $answer2 = "yes" ] || [ $answer2 = "Yes"]; then
104 if [ "$#" -ne 1 ]; then
110 if [ ! -f $ENV_FILE ];then
111 echo ENV file does not exist or was not given
117 SSH_KEY=~/.ssh/onap_key
119 if ! hash openstack jq java
121 echo "ERROR: Required commands not found; please install openstack CLI, jq, java."
125 SO_ENCRYPTION_KEY=aa3871669d893c7fb8abbcda31b88b4f
126 export OS_PASSWORD_ENCRYPTED_FOR_ROBOT=$(echo -n "$OS_PASSWORD" | openssl aes-128-ecb -e -K "$SO_ENCRYPTION_KEY" -nosalt | xxd -c 256 -p)
128 #Use new encryption method
129 pushd $WORKSPACE/deployment/heat/onap-rke/scripts
131 #SO_ENCRYPTION_KEY=aa3871669d893c7fb8abbcda31b88b4f
132 export OS_PASSWORD_ENCRYPTED=$(java Crypto "$OS_PASSWORD" "$SO_ENCRYPTION_KEY")
135 for n in $(seq 1 5); do
136 if [ $full_deletion = true ] ; then
137 $WORKSPACE/deployment/heat/onap-rke/scripts/teardown-onap.sh -n $stack_name -q
139 $WORKSPACE/deployment/heat/onap-rke/scripts/teardown-onap.sh -n $stack_name
142 cd $WORKSPACE/deployment/heat/onap-rke
143 envsubst < $ENV_FILE > $ENV_FILE~
144 if [ -z "$vm_num" ]; then
145 cp onap-oom.yaml onap-oom.yaml~
147 ./scripts/gen-onap-oom-yaml.sh $vm_num > onap-oom.yaml~
150 if ! openstack stack create -t ./onap-oom.yaml~ -e $ENV_FILE~ $stack_name --parameter integration_gerrit_branch=$integration_gerrit_branch --parameter oom_gerrit_branch=$oom_gerrit_branch -parameter portal_hostname=$portal_hostname; then
154 while [ "CREATE_IN_PROGRESS" == "$(openstack stack show -c stack_status -f value $stack_name)" ]; do
158 STATUS=$(openstack stack show -c stack_status -f value $stack_name)
160 if [ "CREATE_COMPLETE" != "$STATUS" ]; then
164 for i in $(seq 1 30); do
166 NFS_IP=$(openstack stack output show $stack_name nfs_vm_ip -c output_value -f value)
167 K8S_IP=$(openstack stack output show $stack_name k8s_01_vm_ip -c output_value -f value)
168 timeout 1 ping -c 1 "$NFS_IP" && break
171 timeout 1 ping -c 1 "$NFS_IP" && break
173 echo Error: OpenStack infrastructure issue: unable to reach NFS server "$NFS_IP"
177 if ! timeout 1 ping -c 1 "$NFS_IP"; then
181 # wait until all k8s VMs have fully initialized
182 for VM_NAME in $(grep _vm: ./onap-oom.yaml~ | cut -d: -f1); do
184 VM_IP=$(openstack stack output show $stack_name ${VM_NAME}_ip -c output_value -f value)
186 until ssh -o StrictHostKeychecking=no -i $SSH_KEY ubuntu@$VM_IP ls -ad /dockerdata-nfs/.git; do
191 cat > ./cluster.yml~ <<EOF
192 # GENERATED for $stack_name
196 for VM_NAME in $(grep -E 'k8s_.+_vm:' ./onap-oom.yaml~ | cut -d: -f1); do
198 VM_IP=$(openstack stack output show $stack_name ${VM_NAME}_ip -c output_value -f value)
199 VM_PRIVATE_IP=$(openstack stack output show $stack_name ${VM_NAME}_private_ip -c output_value -f value)
200 VM_HOSTNAME=$stack_name-$(echo $VM_NAME | tr '_' '-' | cut -d- -f1,2)
201 cat >> ./cluster.yml~ <<EOF
204 internal_address: $VM_PRIVATE_IP
207 hostname_override: "$VM_HOSTNAME"
209 ssh_key_path: "$SSH_KEY"
213 for VM_NAME in $(grep -E 'orch_.+_vm:' ./onap-oom.yaml~ | cut -d: -f1); do
215 VM_IP=$(openstack stack output show $stack_name ${VM_NAME}_ip -c output_value -f value)
216 VM_PRIVATE_IP=$(openstack stack output show $stack_name ${VM_NAME}_private_ip -c output_value -f value)
217 VM_HOSTNAME=$stack_name-$(echo $VM_NAME | tr '_' '-' | cut -d- -f1,2)
218 cat >> ./cluster.yml~ <<EOF
221 internal_address: $VM_PRIVATE_IP
225 hostname_override: "$VM_HOSTNAME"
227 ssh_key_path: "$SSH_KEY"
231 DOCKER_PROXY=$(openstack stack output show $stack_name docker_proxy -c output_value -f value)
233 cat >> ./cluster.yml~ <<EOF
236 service_cluster_ip_range: 10.43.0.0/16
237 pod_security_policy: false
238 always_pull_images: false
240 cluster_cidr: 10.42.0.0/16
241 service_cluster_ip_range: 10.43.0.0/16
243 cluster_domain: cluster.local
244 cluster_dns_server: 10.43.0.10
250 ssh_key_path: "$SSH_KEY"
251 ssh_agent_auth: false
254 ignore_docker_version: false
255 kubernetes_version: "v1.13.5-rancher1-2"
259 cluster_name: "$stack_name"
267 cp ./cluster.yml~ ./target/cluster.yml
270 wget https://github.com/rancher/rke/releases/download/v0.2.1/rke_linux-amd64
271 mv rke_linux-amd64 rke
274 # spin up k8s with RKE
280 scp -i $SSH_KEY ./kube_config_cluster.yml root@$NFS_IP:/root/.kube/config
285 ssh -o StrictHostKeychecking=no -i $SSH_KEY ubuntu@$NFS_IP "sed -u '/Cloud-init.*finished/q' <(tail -n+0 -f /var/log/cloud-init-output.log)"