| armando-migliaccio | 05952e3 | 2014-01-05 07:59:06 -0800 | [diff] [blame] | 1 | # VMware NSX | 
 | 2 | # ---------- | 
 | 3 |  | 
 | 4 | # This third-party addition can be used to configure connectivity between a DevStack instance | 
 | 5 | # and an NSX Gateway in dev/test environments. In order to use this correctly, the following | 
 | 6 | # env variables need to be set (e.g. in your localrc file): | 
 | 7 | # | 
 | 8 | # * enable_service vmware_nsx        --> to execute this third-party addition | 
 | 9 | # * PUBLIC_BRIDGE                    --> bridge used for external connectivity, typically br-ex | 
 | 10 | # * NSX_GATEWAY_NETWORK_INTERFACE    --> interface used to communicate with the NSX Gateway | 
 | 11 | # * NSX_GATEWAY_NETWORK_CIDR         --> CIDR to configure br-ex, e.g. 172.24.4.211/24 | 
 | 12 |  | 
 | 13 | # Save trace setting | 
| Dean Troyer | e3a9160 | 2014-03-28 12:40:56 -0500 | [diff] [blame] | 14 | NSX3_XTRACE=$(set +o | grep xtrace) | 
| armando-migliaccio | 05952e3 | 2014-01-05 07:59:06 -0800 | [diff] [blame] | 15 | set +o xtrace | 
 | 16 |  | 
 | 17 | # This is the interface that connects the Devstack instance | 
 | 18 | # to an network that allows it to talk to the gateway for | 
 | 19 | # testing purposes | 
 | 20 | NSX_GATEWAY_NETWORK_INTERFACE=${NSX_GATEWAY_NETWORK_INTERFACE:-eth2} | 
 | 21 | # Re-declare floating range as it's needed also in stop_vmware_nsx, which | 
 | 22 | # is invoked by unstack.sh | 
 | 23 | FLOATING_RANGE=${FLOATING_RANGE:-172.24.4.0/24} | 
 | 24 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 25 | function configure_vmware_nsx { | 
| armando-migliaccio | 05952e3 | 2014-01-05 07:59:06 -0800 | [diff] [blame] | 26 |     : | 
 | 27 | } | 
 | 28 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 29 | function init_vmware_nsx { | 
| armando-migliaccio | 05952e3 | 2014-01-05 07:59:06 -0800 | [diff] [blame] | 30 |     if ! is_set NSX_GATEWAY_NETWORK_CIDR; then | 
 | 31 |         NSX_GATEWAY_NETWORK_CIDR=$PUBLIC_NETWORK_GATEWAY/${FLOATING_RANGE#*/} | 
 | 32 |         echo "The IP address to set on br-ex was not specified. " | 
 | 33 |         echo "Defaulting to "$NSX_GATEWAY_NETWORK_CIDR | 
 | 34 |     fi | 
 | 35 |     # Make sure the interface is up, but not configured | 
 | 36 |     sudo ip link set $NSX_GATEWAY_NETWORK_INTERFACE up | 
 | 37 |     # Save and then flush the IP addresses on the interface | 
 | 38 |     addresses=$(ip addr show dev $NSX_GATEWAY_NETWORK_INTERFACE | grep inet | awk {'print $2'}) | 
 | 39 |     sudo ip addr flush $NSX_GATEWAY_NETWORK_INTERFACE | 
 | 40 |     # Use the PUBLIC Bridge to route traffic to the NSX gateway | 
 | 41 |     # NOTE(armando-migliaccio): if running in a nested environment this will work | 
 | 42 |     # only with mac learning enabled, portsecurity and security profiles disabled | 
 | 43 |     # The public bridge might not exist for the NSX plugin if Q_USE_DEBUG_COMMAND is off | 
 | 44 |     # Try to create it anyway | 
 | 45 |     sudo ovs-vsctl --no-wait -- --may-exist add-br $PUBLIC_BRIDGE | 
 | 46 |     sudo ovs-vsctl -- --may-exist add-port $PUBLIC_BRIDGE $NSX_GATEWAY_NETWORK_INTERFACE | 
 | 47 |     nsx_gw_net_if_mac=$(ip link show $NSX_GATEWAY_NETWORK_INTERFACE | awk '/ether/ {print $2}') | 
 | 48 |     sudo ip link set address $nsx_gw_net_if_mac dev $PUBLIC_BRIDGE | 
 | 49 |     for address in $addresses; do | 
 | 50 |         sudo ip addr add dev $PUBLIC_BRIDGE $address | 
 | 51 |     done | 
 | 52 |     sudo ip addr add dev $PUBLIC_BRIDGE $NSX_GATEWAY_NETWORK_CIDR | 
 | 53 | } | 
 | 54 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 55 | function install_vmware_nsx { | 
| armando-migliaccio | 05952e3 | 2014-01-05 07:59:06 -0800 | [diff] [blame] | 56 |     : | 
 | 57 | } | 
 | 58 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 59 | function start_vmware_nsx { | 
| armando-migliaccio | 05952e3 | 2014-01-05 07:59:06 -0800 | [diff] [blame] | 60 |     : | 
 | 61 | } | 
 | 62 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 63 | function stop_vmware_nsx { | 
| armando-migliaccio | 05952e3 | 2014-01-05 07:59:06 -0800 | [diff] [blame] | 64 |     if ! is_set NSX_GATEWAY_NETWORK_CIDR; then | 
 | 65 |         NSX_GATEWAY_NETWORK_CIDR=$PUBLIC_NETWORK_GATEWAY/${FLOATING_RANGE#*/} | 
 | 66 |         echo "The IP address expected on br-ex was not specified. " | 
 | 67 |         echo "Defaulting to "$NSX_GATEWAY_NETWORK_CIDR | 
 | 68 |     fi | 
 | 69 |     sudo ip addr del $NSX_GATEWAY_NETWORK_CIDR dev $PUBLIC_BRIDGE | 
 | 70 |     # Save and then flush remaining addresses on the interface | 
 | 71 |     addresses=$(ip addr show dev $PUBLIC_BRIDGE | grep inet | awk {'print $2'}) | 
 | 72 |     sudo ip addr flush $PUBLIC_BRIDGE | 
 | 73 |     # Try to detach physical interface from PUBLIC_BRIDGE | 
 | 74 |     sudo ovs-vsctl del-port $NSX_GATEWAY_NETWORK_INTERFACE | 
 | 75 |     # Restore addresses on NSX_GATEWAY_NETWORK_INTERFACE | 
 | 76 |     for address in $addresses; do | 
 | 77 |         sudo ip addr add dev $NSX_GATEWAY_NETWORK_INTERFACE $address | 
 | 78 |     done | 
 | 79 | } | 
 | 80 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 81 | function check_vmware_nsx { | 
| armando-migliaccio | db20cd5 | 2014-01-05 07:41:30 -0800 | [diff] [blame] | 82 |     neutron-check-nsx-config $NEUTRON_CONF_DIR/plugins/vmware/nsx.ini | 
| armando-migliaccio | ef1e080 | 2014-01-02 16:33:53 -0800 | [diff] [blame] | 83 | } | 
 | 84 |  | 
| armando-migliaccio | 05952e3 | 2014-01-05 07:59:06 -0800 | [diff] [blame] | 85 | # Restore xtrace | 
| Dean Troyer | e3a9160 | 2014-03-28 12:40:56 -0500 | [diff] [blame] | 86 | $NSX3_XTRACE |