Browse code

Consolidate two /sbin/ip commands into a single one

When determining the primary IP/IPv6 addresses on a system,
we can use the /sbin/ip command to filter them for us. The
resulting address is parsed the same way for both address
families, so we can use just a single command.

Change-Id: I0471ff5a258a16a23061941ac38063dbf3d7c233

Brian Haley authored on 2015/11/17 07:18:42
Showing 1 changed files
... ...
@@ -801,13 +801,7 @@ function _move_neutron_addresses_route {
801 801
         DEFAULT_ROUTE_GW=$(ip -f $af r | awk "/default.+$from_intf/ { print \$3; exit }")
802 802
         local ADD_OVS_PORT=""
803 803
 
804
-        if [[ $af == "inet" ]]; then
805
-            IP_BRD=$(ip -f $af a s dev $from_intf | grep inet | awk '{ print $2, $3, $4; exit }')
806
-        fi
807
-
808
-        if [[ $af == "inet6" ]]; then
809
-            IP_BRD=$(ip -f $af a s dev $from_intf | grep 'scope global' | sed '/temporary/d' | awk '{ print $2, $3, $4; exit }')
810
-        fi
804
+        IP_BRD=$(ip -f $af a s dev $from_intf scope global primary | grep inet | awk '{ print $2, $3, $4; exit }')
811 805
 
812 806
         if [ "$DEFAULT_ROUTE_GW" != "" ]; then
813 807
             ADD_DEFAULT_ROUTE="sudo ip -f $af r replace default via $DEFAULT_ROUTE_GW dev $to_intf"