Merge "nsx-v3: Configure interface and route to external network"

This commit is contained in:
Jenkins 2016-03-09 12:55:26 +00:00 committed by Gerrit Code Review
commit b85ccb6579
2 changed files with 68 additions and 1 deletions

View File

@ -20,6 +20,12 @@
# Neutron VMware NSX plugin
# -------------------------
# Settings
# The interface which has connectivity to the NSX Gateway uplink
NSX_GATEWAY_NETWORK_INTERFACE=${NSX_GATEWAY_NETWORK_INTERFACE:-}
# Save trace setting
NSX_XTRACE=$(set +o | grep xtrace)
set +o xtrace
@ -127,5 +133,63 @@ function neutron_plugin_check_adv_test_requirements {
is_service_enabled q-dhcp && return 0
}
function init_vmware_nsx_v3 {
if ! is_set NSX_GATEWAY_NETWORK_INTERFACE; then
echo "NSX_GATEWAY_NETWORK_INTERFACE not set not configuring routes"
return
fi
if ! is_set NSX_GATEWAY_NETWORK_CIDR; then
NSX_GATEWAY_NETWORK_CIDR=$PUBLIC_NETWORK_GATEWAY/${FLOATING_RANGE#*/}
echo "The IP address to set on $PUBLIC_BRIDGE was not specified. "
echo "Defaulting to $NSX_GATEWAY_NETWORK_CIDR"
fi
# Make sure the interface is up, but not configured
sudo ip link set $NSX_GATEWAY_NETWORK_INTERFACE up
# Save and then flush the IP addresses on the interface
addresses=$(ip addr show dev $NSX_GATEWAY_NETWORK_INTERFACE | grep inet | awk {'print $2'})
sudo ip addr flush $NSX_GATEWAY_NETWORK_INTERFACE
# Use the PUBLIC Bridge to route traffic to the NSX gateway
# NOTE(armando-migliaccio): if running in a nested environment this will work
# only with mac learning enabled, portsecurity and security profiles disabled
# The public bridge might not exist for the NSX plugin if Q_USE_DEBUG_COMMAND is off
# Try to create it anyway
sudo ovs-vsctl --may-exist add-br $PUBLIC_BRIDGE
sudo ovs-vsctl --may-exist add-port $PUBLIC_BRIDGE $NSX_GATEWAY_NETWORK_INTERFACE
# Flush all existing addresses on public bridge
sudo ip addr flush dev $PUBLIC_BRIDGE
nsx_gw_net_if_mac=$(ip link show $NSX_GATEWAY_NETWORK_INTERFACE | awk '/ether/ {print $2}')
sudo ip link set address $nsx_gw_net_if_mac dev $PUBLIC_BRIDGE
for address in $addresses; do
sudo ip addr add dev $PUBLIC_BRIDGE $address
done
sudo ip addr add dev $PUBLIC_BRIDGE $NSX_GATEWAY_NETWORK_CIDR
sudo ip link set $PUBLIC_BRIDGE up
}
function stop_vmware_nsx_v3 {
if ! is_set NSX_GATEWAY_NETWORK_INTERFACE; then
echo "NSX_GATEWAY_NETWORK_INTERFACE was not configured."
return
fi
if ! is_set NSX_GATEWAY_NETWORK_CIDR; then
NSX_GATEWAY_NETWORK_CIDR=$PUBLIC_NETWORK_GATEWAY/${FLOATING_RANGE#*/}
echo "The IP address expected on $PUBLIC_BRIDGE was not specified. "
echo "Defaulting to "$NSX_GATEWAY_NETWORK_CIDR
fi
sudo ip addr del $NSX_GATEWAY_NETWORK_CIDR dev $PUBLIC_BRIDGE
# Save and then flush remaining addresses on the interface
addresses=$(ip addr show dev $PUBLIC_BRIDGE | grep inet | awk {'print $2'})
sudo ip addr flush $PUBLIC_BRIDGE
# Try to detach physical interface from PUBLIC_BRIDGE
sudo ovs-vsctl del-port $NSX_GATEWAY_NETWORK_INTERFACE
# Restore addresses on NSX_GATEWAY_NETWORK_INTERFACE
for address in $addresses; do
sudo ip addr add dev $NSX_GATEWAY_NETWORK_INTERFACE $address
done
}
# Restore xtrace
$NSX_XTRACE

View File

@ -39,7 +39,10 @@ elif [[ $Q_PLUGIN == 'vmware_nsx' ]]; then
fi
elif [[ $Q_PLUGIN == 'vmware_nsx_v3' ]]; then
source $dir/lib/vmware_nsx_v3
if [[ "$1" == "unstack" ]]; then
if [[ "$1" == "stack" && "$2" == "post-config" ]]; then
init_vmware_nsx_v3
elif [[ "$1" == "unstack" ]]; then
stop_vmware_nsx
NSX_MANAGER=${NSX_MANAGERS:-$NSX_MANAGER}
IFS=','
NSX_MANAGER=($NSX_MANAGER)