Browse code

Support for single interface Neutron networking with OVS

When running Neutron on a single node that only has a single interface,
the following operations are required:

* Remove the IP address from the physical interface
* Add the interface to the OVS physical bridge
* Add the IP address from the physical interface to the OVS bridge
* Update the routing table

The reverse is done on cleanup.

In order run Neutron on a single interface, the $PUBLIC_INTERFACE and
$OVS_PHYSICAL_BRIDGE variables must be set.

Co-Authored-By: Brian Haley <brian.haley@hp.com>

Change-Id: Ie35cb537bb670c4773598b8db29877fb8a12ff50

Sean M. Collins authored on 2015/02/21 01:45:21
Showing 1 changed files
... ...
@@ -780,9 +780,41 @@ function stop_neutron {
780 780
     fi
781 781
 }
782 782
 
783
+# _move_neutron_addresses_route() - Move the primary IP to the OVS bridge
784
+# on startup, or back to the public interface on cleanup
785
+function _move_neutron_addresses_route {
786
+    local from_intf=$1
787
+    local to_intf=$2
788
+    local add_ovs_port=$3
789
+
790
+    if [[ -n "$from_intf" && -n "$to_intf" ]]; then
791
+        # Remove the primary IP address from $from_intf and add it to $to_intf,
792
+        # along with the default route, if it exists.  Also, when called
793
+        # on configure we will also add $from_intf as a port on $to_intf,
794
+        # assuming it is an OVS bridge.
795
+
796
+        local IP_BRD=$(ip -4 a s dev $from_intf | awk '/inet/ { print $2, $3, $4; exit }')
797
+        local DEFAULT_ROUTE_GW=$(ip r | awk "/default.+$from_intf/ { print \$3; exit }")
798
+        local ADD_OVS_PORT=""
799
+
800
+        if [ "$DEFAULT_ROUTE_GW" != "" ]; then
801
+            ADD_DEFAULT_ROUTE="sudo ip r replace default via $DEFAULT_ROUTE_GW dev $to_intf"
802
+        fi
803
+
804
+        if [[ "$add_ovs_port" == "True" ]]; then
805
+            ADD_OVS_PORT="sudo ovs-vsctl add-port $to_intf $from_intf"
806
+        fi
807
+
808
+        sudo ip addr del $IP_BRD dev $from_intf; sudo ip addr add $IP_BRD dev $to_intf; $ADD_OVS_PORT; $ADD_DEFAULT_ROUTE
809
+    fi
810
+}
811
+
783 812
 # cleanup_neutron() - Remove residual data files, anything left over from previous
784 813
 # runs that a clean run would need to clean up
785 814
 function cleanup_neutron {
815
+
816
+    _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False
817
+
786 818
     if is_provider_network && is_ironic_hardware; then
787 819
         for IP in $(ip addr show dev $OVS_PHYSICAL_BRIDGE | grep ' inet ' | awk '{print $2}'); do
788 820
             sudo ip addr del $IP dev $OVS_PHYSICAL_BRIDGE
... ...
@@ -960,6 +992,8 @@ function _configure_neutron_l3_agent {
960 960
     _neutron_setup_interface_driver $Q_L3_CONF_FILE
961 961
 
962 962
     neutron_plugin_configure_l3_agent
963
+
964
+    _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" True
963 965
 }
964 966
 
965 967
 function _configure_neutron_metadata_agent {
... ...
@@ -1235,8 +1269,10 @@ function _neutron_configure_router_v4 {
1235 1235
         if is_neutron_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then
1236 1236
             local ext_gw_interface=$(_neutron_get_ext_gw_interface)
1237 1237
             local cidr_len=${FLOATING_RANGE#*/}
1238
-            sudo ip addr add $ext_gw_ip/$cidr_len dev $ext_gw_interface
1239
-            sudo ip link set $ext_gw_interface up
1238
+            if [[ $(ip addr show dev $ext_gw_interface | grep -c $ext_gw_ip) == 0 && $Q_USE_PROVIDERNET_FOR_PUBLIC == "False" ]]; then
1239
+                sudo ip addr add $ext_gw_ip/$cidr_len dev $ext_gw_interface
1240
+                sudo ip link set $ext_gw_interface up
1241
+            fi
1240 1242
             ROUTER_GW_IP=`neutron port-list -c fixed_ips -c device_owner | grep router_gateway | awk -F '"' -v subnet_id=$PUB_SUBNET_ID '$4 == subnet_id { print $8; }'`
1241 1243
             die_if_not_set $LINENO ROUTER_GW_IP "Failure retrieving ROUTER_GW_IP"
1242 1244
             sudo route add -net $FIXED_RANGE gw $ROUTER_GW_IP