blob: e1c3c3f11671260433626334e194370f4af0f860 [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
Ian Wienandaee18c72014-02-21 15:35:08 +110035function _neutron_ovs_base_install_agent_packages {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090036 local kernel_version
37 # Install deps
Mark McClainb05c8762013-07-06 23:29:39 -040038 # FIXME add to ``files/apts/neutron``, but don't install if not needed!
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090039 if is_ubuntu; then
40 kernel_version=`cat /proc/version | cut -d " " -f3`
41 install_package make fakeroot dkms openvswitch-switch openvswitch-datapath-dkms linux-headers-$kernel_version
Gary Kotton5452b182013-02-25 13:02:38 +000042 elif is_fedora; then
43 install_package openvswitch
44 # Ensure that the service is started
45 restart_service openvswitch
46 elif is_suse; then
Ralf Haferkampce03d102014-04-07 17:01:53 +020047 install_package openvswitch-switch
Vincent Untzcf6d8092013-07-04 09:59:34 +020048 restart_service openvswitch-switch
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090049 fi
50}
51
Ian Wienandaee18c72014-02-21 15:35:08 +110052function _neutron_ovs_base_configure_debug_command {
Mark McClainb05c8762013-07-06 23:29:39 -040053 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090054}
55
Ian Wienandaee18c72014-02-21 15:35:08 +110056function _neutron_ovs_base_configure_firewall_driver {
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +090057 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -040058 iniset /$Q_PLUGIN_CONF_FILE securitygroup firewall_driver neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +090059 else
Mark McClainb05c8762013-07-06 23:29:39 -040060 iniset /$Q_PLUGIN_CONF_FILE securitygroup firewall_driver neutron.agent.firewall.NoopFirewallDriver
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +090061 fi
62}
63
Ian Wienandaee18c72014-02-21 15:35:08 +110064function _neutron_ovs_base_configure_l3_agent {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090065 iniset $Q_L3_CONF_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE
66
Mark McClainb05c8762013-07-06 23:29:39 -040067 neutron-ovs-cleanup
Dave Tuckerf60e8c02014-06-11 17:02:24 +010068 # --no-wait causes a race condition if $PUBLIC_BRIDGE is not up when ip addr flush is called
69 sudo ovs-vsctl -- --may-exist add-br $PUBLIC_BRIDGE
70 sudo ovs-vsctl br-set-external-id $PUBLIC_BRIDGE bridge-id $PUBLIC_BRIDGE
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090071 # ensure no IP is configured on the public bridge
72 sudo ip addr flush dev $PUBLIC_BRIDGE
73}
74
Ian Wienandaee18c72014-02-21 15:35:08 +110075function _neutron_ovs_base_configure_nova_vif_driver {
Aaron Rosen4540d002013-10-24 13:59:33 -070076 :
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +090077}
78
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090079# Restore xtrace
Dean Troyere3a91602014-03-28 12:40:56 -050080$OVSB_XTRACE