trying to pass correct target for deployment.
[joid.git] / ci / openstack.sh
1 #!/bin/bash -ex
2
3 ##############################################################################
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 #./openstack.sh "$opnfvsdn" "$opnfvdistro" "$openstack"
11
12 opnfvsdn=$1
13 opnfvdistro=$2
14 opnfvos=$3
15
16 if [ -f ./deployconfig.yaml ];then
17     EXTERNAL_NETWORK=`grep floating-ip-range deployconfig.yaml | cut -d ' ' -f 4 `
18
19     # split EXTERNAL_NETWORK=first ip;last ip; gateway;network
20
21     EXTNET=(${EXTERNAL_NETWORK//,/ })
22
23     EXTNET_FIP=${EXTNET[0]}
24     EXTNET_LIP=${EXTNET[1]}
25     EXTNET_GW=${EXTNET[2]}
26     EXTNET_NET=${EXTNET[3]}
27     EXTNET_PORT=`grep "ext-port" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //' | tr ',' ' '`
28     ADMNET_GW=`grep "admNetgway" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //' | tr ',' ' '`
29     API_FQDN=`grep "os-domain-name" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //' | tr ',' ' '`
30 fi
31
32 # launch eth on computer nodes and remove default gw route
33 launch_eth() {
34     computer_list=$(juju status --format short | grep -Eo 'nova-compute/[0-9]')
35     for node in $computer_list; do
36         echo "node name is ${node}"
37         juju ssh $node "sudo ifconfig $EXTNET_PORT up"
38         #juju ssh $node "sudo route del default gw $ADMNET_GW"
39     done
40 }
41
42 # Update gateway mac to onos for l3 function
43 update_gw_mac() {
44     ## get gateway mac
45     EXTNET_GW_MAC=$(juju ssh nova-compute/0 "arp -a ${EXTNET_GW} | grep -Eo '([0-9a-fA-F]{2})(([/\s:-][0-9a-fA-F]{2}){5})'")
46     ## set external gateway mac in onos
47     juju set onos-controller gateway-mac=$EXTNET_GW_MAC
48 }
49
50 unitAddress() {
51         juju status | python -c "import yaml; import sys; print yaml.load(sys.stdin)[\"services\"][\"$1\"][\"units\"][\"$1/$2\"][\"public-address\"]" 2> /dev/null
52 }
53
54 unitMachine() {
55         juju status | python -c "import yaml; import sys; print yaml.load(sys.stdin)[\"services\"][\"$1\"][\"units\"][\"$1/$2\"][\"machine\"]" 2> /dev/null
56 }
57
58 keystoneIp() {
59     KEYSTONE=$(juju status keystone |grep public-address|sed -- 's/.*\: //')
60     if [ $(echo $KEYSTONE|wc -w) == 1 ];then
61         echo $KEYSTONE
62     else
63         juju get keystone | python -c "import yaml; import sys; print yaml.load(sys.stdin)['settings']['vip']['value']"
64     fi
65 }
66
67 # create external network and subnet in openstack
68 create_openrc() {
69     mkdir -m 0700 -p cloud
70     keystoneIp=$(keystoneIp)
71     adminPasswd=$(juju get keystone | grep admin-password -A 5 | grep value | awk '{print $2}' 2> /dev/null)
72     configOpenrc admin $adminPasswd admin http://$keystoneIp:5000/v2.0 RegionOne > cloud/admin-openrc
73     chmod 0600 cloud/admin-openrc
74 }
75
76 configOpenrc() {
77 if [ "$API_FQDN" != "None" ]; then
78     cat <<-EOF
79         export OS_USERNAME=$1
80         export OS_PASSWORD=$2
81         export OS_TENANT_NAME=$3
82         export OS_AUTH_URL=$4
83         export OS_REGION_NAME=$5
84         export OS_ENDPOINT_TYPE='internalURL'
85         export CINDER_ENDPOINT_TYPE='internalURL'
86         export GLANCE_ENDPOINT_TYPE='internalURL'
87         export KEYSTONE_ENDPOINT_TYPE='internalURL'
88         export NEUTRON_ENDPOINT_TYPE='internalURL'
89         export NOVA_ENDPOINT_TYPE='internalURL'
90 EOF
91 else
92     cat <<-EOF
93         export OS_USERNAME=$1
94         export OS_PASSWORD=$2
95         export OS_TENANT_NAME=$3
96         export OS_AUTH_URL=$4
97         export OS_REGION_NAME=$5
98 EOF
99
100 fi
101 }
102
103 if [ "$API_FQDN" != "None" ]; then
104     # Push api fqdn local ip to all /etc/hosts
105     API_FQDN=$(juju get keystone | python -c "import yaml; import sys;\
106         print yaml.load(sys.stdin)['settings']['os-public-hostname']['value']")
107
108     KEYSTONEIP=$(keystoneIp)
109     juju run --all "if grep $API_FQDN /etc/hosts > /dev/null; then \
110                         echo 'API FQDN already present'; \
111                     else \
112                         sudo sh -c 'echo $KEYSTONEIP $API_FQDN >> /etc/hosts'; \
113                         echo 'API FQDN injected'; \
114                     fi"
115
116     #change in jumphost as well as below commands will run on jumphost
117
118     if grep $API_FQDN /etc/hosts; then
119         echo 'API FQDN already present'
120     else
121         sudo sh -c "echo $KEYSTONEIP $API_FQDN >> /etc/hosts"
122         echo 'API FQDN injected'
123     fi
124 fi
125
126 # Create an load openrc
127 create_openrc
128
129 . ./cloud/admin-openrc
130
131 echo "...... deploy public api proxy ......"
132
133 if [ "$opnfvlab" == "orangepod1" ] && [ "$opnfvsdn" == "nosdn" ]; then # only for first test phase
134     if [ -e ./labconfig.yaml ]; then
135         PUB_API_NET=$(grep floating-ip-range ./labconfig.yaml |cut -d/ -f2)
136         PUB_API_IP=$(grep public-api-ip ./labconfig.yaml |cut -d: -f2)
137         juju run --unit nodes/0 "sudo ip a a ${PUB_API_IP}/${PUB_API_NET} dev br-ex" || true
138         juju run --unit nodes/0 "sudo ip l set dev br-ex up" || true
139         python genPublicAPIProxyBundle.py -l labconfig.yaml >> bundles.yaml
140         juju-deployer -vW -d -t 7200 -r 5 -c bundles.yaml $opnfvdistro-"$opnfvos" || true
141     fi
142 fi
143
144 echo "...... deploy end public api proxy ......"
145
146 ##
147 ## removing the swift API endpoint which is created by radosgw.
148 ## one option is not to used radosgw and other one is remove endpoint.
149 ##
150
151 #echo "Removing swift endpoint and service"
152 #swift_service_id=$(openstack service list | grep swift | cut -d ' ' -f 2)
153 #swift_endpoint_id=$(openstack endpoint list | grep swift | cut -d ' ' -f 2)
154 #openstack endpoint delete $swift_endpoint_id
155 #openstack service delete $swift_service_id
156
157 ##
158 ## Create external subnet Network
159 ##
160
161 if [ "onos" == "$opnfvsdn" ]; then
162     launch_eth
163     neutron net-show ext-net > /dev/null 2>&1 || neutron net-create ext-net --router:external=True
164     neutron subnet-show ext-subnet > /dev/null 2>&1 || neutron subnet-create ext-net \
165        --name ext-subnet --allocation-pool start=$EXTNET_FIP,end=$EXTNET_LIP \
166        --disable-dhcp --gateway $EXTNET_GW $EXTNET_NET
167     #neutron subnet-create ext-net --name ext-subnet $EXTNET_NET
168     #update_gw_mac
169 elif [ "nosdn" == "$opnfvsdn" ]; then
170     neutron net-show ext-net > /dev/null 2>&1 || neutron net-create ext-net \
171                                              --router:external=True \
172                                              --provider:network_type flat \
173                                               --provider:physical_network external
174
175     neutron subnet-show ext-subnet > /dev/null 2>&1 || neutron subnet-create ext-net \
176        --name ext-subnet --allocation-pool start=$EXTNET_FIP,end=$EXTNET_LIP \
177        --disable-dhcp --gateway $EXTNET_GW $EXTNET_NET
178 else
179     neutron net-show ext-net > /dev/null 2>&1 || neutron net-create ext-net --router:external=True
180     neutron subnet-show ext-subnet > /dev/null 2>&1 || neutron subnet-create ext-net \
181        --name ext-subnet --allocation-pool start=$EXTNET_FIP,end=$EXTNET_LIP \
182        --disable-dhcp --gateway $EXTNET_GW $EXTNET_NET
183 fi
184
185
186 # Create Congress datasources
187 sudo apt-get install -y python-congressclient
188
189 openstack congress datasource create nova "nova" \
190   --config username=$OS_USERNAME \
191   --config tenant_name=$OS_TENANT_NAME \
192   --config password=$OS_PASSWORD \
193   --config auth_url=http://$keystoneIp:5000/v2.0
194 openstack congress datasource create neutronv2 "neutronv2" \
195   --config username=$OS_USERNAME \
196   --config tenant_name=$OS_TENANT_NAME \
197   --config password=$OS_PASSWORD \
198   --config auth_url=http://$keystoneIp:5000/v2.0
199 openstack congress datasource create ceilometer "ceilometer" \
200   --config username=$OS_USERNAME \
201   --config tenant_name=$OS_TENANT_NAME \
202   --config password=$OS_PASSWORD \
203   --config auth_url=http://$keystoneIp:5000/v2.0
204 openstack congress datasource create cinder "cinder" \
205   --config username=$OS_USERNAME \
206   --config tenant_name=$OS_TENANT_NAME \
207   --config password=$OS_PASSWORD \
208   --config auth_url=http://$keystoneIp:5000/v2.0
209 openstack congress datasource create glancev2 "glancev2" \
210   --config username=$OS_USERNAME \
211   --config tenant_name=$OS_TENANT_NAME \
212   --config password=$OS_PASSWORD \
213   --config auth_url=http://$keystoneIp:5000/v2.0
214 openstack congress datasource create keystone "keystone" \
215   --config username=$OS_USERNAME \
216   --config tenant_name=$OS_TENANT_NAME \
217   --config password=$OS_PASSWORD \
218   --config auth_url=http://$keystoneIp:5000/v2.0
219