+echo "...... configuring public access ......."
+
+# translate bundle.yaml to json
+python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)' < bundles.yaml > bundles.json
+# get services list having a public interface
+srv_list=$(cat bundles.json | jq -r ".services | to_entries[] | {\"key\": .key, \"value\": .value[\"bindings\"]} | select (.value!=null) | select(.value[] | contains(\"public-api\"))".key)
+# get cnt list from service list
+cnt_list=$(for cnt in $srv_list; do juju status $cnt --format=json | jq -r ".machines[].containers | to_entries[]".key; done)
+# get public network gateway (supposing it is the first ip of the network)
+public_api_gw=$(cat labconfig.json | jq --raw-output ".opnfv.spaces[] | select(.type==\"public\")".gateway)
+admin_gw=$(cat labconfig.json | jq --raw-output ".opnfv.spaces[] | select(.type==\"admin\")".gateway)
+
+if ([ $admin_gw ] && [ $admin_gw != "null" ]); then
+ # set default gateway to public api gateway
+ for cnt in $cnt_list; do
+ echo "changing default gw on $cnt"
+ if ([ $public_api_gw ] && [ $public_api_gw != "null" ]); then
+ juju ssh $cnt "sudo ip r d default && sudo ip r a default via $public_api_gw";
+ juju ssh $cnt "gw_dev=\$(ip r l | grep 'via $public_api_gw' | cut -d \ -f5) &&\
+ sudo cp /etc/network/interfaces /etc/network/interfaces.bak &&\
+ echo 'removing old default gateway' &&\
+ sudo perl -i -pe 's/^\ *gateway $admin_gw\n$//' /etc/network/interfaces &&\
+ sudo perl -i -pe \"s/iface \$gw_dev inet static/iface \$gw_dev inet static\\n gateway $public_api_gw/\" /etc/network/interfaces \
+ ";
+ fi
+ done
+fi
+
+echo "...... configure ......."
+
+if ([ $opnfvmodel == "openstack" ]); then
+ ./openstack.sh "$opnfvsdn" "$opnfvlab" "$opnfvdistro" "$openstack" || true
+
+ # creating heat domain after puching the public API into /etc/hosts
+ if [[ "$jujuver" > "2" ]]; then
+ status=`juju run-action heat/0 domain-setup`
+ echo $status
+ else
+ status=`juju action do heat/0 domain-setup`
+ echo $status
+ fi
+
+ sudo ../juju/get-cloud-images || true
+ ../juju/joid-configure-openstack || true
+
+ if grep -q 'openbaton' bundles.yaml; then
+ juju add-relation openbaton keystone
+ fi
+
+elif ([ $opnfvmodel == "kubernetes" ]); then
+ ./k8.sh
+fi
+
+# expose the juju gui-url to login into juju gui