Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 1 | # common functions for ovs based plugin |
| 2 | # ------------------------------------- |
| 3 | |
| 4 | # Save trace setting |
Dean Troyer | e3a9160 | 2014-03-28 12:40:56 -0500 | [diff] [blame] | 5 | OVSB_XTRACE=$(set +o | grep xtrace) |
Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 6 | set +o xtrace |
| 7 | |
JordanP | 614202f | 2013-05-16 11:16:13 +0200 | [diff] [blame] | 8 | OVS_BRIDGE=${OVS_BRIDGE:-br-int} |
| 9 | PUBLIC_BRIDGE=${PUBLIC_BRIDGE:-br-ex} |
| 10 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 11 | function is_neutron_ovs_base_plugin { |
Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 12 | # Yes, we use OVS. |
| 13 | return 0 |
| 14 | } |
| 15 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 16 | function _neutron_ovs_base_setup_bridge { |
Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 17 | local bridge=$1 |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 18 | neutron-ovs-cleanup |
Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 19 | sudo ovs-vsctl --no-wait -- --may-exist add-br $bridge |
| 20 | sudo ovs-vsctl --no-wait br-set-external-id $bridge bridge-id $bridge |
| 21 | } |
| 22 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 23 | function neutron_ovs_base_cleanup { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 24 | # remove all OVS ports that look like Neutron created ports |
JordanP | 614202f | 2013-05-16 11:16:13 +0200 | [diff] [blame] | 25 | for port in $(sudo ovs-vsctl list port | grep -o -e tap[0-9a-f\-]* -e q[rg]-[0-9a-f\-]*); do |
| 26 | sudo ovs-vsctl del-port ${port} |
| 27 | done |
| 28 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 29 | # remove all OVS bridges created by Neutron |
JordanP | 614202f | 2013-05-16 11:16:13 +0200 | [diff] [blame] | 30 | for bridge in $(sudo ovs-vsctl list-br | grep -o -e ${OVS_BRIDGE} -e ${PUBLIC_BRIDGE}); do |
| 31 | sudo ovs-vsctl del-br ${bridge} |
| 32 | done |
| 33 | } |
| 34 | |
Kyle Mestery | 86af4a0 | 2014-06-24 11:07:54 +0000 | [diff] [blame^] | 35 | function _neutron_ovs_base_install_ubuntu_dkms { |
| 36 | # install Dynamic Kernel Module Support packages if needed |
| 37 | local kernel_version=$(uname -r) |
| 38 | local kernel_major_minor=`echo $kernel_version | cut -d. -f1-2` |
| 39 | # From kernel 3.13 on, openvswitch-datapath-dkms is not needed |
| 40 | if [ `vercmp_numbers "$kernel_major_minor" "3.13"` -lt "0" ]; then |
| 41 | install_package "dkms openvswitch-datapath-dkms linux-headers-$kernel_version" |
| 42 | fi |
| 43 | } |
| 44 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 45 | function _neutron_ovs_base_install_agent_packages { |
Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 46 | # Install deps |
Kyle Mestery | 86af4a0 | 2014-06-24 11:07:54 +0000 | [diff] [blame^] | 47 | install_package $(get_packages "openvswitch") |
Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 48 | if is_ubuntu; then |
Kyle Mestery | 86af4a0 | 2014-06-24 11:07:54 +0000 | [diff] [blame^] | 49 | _neutron_ovs_base_install_ubuntu_dkms |
Gary Kotton | 5452b18 | 2013-02-25 13:02:38 +0000 | [diff] [blame] | 50 | elif is_fedora; then |
Gary Kotton | 5452b18 | 2013-02-25 13:02:38 +0000 | [diff] [blame] | 51 | restart_service openvswitch |
| 52 | elif is_suse; then |
Vincent Untz | cf6d809 | 2013-07-04 09:59:34 +0200 | [diff] [blame] | 53 | restart_service openvswitch-switch |
Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 54 | fi |
| 55 | } |
| 56 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 57 | function _neutron_ovs_base_configure_debug_command { |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 58 | iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE |
Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 59 | } |
| 60 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 61 | function _neutron_ovs_base_configure_firewall_driver { |
Akihiro MOTOKI | 3452f8e | 2013-03-21 14:11:27 +0900 | [diff] [blame] | 62 | if [[ "$Q_USE_SECGROUP" == "True" ]]; then |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 63 | iniset /$Q_PLUGIN_CONF_FILE securitygroup firewall_driver neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver |
Akihiro MOTOKI | 3452f8e | 2013-03-21 14:11:27 +0900 | [diff] [blame] | 64 | else |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 65 | iniset /$Q_PLUGIN_CONF_FILE securitygroup firewall_driver neutron.agent.firewall.NoopFirewallDriver |
Akihiro MOTOKI | 3452f8e | 2013-03-21 14:11:27 +0900 | [diff] [blame] | 66 | fi |
| 67 | } |
| 68 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 69 | function _neutron_ovs_base_configure_l3_agent { |
Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 70 | iniset $Q_L3_CONF_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE |
| 71 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 72 | neutron-ovs-cleanup |
Dave Tucker | f60e8c0 | 2014-06-11 17:02:24 +0100 | [diff] [blame] | 73 | # --no-wait causes a race condition if $PUBLIC_BRIDGE is not up when ip addr flush is called |
| 74 | sudo ovs-vsctl -- --may-exist add-br $PUBLIC_BRIDGE |
| 75 | sudo ovs-vsctl br-set-external-id $PUBLIC_BRIDGE bridge-id $PUBLIC_BRIDGE |
Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 76 | # ensure no IP is configured on the public bridge |
| 77 | sudo ip addr flush dev $PUBLIC_BRIDGE |
| 78 | } |
| 79 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 80 | function _neutron_ovs_base_configure_nova_vif_driver { |
Aaron Rosen | 4540d00 | 2013-10-24 13:59:33 -0700 | [diff] [blame] | 81 | : |
Akihiro MOTOKI | 3452f8e | 2013-03-21 14:11:27 +0900 | [diff] [blame] | 82 | } |
| 83 | |
Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 84 | # Restore xtrace |
Dean Troyer | e3a9160 | 2014-03-28 12:40:56 -0500 | [diff] [blame] | 85 | $OVSB_XTRACE |