summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/common-functions.sh20
-rw-r--r--lib/installer/onos/onos_gw_mac_update.sh56
2 files changed, 76 insertions, 0 deletions
diff --git a/lib/common-functions.sh b/lib/common-functions.sh
index edf06cff..1e55aa18 100644
--- a/lib/common-functions.sh
+++ b/lib/common-functions.sh
@@ -504,3 +504,23 @@ PEERDNS=no" > ${net_path}/ifcfg-${line}
sudo systemctl restart network
}
+
+# Update iptables rule for external network reach internet
+# for virtual deployments
+# params: external_cidr
+function configure_undercloud_nat {
+ local external_cidr
+ if [[ -z "$1" ]]; then
+ return 1
+ else
+ external_cidr=$1
+ fi
+
+ ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" <<EOI
+iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
+iptables -t nat -A POSTROUTING -s ${external_cidr} -o eth0 -j MASQUERADE
+iptables -A FORWARD -i eth2 -j ACCEPT
+iptables -A FORWARD -s ${external_cidr} -m state --state ESTABLISHED,RELATED -j ACCEPT
+service iptables save
+EOI
+}
diff --git a/lib/installer/onos/onos_gw_mac_update.sh b/lib/installer/onos/onos_gw_mac_update.sh
new file mode 100644
index 00000000..d003cc01
--- /dev/null
+++ b/lib/installer/onos/onos_gw_mac_update.sh
@@ -0,0 +1,56 @@
+#!/bin/bash
+
+# Update gateway mac to onos for l3 function
+
+# author: Bob zhou
+# author: Tim Rozet
+
+
+# Update gateway mac to onos for l3 function
+# params: external CIDR, external gateway
+function onos_update_gw_mac {
+ local CIDR
+ local GW_IP
+
+ if [[ -z "$1" || -z "$2" ]]; then
+ return 1
+ else
+ CIDR=$1
+ GW_IP=$2
+ fi
+
+ if [ -z "$UNDERCLOUD" ]; then
+ #if not found then dnsmasq may be using leasefile-ro
+ instack_mac=$(virsh domiflist instack | grep default | \
+ grep -Eo "[0-9a-f\]+:[0-9a-f\]+:[0-9a-f\]+:[0-9a-f\]+:[0-9a-f\]+:[0-9a-f\]+")
+ UNDERCLOUD=$(/usr/sbin/arp -e | grep ${instack_mac} | awk {'print $1'})
+ fi
+ # get controller ip address
+ controller_ip=$(ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
+source stackrc
+openstack server list | grep overcloud-controller-0 | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"
+EOI
+)
+
+ if [ -z "$controller_ip" ]; then
+ echo "ERROR: Failed to find controller_ip for overcloud-controller-0"
+ return 1
+ fi
+
+ # get gateway mac
+ GW_MAC=$(arping ${GW_IP} -c 1 -I brbm2 | grep -Eo '([0-9a-fA-F]{2})(([/\s:-][0-9a-fA-F]{2}){5})')
+
+ if [ -z "$GW_MAC" ]; then
+ echo "ERROR: Failed to find gateway mac for ${GW_IP}"
+ return 1
+ fi
+
+ # update gateway mac to onos
+ ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
+ssh -T ${SSH_OPTIONS[@]} "heat-admin@${controller_ip}" <<EOF
+echo "external gateway mac is ${GW_MAC}"
+/opt/onos/bin/onos "externalgateway-update -m ${GW_MAC}"
+EOF
+EOI
+
+}