2 ##############################################################################
3 # All rights reserved. This program and the accompanying materials
4 # are made available under the terms of the Apache License, Version 2.0
5 # which accompanies this distribution, and is available at
6 # http://www.apache.org/licenses/LICENSE-2.0
7 ##############################################################################
13 #./openstack.sh "$opnfvsdn" "$opnfvlab" "$opnfvdistro" "$openstack" || true
20 jujuver=`juju --version`
22 if [ -f ./deployconfig.yaml ];then
23 EXTERNAL_NETWORK=`grep floating-ip-range deployconfig.yaml | cut -d ' ' -f 4 `
25 # split EXTERNAL_NETWORK=first ip;last ip; gateway;network
27 EXTNET=(${EXTERNAL_NETWORK//,/ })
29 EXTNET_FIP=${EXTNET[0]}
30 EXTNET_LIP=${EXTNET[1]}
31 EXTNET_GW=${EXTNET[2]}
32 EXTNET_NET=${EXTNET[3]}
33 EXTNET_PORT=`grep "ext-port" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //' | tr ',' ' '`
34 ADMNET_GW=`grep "admNetgway" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //' | tr ',' ' '`
35 API_FQDN=`grep "os-domain-name" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //' | tr ',' ' '`
38 # launch eth on computer nodes and remove default gw route
40 computer_list=$(juju status --format short | grep -Eo 'nova-compute/[0-9]')
41 for node in $computer_list; do
42 echo "node name is ${node}"
43 juju ssh $node "sudo ifconfig $EXTNET_PORT up"
44 #juju ssh $node "sudo route del default gw $ADMNET_GW"
48 # Update gateway mac to onos for l3 function
51 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})'")
52 ## set external gateway mac in onos
53 if [[ "$jujuver" < "2" ]]; then
54 juju set onos-controller gateway-mac=$EXTNET_GW_MAC
56 juju config onos-controller gateway-mac=$EXTNET_GW_MAC
61 if [[ "$jujuver" < "2" ]]; then
62 juju status --format yaml | python -c "import yaml; import sys; print yaml.load(sys.stdin)[\"services\"][\"$1\"][\"units\"][\"$1/$2\"][\"public-address\"]" 2> /dev/null
64 juju status --format yaml | python -c "import yaml; import sys; print yaml.load(sys.stdin)[\"applications\"][\"$1\"][\"units\"][\"$1/$2\"][\"public-address\"]" 2> /dev/null
69 if [[ "$jujuver" < "2" ]]; then
70 juju status --format yaml | python -c "import yaml; import sys; print yaml.load(sys.stdin)[\"services\"][\"$1\"][\"units\"][\"$1/$2\"][\"machine\"]" 2> /dev/null
72 juju status --format yaml | python -c "import yaml; import sys; print yaml.load(sys.stdin)[\"applications\"][\"$1\"][\"units\"][\"$1/$2\"][\"machine\"]" 2> /dev/null
77 if [ $(juju status keystone --format=short | grep " keystone"|wc -l) == 1 ];then
78 unitAddress keystone 0
80 if [[ "$jujuver" < "2" ]]; then
81 juju get keystone | python -c "import yaml; import sys; print yaml.load(sys.stdin)['settings']['vip']['value']" | cut -d " " -f 1
83 juju config keystone | python -c "import yaml; import sys; print yaml.load(sys.stdin)['settings']['vip']['value']" | cut -d " " -f 1
88 # create external network and subnet in openstack
90 echo_info "Creating the openrc (OpenStack client environment scripts)"
92 mkdir -m 0700 -p cloud
93 keystoneIp=$(keystoneIp)
94 if [[ "$jujuver" < "2" ]]; then
95 adminPasswd=$(juju get keystone | grep admin-password -A 5 | grep value | awk '{print $2}' 2> /dev/null)
97 adminPasswd=$(juju config keystone | grep admin-password -A 5 | grep value | awk '{print $2}' 2> /dev/null)
100 v3api=`juju config keystone preferred-api-version`
102 if [[ "$v3api" == "3" ]]; then
103 configOpenrc admin $adminPasswd admin http://$keystoneIp:5000/v3 RegionOne publicURL > ~/joid_config/admin-openrc
104 chmod 0600 ~/joid_config/admin-openrc
105 source ~/joid_config/admin-openrc
106 projectid=`openstack project show admin -c id -f value`
107 projectdomainid=`openstack domain show admin_domain -c id -f value`
108 userdomainid=`openstack user show admin -c domain_id -f value`
109 urlapi=`openstack catalog show keystone --format yaml | python -c "import yaml; import sys; print yaml.load(sys.stdin)['endpoints']" | grep public | cut -d " " -f 4`
110 configOpenrc admin $adminPasswd admin $urlapi > ~/joid_config/admin-openrcinternal
111 configOpenrc admin $adminPasswd admin $urlapi > ~/joid_config/admin-openrc
113 configOpenrc2 admin $adminPasswd admin http://$keystoneIp:5000/v2.0 RegionOne > ~/joid_config/admin-openrc
114 chmod 0600 ~/joid_config/admin-openrc
120 export SERVICE_ENDPOINT=$4
122 unset SERVICE_ENDPOINT
123 export OS_USERNAME=$1
124 export OS_PASSWORD=$2
125 export OS_TENANT_NAME=$3
126 export OS_AUTH_URL=$4
127 export OS_REGION_NAME=$5
133 #export OS_NO_CACHE='true'
134 export OS_AUTH_URL=$4
135 export OS_USER_DOMAIN_NAME=admin_domain
136 export OS_PROJECT_DOMAIN_NAME=admin_domain
137 export OS_USERNAME=$1
138 export OS_TENANT_NAME=$3
139 export OS_PROJECT_NAME=$3
140 export OS_PASSWORD=$2
141 export OS_VOLUME_API_VERSION=2
142 export OS_IDENTITY_API_VERSION=3
143 export OS_IMAGE_API_VERSION=2
147 if ([ $API_FQDN ] && [ $API_FQDN != "null" ] && [ $API_FQDN != "None" ]); then
148 echo_info "OS domain name was specified - injecting API FQDN to nodes"
150 # Push api fqdn local ip to all /etc/hosts
151 if [[ "$jujuver" < "2" ]]; then
152 API_FQDN=$(juju get keystone | python -c "import yaml; import sys;\
153 print yaml.load(sys.stdin)['settings']['os-public-hostname']['value']")
155 API_FQDN=$(juju config keystone | python -c "import yaml; import sys;\
156 print yaml.load(sys.stdin)['settings']['os-public-hostname']['value']")
160 KEYSTONEIP=$(keystoneIp)
161 juju run --all "if grep $API_FQDN /etc/hosts > /dev/null; then \
162 echo 'API FQDN already present'; \
164 sudo sh -c 'echo $KEYSTONEIP $API_FQDN >> /etc/hosts'; \
165 echo 'API FQDN injected'; \
168 # remove this enhancement for heat that does not manage endpoints
169 juju run --application=heat "cp /etc/hosts /tmp/hosts ; \
170 grep -v $API_FQDN /tmp/hosts > /etc/hosts"
172 #change in jumphost as well as below commands will run on jumphost
173 if grep $API_FQDN /etc/hosts; then
174 echo 'API FQDN already present'
176 sudo sh -c "echo $KEYSTONEIP $API_FQDN >> /etc/hosts"
177 echo 'API FQDN injected'
181 # Create an load openrc
184 . ~/joid_config/admin-openrc
186 if ([ "$opnfvlab" == "orangepod1" ] \
187 || [ "$opnfvlab" == "intelpod6" ]) \
188 && [ "$opnfvsdn" == "nosdn" ] \
189 && [ "$API_FQDN" != "None" ]; then # only for first test phase
190 if [ -e ./labconfig.yaml ]; then
191 echo_info "Deploying public API proxy"
193 PUB_API_MASK=$(grep floating-ip-range ./labconfig.yaml |cut -d/ -f2)
194 PUB_API_NET=$(grep floating-ip-range ./labconfig.yaml |cut -d, -f4)
195 PUB_API_IP=$(grep public-api-ip ./labconfig.yaml |cut -d: -f2)
196 if grep "- type: public" ./labconfig.yaml; then
197 # The public network exists on MAAS, so we push the dns record to it
199 # Recover maas ips and login to it
200 maas_ip=$(grep " ip_address" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //')
201 maas_pubip=$(grep floating-ip-range ./labconfig.yaml |cut -d, -f4 |perl -pe 's!^(.*)\.\d+/\d+$!$1.5!')
202 apikey=$(grep maas-oauth: environments.yaml | cut -d "'" -f 2)
203 maas login maas http://${maas_ip}/MAAS/api/1.0 ${apikey}
205 # Configure maas to add the record
206 CLUSTER_UUID=$(maas ubuntu node-groups list | grep uuid | cut -d\" -f4)
207 PUBLIC_MAAS_IF=$(maas ubuntu node-group-interfaces list $cluster_uuid |\
208 python -c "import yaml; import sys; cfg=yaml.load(sys.stdin); net_h={net['ip']:net['name'] for net in cfg}; print(net_h['$maas_pubip'])")
209 maas maas node-group-interface update ${CLUSTER_UUID} ${PUBLIC_MAAS_IF} static_ip_range_high=${PUB_API_IP} static_ip_range_low=${PUB_API_IP}
210 maas maas ipaddresses reserve network=${PUB_API_NET} requested_address=${PUB_API_IP} hostname=${API_FQDN}
211 dig ${PUB_API_IP} @${maas_ip} # just for log
213 juju run --unit nodes/0 "sudo ip a a ${PUB_API_IP}/${PUB_API_MASK} dev br-ex" || true
214 juju run --unit nodes/0 "sudo ip l set dev br-ex up" || true
215 python genPublicAPIProxyBundle.py -l labconfig.yaml >> bundles.yaml
216 juju-deployer -vW -d -t 7200 -r 5 -c bundles.yaml $opnfvdistro-"$opnfvos" || true
218 echo_info "Public API proxy deployed!"
224 ## removing the swift API endpoint which is created by radosgw.
225 ## one option is not to used radosgw and other one is remove endpoint.
228 #echo "Removing swift endpoint and service"
229 #swift_service_id=$(openstack service list | grep swift | cut -d ' ' -f 2)
230 #swift_endpoint_id=$(openstack endpoint list | grep swift | cut -d ' ' -f 2)
231 #openstack endpoint delete $swift_endpoint_id
232 #openstack service delete $swift_service_id
235 ## Create external subnet Network
238 echo_info "Creating external network with neutron"
240 if [ "onos" == "$opnfvsdn" ]; then
242 neutron net-show ext-net > /dev/null 2>&1 || neutron net-create ext-net \
243 --router:external=True
245 neutron net-show ext-net > /dev/null 2>&1 || neutron net-create ext-net \
246 --router:external=True \
247 --provider:network_type flat \
248 --provider:physical_network physnet1
251 neutron subnet-show ext-subnet > /dev/null 2>&1 || neutron subnet-create ext-net \
252 --name ext-subnet --allocation-pool start=$EXTNET_FIP,end=$EXTNET_LIP \
253 --disable-dhcp --gateway $EXTNET_GW $EXTNET_NET
255 #congress team is not updating and supporting charm anymore so defer it.
257 # Create Congress datasources
258 #sudo apt-get install -y python-congressclient
260 #openstack congress datasource create nova "nova" \
261 # --config username=$OS_USERNAME \
262 # --config tenant_name=$OS_TENANT_NAME \
263 # --config password=$OS_PASSWORD \
264 # --config auth_url=http://$keystoneIp:5000/v2.0
265 #openstack congress datasource create neutronv2 "neutronv2" \
266 # --config username=$OS_USERNAME \
267 # --config tenant_name=$OS_TENANT_NAME \
268 # --config password=$OS_PASSWORD \
269 # --config auth_url=http://$keystoneIp:5000/v2.0
270 #openstack congress datasource create ceilometer "ceilometer" \
271 # --config username=$OS_USERNAME \
272 # --config tenant_name=$OS_TENANT_NAME \
273 # --config password=$OS_PASSWORD \
274 # --config auth_url=http://$keystoneIp:5000/v2.0
275 #openstack congress datasource create cinder "cinder" \
276 # --config username=$OS_USERNAME \
277 # --config tenant_name=$OS_TENANT_NAME \
278 # --config password=$OS_PASSWORD \
279 # --config auth_url=http://$keystoneIp:5000/v2.0
280 #openstack congress datasource create glancev2 "glancev2" \
281 # --config username=$OS_USERNAME \
282 # --config tenant_name=$OS_TENANT_NAME \
283 # --config password=$OS_PASSWORD \
284 # --config auth_url=http://$keystoneIp:5000/v2.0
285 #openstack congress datasource create keystone "keystone" \
286 # --config username=$OS_USERNAME \
287 # --config tenant_name=$OS_TENANT_NAME \
288 # --config password=$OS_PASSWORD \
289 # --config auth_url=http://$keystoneIp:5000/v2.0