typo error
[joid.git] / ci / deploy.sh
1 #!/bin/bash
2
3 set -ex
4
5 #need to put mutiple cases here where decide this bundle to deploy by default use the odl bundle.
6 # Below parameters are the default and we can according the release
7
8 opnfvsdn=nosdn
9 opnfvtype=nonha
10 openstack=liberty
11 opnfvlab=default
12 opnfvrel=b
13
14 read_config() {
15     opnfvrel=`grep release: deploy.yaml | cut -d ":" -f2`
16     openstack=`grep openstack: deploy.yaml | cut -d ":" -f2`
17     opnfvtype=`grep type: deploy.yaml | cut -d ":" -f2`
18     opnfvlab=`grep lab: deploy.yaml | cut -d ":" -f2`
19     opnfvsdn=`grep sdn: deploy.yaml | cut -d ":" -f2`
20 }
21
22 usage() { echo "Usage: $0 [-s <nosdn|odl|opencontrail>]
23                          [-t <nonha|ha|tip>] 
24                          [-o <juno|liberty>]
25                          [-l <default|intelpod5>]
26                          [-r <a|b>]" 1>&2 exit 1; } 
27
28 while getopts ":s:t:o:l:h:r:" opt; do
29     case "${opt}" in
30         s)
31             opnfvsdn=${OPTARG}
32             ;;
33         t)
34             opnfvtype=${OPTARG}
35             ;;
36         o)
37             openstack=${OPTARG}
38             ;;
39         l)
40             opnfvlab=${OPTARG}
41             ;;
42         r)
43             opnfvrel=${OPTARG}
44             ;;
45         h)
46             usage
47             ;;
48         *)
49             ;;
50     esac
51 done
52
53 deploy_dep() {
54     sudo apt-add-repository ppa:juju/stable -y
55     sudo apt-get update
56     sudo apt-get install juju git juju-deployer -y
57     juju init -f
58     cp environments.yaml ~/.juju/
59 }
60
61 deploy() {
62     #copy the script which needs to get deployed as part of ofnfv release
63     echo "...... deploying now ......"
64     echo "   " >> environments.yaml
65     echo "        enable-os-refresh-update: false" >> environments.yaml
66     echo "        enable-os-upgrade: false" >> environments.yaml
67     echo "        admin-secret: admin" >> environments.yaml
68     echo "        default-series: trusty" >> environments.yaml
69
70     cp environments.yaml ~/.juju/
71
72     cp ./$opnfvsdn/01-deploybundle.sh ./01-deploybundle.sh
73     ./00-bootstrap.sh
74
75     #case default:
76     ./01-deploybundle.sh $opnfvtype $openstack $opnfvlab
77 }
78
79 check_status() {
80     retval=0
81     timeoutiter=0
82     while [ $retval -eq 0 ]; do
83        sleep 30
84        juju status > status.txt 
85        if [ "$(grep -c "executing" status.txt )" -ge 1 ]; then
86            echo " still executing the reltionship within charms ..."
87            if [ $timeoutiter -ge 60 ]; then
88                retval=1
89            fi
90            timeoutiter=$((timeoutiter+1))
91        else
92            retval=1
93        fi
94     done
95     echo "...... deployment finishing ......."
96 }
97
98 configOpenrc()
99 {
100     echo  "  " > ./cloud/admin-openrc
101     echo  "export OS_USERNAME=$1" >> ./cloud/admin-openrc 
102     echo  "export OS_PASSWORD=$2" >> ./cloud/admin-openrc
103     echo  "export OS_TENANT_NAME=$3" >> ./cloud/admin-openrc
104     echo  "export OS_AUTH_URL=$4" >> ./cloud/admin-openrc
105     echo  "export OS_REGION_NAME=$5" >> ./cloud/admin-openrc
106  }
107
108 unitAddress()
109 {
110     juju status | python -c "import yaml; import sys; print yaml.load(sys.stdin)[\"services\"][\"$1\"][\"units\"][\"$1/$2\"][\"public-address\"]" 2> /dev/null
111 }
112
113 createopenrc()
114 {
115     mkdir -m 0700 -p cloud
116
117     controller_address=$(unitAddress keystone 0)
118     configOpenrc admin openstack admin http://$controller_address:5000/v2.0 Canonical 
119     chmod 0600 cloud/admin-openrc
120 }
121
122 if [ "$#" -eq 0 ]; then
123   echo "This installtion will use deploy.yaml" 
124   read_config
125 fi
126
127 echo "...... deployment started ......"
128 #deploy_dep
129 deploy
130 check_status
131 echo "...... deployment finished  ......."
132
133 echo "...... creating OpenRc file for consuming by various user ......."
134
135 createopenrc
136
137 echo "...... finished  ......."
138
139