3b3b072463a55a27652fcaa41b0d846bc2aa002a
[apex.git] / lib / installer / onos / onos_gw_mac_update.sh
1 #!/bin/bash
2
3 # Update gateway mac to onos for l3 function
4
5 # author: Bob zhou
6 # author: Tim Rozet
7
8
9 # Update gateway mac to onos for l3 function
10 # params: external CIDR, external gateway
11 function onos_update_gw_mac {
12   local CIDR
13   local GW_IP
14
15   if [[ -z "$1" || -z "$2" ]]; then
16     return 1
17   else
18     CIDR=$1
19     GW_IP=$2
20   fi
21
22   if [ -z "$UNDERCLOUD" ]; then
23     #if not found then dnsmasq may be using leasefile-ro
24     undercloud_mac=$(virsh domiflist undercloud | grep default | \
25                   grep -Eo "[0-9a-f\]+:[0-9a-f\]+:[0-9a-f\]+:[0-9a-f\]+:[0-9a-f\]+:[0-9a-f\]+")
26     UNDERCLOUD=$(/usr/sbin/arp -e | grep ${undercloud_mac} | awk {'print $1'})
27   fi
28   # get controller ip address
29   controller_ip=$(ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
30 source stackrc
31 openstack server list | grep overcloud-controller-0 | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"
32 EOI
33 )
34
35   if [ -z "$controller_ip" ]; then
36     echo "ERROR: Failed to find controller_ip for overcloud-controller-0"
37     return 1
38   fi
39
40   # get gateway mac
41   GW_MAC=$(arping ${GW_IP} -c 1 -I br-external | grep -Eo '([0-9a-fA-F]{2})(([/\s:-][0-9a-fA-F]{2}){5})')
42
43   if [ -z "$GW_MAC" ]; then
44     echo "ERROR: Failed to find gateway mac for ${GW_IP}"
45     return 1
46   fi
47
48   # update gateway mac to onos
49   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
50 ssh -T ${SSH_OPTIONS[@]} "heat-admin@${controller_ip}" <<EOF
51 echo "external gateway mac is ${GW_MAC}"
52 /opt/onos/bin/onos "externalgateway-update -m ${GW_MAC}"
53 EOF
54 EOI
55
56 }