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: I71e2594288bae1a71dc2c8c3fb350b913dbd5e2c

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