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 RegionOne publicURL $projectid $projectdomainid $userdomainid > ~/joid_config/admin-openrcinternal
111 configOpenrc admin $adminPasswd admin $urlapi RegionOne publicURL $projectid $projectdomainid $userdomainid > ~/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_TENANT_NAME=$3
135 #export OS_TENANT_ID=$7
136 export OS_PROJECT_NAME=$3
137 export OS_USERNAME=$1
138 export OS_PASSWORD=$2
139 export OS_IDENTITY_API_VERSION=3
140 export OS_DEFAULT_DOMAIN=admin_domain
141 export OS_USER_DOMAIN_NAME=admin_domain
142 export OS_USER_DOMAIN_ID=$9
143 export OS_PROJECT_DOMAIN_NAME=admin_domain
144 export OS_PROJECT_DOMAIN_ID=$8
145 export OS_AUTH_STRATEGY='keystone'
146 export OS_REGION_NAME=$5
147 export CINDER_ENDPOINT_TYPE=$6
148 export GLANCE_ENDPOINT_TYPE=$6
149 export KEYSTONE_ENDPOINT_TYPE=$6
150 export NOVA_ENDPOINT_TYPE=$6
151 export NEUTRON_ENDPOINT_TYPE=$6
152 export OS_ENDPOINT_TYPE=$6
153 export OS_INTERFACE=public
154 export OS_AUTH_URL=$4
158 if ([ $API_FQDN ] && [ $API_FQDN != "null" ] && [ $API_FQDN != "None" ]); then
159 echo_info "OS domain name was specified - injecting API FQDN to nodes"
161 # Push api fqdn local ip to all /etc/hosts
162 if [[ "$jujuver" < "2" ]]; then
163 API_FQDN=$(juju get keystone | python -c "import yaml; import sys;\
164 print yaml.load(sys.stdin)['settings']['os-public-hostname']['value']")
166 API_FQDN=$(juju config keystone | python -c "import yaml; import sys;\
167 print yaml.load(sys.stdin)['settings']['os-public-hostname']['value']")
171 KEYSTONEIP=$(keystoneIp)
172 juju run --all "if grep $API_FQDN /etc/hosts > /dev/null; then \
173 echo 'API FQDN already present'; \
175 sudo sh -c 'echo $KEYSTONEIP $API_FQDN >> /etc/hosts'; \
176 echo 'API FQDN injected'; \
179 # remove this enhancement for heat that does not manage endpoints
180 juju run --application=heat "cp /etc/hosts /tmp/hosts ; \
181 grep -v $API_FQDN /tmp/hosts > /etc/hosts"
183 #change in jumphost as well as below commands will run on jumphost
184 if grep $API_FQDN /etc/hosts; then
185 echo 'API FQDN already present'
187 sudo sh -c "echo $KEYSTONEIP $API_FQDN >> /etc/hosts"
188 echo 'API FQDN injected'
192 # Create an load openrc
195 . ~/joid_config/admin-openrc
197 if ([ "$opnfvlab" == "orangepod1" ] \
198 || [ "$opnfvlab" == "intelpod6" ]) \
199 && [ "$opnfvsdn" == "nosdn" ] \
200 && [ "$API_FQDN" != "None" ]; then # only for first test phase
201 if [ -e ./labconfig.yaml ]; then
202 echo_info "Deploying public API proxy"
204 PUB_API_MASK=$(grep floating-ip-range ./labconfig.yaml |cut -d/ -f2)
205 PUB_API_NET=$(grep floating-ip-range ./labconfig.yaml |cut -d, -f4)
206 PUB_API_IP=$(grep public-api-ip ./labconfig.yaml |cut -d: -f2)
207 if grep "- type: public" ./labconfig.yaml; then
208 # The public network exists on MAAS, so we push the dns record to it
210 # Recover maas ips and login to it
211 maas_ip=$(grep " ip_address" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //')
212 maas_pubip=$(grep floating-ip-range ./labconfig.yaml |cut -d, -f4 |perl -pe 's!^(.*)\.\d+/\d+$!$1.5!')
213 apikey=$(grep maas-oauth: environments.yaml | cut -d "'" -f 2)
214 maas login maas http://${maas_ip}/MAAS/api/1.0 ${apikey}
216 # Configure maas to add the record
217 CLUSTER_UUID=$(maas ubuntu node-groups list | grep uuid | cut -d\" -f4)
218 PUBLIC_MAAS_IF=$(maas ubuntu node-group-interfaces list $cluster_uuid |\
219 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'])")
220 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}
221 maas maas ipaddresses reserve network=${PUB_API_NET} requested_address=${PUB_API_IP} hostname=${API_FQDN}
222 dig ${PUB_API_IP} @${maas_ip} # just for log
224 juju run --unit nodes/0 "sudo ip a a ${PUB_API_IP}/${PUB_API_MASK} dev br-ex" || true
225 juju run --unit nodes/0 "sudo ip l set dev br-ex up" || true
226 python genPublicAPIProxyBundle.py -l labconfig.yaml >> bundles.yaml
227 juju-deployer -vW -d -t 7200 -r 5 -c bundles.yaml $opnfvdistro-"$opnfvos" || true
229 echo_info "Public API proxy deployed!"
235 ## removing the swift API endpoint which is created by radosgw.
236 ## one option is not to used radosgw and other one is remove endpoint.
239 #echo "Removing swift endpoint and service"
240 #swift_service_id=$(openstack service list | grep swift | cut -d ' ' -f 2)
241 #swift_endpoint_id=$(openstack endpoint list | grep swift | cut -d ' ' -f 2)
242 #openstack endpoint delete $swift_endpoint_id
243 #openstack service delete $swift_service_id
246 ## Create external subnet Network
249 echo_info "Creating external network with neutron"
251 if [ "onos" == "$opnfvsdn" ]; then
253 neutron net-show ext-net > /dev/null 2>&1 || neutron net-create ext-net \
254 --router:external=True
256 neutron net-show ext-net > /dev/null 2>&1 || neutron net-create ext-net \
257 --router:external=True \
258 --provider:network_type flat \
259 --provider:physical_network physnet1
262 neutron subnet-show ext-subnet > /dev/null 2>&1 || neutron subnet-create ext-net \
263 --name ext-subnet --allocation-pool start=$EXTNET_FIP,end=$EXTNET_LIP \
264 --disable-dhcp --gateway $EXTNET_GW $EXTNET_NET
266 #congress team is not updating and supporting charm anymore so defer it.
268 # Create Congress datasources
269 #sudo apt-get install -y python-congressclient
271 #openstack congress datasource create nova "nova" \
272 # --config username=$OS_USERNAME \
273 # --config tenant_name=$OS_TENANT_NAME \
274 # --config password=$OS_PASSWORD \
275 # --config auth_url=http://$keystoneIp:5000/v2.0
276 #openstack congress datasource create neutronv2 "neutronv2" \
277 # --config username=$OS_USERNAME \
278 # --config tenant_name=$OS_TENANT_NAME \
279 # --config password=$OS_PASSWORD \
280 # --config auth_url=http://$keystoneIp:5000/v2.0
281 #openstack congress datasource create ceilometer "ceilometer" \
282 # --config username=$OS_USERNAME \
283 # --config tenant_name=$OS_TENANT_NAME \
284 # --config password=$OS_PASSWORD \
285 # --config auth_url=http://$keystoneIp:5000/v2.0
286 #openstack congress datasource create cinder "cinder" \
287 # --config username=$OS_USERNAME \
288 # --config tenant_name=$OS_TENANT_NAME \
289 # --config password=$OS_PASSWORD \
290 # --config auth_url=http://$keystoneIp:5000/v2.0
291 #openstack congress datasource create glancev2 "glancev2" \
292 # --config username=$OS_USERNAME \
293 # --config tenant_name=$OS_TENANT_NAME \
294 # --config password=$OS_PASSWORD \
295 # --config auth_url=http://$keystoneIp:5000/v2.0
296 #openstack congress datasource create keystone "keystone" \
297 # --config username=$OS_USERNAME \
298 # --config tenant_name=$OS_TENANT_NAME \
299 # --config password=$OS_PASSWORD \
300 # --config auth_url=http://$keystoneIp:5000/v2.0