Sean Dague | e263c82 | 2014-12-05 14:25:28 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
armando-migliaccio | 05952e3 | 2014-01-05 07:59:06 -0800 | [diff] [blame] | 3 | # 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 |
taturiello | e7f071b | 2014-10-15 05:09:45 -0700 | [diff] [blame] | 13 | # * NSX_GATEWAY_NETWORK_CIDR --> CIDR to configure $PUBLIC_BRIDGE, e.g. 172.24.4.211/24 |
armando-migliaccio | 05952e3 | 2014-01-05 07:59:06 -0800 | [diff] [blame] | 14 | |
| 15 | # Save trace setting |
Dean Troyer | e3a9160 | 2014-03-28 12:40:56 -0500 | [diff] [blame] | 16 | NSX3_XTRACE=$(set +o | grep xtrace) |
armando-migliaccio | 05952e3 | 2014-01-05 07:59:06 -0800 | [diff] [blame] | 17 | set +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 |
| 22 | NSX_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 |
| 25 | FLOATING_RANGE=${FLOATING_RANGE:-172.24.4.0/24} |
| 26 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 27 | function configure_vmware_nsx { |
armando-migliaccio | 05952e3 | 2014-01-05 07:59:06 -0800 | [diff] [blame] | 28 | : |
| 29 | } |
| 30 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 31 | function init_vmware_nsx { |
armando-migliaccio | 05952e3 | 2014-01-05 07:59:06 -0800 | [diff] [blame] | 32 | if ! is_set NSX_GATEWAY_NETWORK_CIDR; then |
| 33 | NSX_GATEWAY_NETWORK_CIDR=$PUBLIC_NETWORK_GATEWAY/${FLOATING_RANGE#*/} |
taturiello | e7f071b | 2014-10-15 05:09:45 -0700 | [diff] [blame] | 34 | echo "The IP address to set on $PUBLIC_BRIDGE was not specified. " |
armando-migliaccio | 05952e3 | 2014-01-05 07:59:06 -0800 | [diff] [blame] | 35 | 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 |
taturiello | e7f071b | 2014-10-15 05:09:45 -0700 | [diff] [blame] | 47 | sudo ovs-vsctl --may-exist add-br $PUBLIC_BRIDGE |
| 48 | sudo ovs-vsctl --may-exist add-port $PUBLIC_BRIDGE $NSX_GATEWAY_NETWORK_INTERFACE |
armando-migliaccio | 05952e3 | 2014-01-05 07:59:06 -0800 | [diff] [blame] | 49 | 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 |
taturiello | e7f071b | 2014-10-15 05:09:45 -0700 | [diff] [blame] | 55 | sudo ip link set $PUBLIC_BRIDGE up |
armando-migliaccio | 05952e3 | 2014-01-05 07:59:06 -0800 | [diff] [blame] | 56 | } |
| 57 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 58 | function install_vmware_nsx { |
armando-migliaccio | 05952e3 | 2014-01-05 07:59:06 -0800 | [diff] [blame] | 59 | : |
| 60 | } |
| 61 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 62 | function start_vmware_nsx { |
armando-migliaccio | 05952e3 | 2014-01-05 07:59:06 -0800 | [diff] [blame] | 63 | : |
| 64 | } |
| 65 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 66 | function stop_vmware_nsx { |
armando-migliaccio | 05952e3 | 2014-01-05 07:59:06 -0800 | [diff] [blame] | 67 | if ! is_set NSX_GATEWAY_NETWORK_CIDR; then |
| 68 | NSX_GATEWAY_NETWORK_CIDR=$PUBLIC_NETWORK_GATEWAY/${FLOATING_RANGE#*/} |
taturiello | e7f071b | 2014-10-15 05:09:45 -0700 | [diff] [blame] | 69 | echo "The IP address expected on $PUBLIC_BRIDGE was not specified. " |
armando-migliaccio | 05952e3 | 2014-01-05 07:59:06 -0800 | [diff] [blame] | 70 | 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 Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 84 | function check_vmware_nsx { |
armando-migliaccio | db20cd5 | 2014-01-05 07:41:30 -0800 | [diff] [blame] | 85 | neutron-check-nsx-config $NEUTRON_CONF_DIR/plugins/vmware/nsx.ini |
armando-migliaccio | ef1e080 | 2014-01-02 16:33:53 -0800 | [diff] [blame] | 86 | } |
| 87 | |
armando-migliaccio | 05952e3 | 2014-01-05 07:59:06 -0800 | [diff] [blame] | 88 | # Restore xtrace |
Dean Troyer | e3a9160 | 2014-03-28 12:40:56 -0500 | [diff] [blame] | 89 | $NSX3_XTRACE |