blob: 26c5489c5b0e4393eee035e02fb2c5ae08fe580a [file] [log] [blame]
Isaku Yamahata0dd34df2012-12-28 13:15:31 +09001# common functions for ovs based plugin
2# -------------------------------------
3
4# Save trace setting
Dean Troyere3a91602014-03-28 12:40:56 -05005OVSB_XTRACE=$(set +o | grep xtrace)
Isaku Yamahata0dd34df2012-12-28 13:15:31 +09006set +o xtrace
7
JordanP614202f2013-05-16 11:16:13 +02008OVS_BRIDGE=${OVS_BRIDGE:-br-int}
9PUBLIC_BRIDGE=${PUBLIC_BRIDGE:-br-ex}
10
Ian Wienandaee18c72014-02-21 15:35:08 +110011function is_neutron_ovs_base_plugin {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090012 # Yes, we use OVS.
13 return 0
14}
15
Ian Wienandaee18c72014-02-21 15:35:08 +110016function _neutron_ovs_base_setup_bridge {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090017 local bridge=$1
Mark McClainb05c8762013-07-06 23:29:39 -040018 neutron-ovs-cleanup
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090019 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 Wienandaee18c72014-02-21 15:35:08 +110023function neutron_ovs_base_cleanup {
Mark McClainb05c8762013-07-06 23:29:39 -040024 # remove all OVS ports that look like Neutron created ports
JordanP614202f2013-05-16 11:16:13 +020025 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 McClainb05c8762013-07-06 23:29:39 -040029 # remove all OVS bridges created by Neutron
JordanP614202f2013-05-16 11:16:13 +020030 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 Mestery86af4a02014-06-24 11:07:54 +000035function _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 Wienandaee18c72014-02-21 15:35:08 +110045function _neutron_ovs_base_install_agent_packages {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090046 # Install deps
Kyle Mestery86af4a02014-06-24 11:07:54 +000047 install_package $(get_packages "openvswitch")
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090048 if is_ubuntu; then
Kyle Mestery86af4a02014-06-24 11:07:54 +000049 _neutron_ovs_base_install_ubuntu_dkms
Gary Kotton5452b182013-02-25 13:02:38 +000050 elif is_fedora; then
Gary Kotton5452b182013-02-25 13:02:38 +000051 restart_service openvswitch
52 elif is_suse; then
Vincent Untzcf6d8092013-07-04 09:59:34 +020053 restart_service openvswitch-switch
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090054 fi
55}
56
Ian Wienandaee18c72014-02-21 15:35:08 +110057function _neutron_ovs_base_configure_debug_command {
Mark McClainb05c8762013-07-06 23:29:39 -040058 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090059}
60
Ian Wienandaee18c72014-02-21 15:35:08 +110061function _neutron_ovs_base_configure_firewall_driver {
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +090062 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -040063 iniset /$Q_PLUGIN_CONF_FILE securitygroup firewall_driver neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +090064 else
Mark McClainb05c8762013-07-06 23:29:39 -040065 iniset /$Q_PLUGIN_CONF_FILE securitygroup firewall_driver neutron.agent.firewall.NoopFirewallDriver
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +090066 fi
67}
68
Ian Wienandaee18c72014-02-21 15:35:08 +110069function _neutron_ovs_base_configure_l3_agent {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090070 iniset $Q_L3_CONF_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE
71
Mark McClainb05c8762013-07-06 23:29:39 -040072 neutron-ovs-cleanup
Dave Tuckerf60e8c02014-06-11 17:02:24 +010073 # --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 Yamahata0dd34df2012-12-28 13:15:31 +090076 # ensure no IP is configured on the public bridge
77 sudo ip addr flush dev $PUBLIC_BRIDGE
78}
79
Ian Wienandaee18c72014-02-21 15:35:08 +110080function _neutron_ovs_base_configure_nova_vif_driver {
Aaron Rosen4540d002013-10-24 13:59:33 -070081 :
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +090082}
83
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090084# Restore xtrace
Dean Troyere3a91602014-03-28 12:40:56 -050085$OVSB_XTRACE