blob: 7027a29892fd12801a6fd09d6f1f7a05da5b805b [file] [log] [blame]
Sean Daguee263c822014-12-05 14:25:28 -05001#!/bin/bash
2#
armando-migliaccio05952e32014-01-05 07:59:06 -08003# VMware NSX
4# ----------
5
6# This third-party addition can be used to configure connectivity between a DevStack instance
7# and an NSX Gateway in dev/test environments. In order to use this correctly, the following
8# env variables need to be set (e.g. in your localrc file):
9#
10# * enable_service vmware_nsx --> to execute this third-party addition
11# * PUBLIC_BRIDGE --> bridge used for external connectivity, typically br-ex
12# * NSX_GATEWAY_NETWORK_INTERFACE --> interface used to communicate with the NSX Gateway
taturielloe7f071b2014-10-15 05:09:45 -070013# * NSX_GATEWAY_NETWORK_CIDR --> CIDR to configure $PUBLIC_BRIDGE, e.g. 172.24.4.211/24
armando-migliaccio05952e32014-01-05 07:59:06 -080014
15# Save trace setting
Dean Troyere3a91602014-03-28 12:40:56 -050016NSX3_XTRACE=$(set +o | grep xtrace)
armando-migliaccio05952e32014-01-05 07:59:06 -080017set +o xtrace
18
19# This is the interface that connects the Devstack instance
20# to an network that allows it to talk to the gateway for
21# testing purposes
22NSX_GATEWAY_NETWORK_INTERFACE=${NSX_GATEWAY_NETWORK_INTERFACE:-eth2}
23# Re-declare floating range as it's needed also in stop_vmware_nsx, which
24# is invoked by unstack.sh
25FLOATING_RANGE=${FLOATING_RANGE:-172.24.4.0/24}
26
Ian Wienandaee18c72014-02-21 15:35:08 +110027function configure_vmware_nsx {
armando-migliaccio05952e32014-01-05 07:59:06 -080028 :
29}
30
Ian Wienandaee18c72014-02-21 15:35:08 +110031function init_vmware_nsx {
armando-migliaccio05952e32014-01-05 07:59:06 -080032 if ! is_set NSX_GATEWAY_NETWORK_CIDR; then
33 NSX_GATEWAY_NETWORK_CIDR=$PUBLIC_NETWORK_GATEWAY/${FLOATING_RANGE#*/}
taturielloe7f071b2014-10-15 05:09:45 -070034 echo "The IP address to set on $PUBLIC_BRIDGE was not specified. "
armando-migliaccio05952e32014-01-05 07:59:06 -080035 echo "Defaulting to "$NSX_GATEWAY_NETWORK_CIDR
36 fi
37 # Make sure the interface is up, but not configured
38 sudo ip link set $NSX_GATEWAY_NETWORK_INTERFACE up
39 # Save and then flush the IP addresses on the interface
40 addresses=$(ip addr show dev $NSX_GATEWAY_NETWORK_INTERFACE | grep inet | awk {'print $2'})
41 sudo ip addr flush $NSX_GATEWAY_NETWORK_INTERFACE
42 # Use the PUBLIC Bridge to route traffic to the NSX gateway
43 # NOTE(armando-migliaccio): if running in a nested environment this will work
44 # only with mac learning enabled, portsecurity and security profiles disabled
45 # The public bridge might not exist for the NSX plugin if Q_USE_DEBUG_COMMAND is off
46 # Try to create it anyway
taturielloe7f071b2014-10-15 05:09:45 -070047 sudo ovs-vsctl --may-exist add-br $PUBLIC_BRIDGE
48 sudo ovs-vsctl --may-exist add-port $PUBLIC_BRIDGE $NSX_GATEWAY_NETWORK_INTERFACE
armando-migliaccio05952e32014-01-05 07:59:06 -080049 nsx_gw_net_if_mac=$(ip link show $NSX_GATEWAY_NETWORK_INTERFACE | awk '/ether/ {print $2}')
50 sudo ip link set address $nsx_gw_net_if_mac dev $PUBLIC_BRIDGE
51 for address in $addresses; do
52 sudo ip addr add dev $PUBLIC_BRIDGE $address
53 done
54 sudo ip addr add dev $PUBLIC_BRIDGE $NSX_GATEWAY_NETWORK_CIDR
taturielloe7f071b2014-10-15 05:09:45 -070055 sudo ip link set $PUBLIC_BRIDGE up
armando-migliaccio05952e32014-01-05 07:59:06 -080056}
57
Ian Wienandaee18c72014-02-21 15:35:08 +110058function install_vmware_nsx {
armando-migliaccio05952e32014-01-05 07:59:06 -080059 :
60}
61
Ian Wienandaee18c72014-02-21 15:35:08 +110062function start_vmware_nsx {
armando-migliaccio05952e32014-01-05 07:59:06 -080063 :
64}
65
Ian Wienandaee18c72014-02-21 15:35:08 +110066function stop_vmware_nsx {
armando-migliaccio05952e32014-01-05 07:59:06 -080067 if ! is_set NSX_GATEWAY_NETWORK_CIDR; then
68 NSX_GATEWAY_NETWORK_CIDR=$PUBLIC_NETWORK_GATEWAY/${FLOATING_RANGE#*/}
taturielloe7f071b2014-10-15 05:09:45 -070069 echo "The IP address expected on $PUBLIC_BRIDGE was not specified. "
armando-migliaccio05952e32014-01-05 07:59:06 -080070 echo "Defaulting to "$NSX_GATEWAY_NETWORK_CIDR
71 fi
72 sudo ip addr del $NSX_GATEWAY_NETWORK_CIDR dev $PUBLIC_BRIDGE
73 # Save and then flush remaining addresses on the interface
74 addresses=$(ip addr show dev $PUBLIC_BRIDGE | grep inet | awk {'print $2'})
75 sudo ip addr flush $PUBLIC_BRIDGE
76 # Try to detach physical interface from PUBLIC_BRIDGE
77 sudo ovs-vsctl del-port $NSX_GATEWAY_NETWORK_INTERFACE
78 # Restore addresses on NSX_GATEWAY_NETWORK_INTERFACE
79 for address in $addresses; do
80 sudo ip addr add dev $NSX_GATEWAY_NETWORK_INTERFACE $address
81 done
82}
83
Ian Wienandaee18c72014-02-21 15:35:08 +110084function check_vmware_nsx {
armando-migliacciodb20cd52014-01-05 07:41:30 -080085 neutron-check-nsx-config $NEUTRON_CONF_DIR/plugins/vmware/nsx.ini
armando-migliaccioef1e0802014-01-02 16:33:53 -080086}
87
armando-migliaccio05952e32014-01-05 07:59:06 -080088# Restore xtrace
Dean Troyere3a91602014-03-28 12:40:56 -050089$NSX3_XTRACE