blob: 0a2ba58fbb31fc280dbb138a9a622191dba900f9 [file] [log] [blame]
Isaku Yamahata0dd34df2012-12-28 13:15:31 +09001# common functions for ovs based plugin
2# -------------------------------------
3
4# Save trace setting
Dean Troyer8d55be32013-02-07 17:16:35 -06005MY_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
Vincent Untzcf6d8092013-07-04 09:59:34 +020047 install_package openvswitch
48 restart_service openvswitch-switch
49 restart_service openvswitch-controller
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090050 fi
51}
52
Ian Wienandaee18c72014-02-21 15:35:08 +110053function _neutron_ovs_base_configure_debug_command {
Mark McClainb05c8762013-07-06 23:29:39 -040054 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090055}
56
Ian Wienandaee18c72014-02-21 15:35:08 +110057function _neutron_ovs_base_configure_firewall_driver {
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +090058 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -040059 iniset /$Q_PLUGIN_CONF_FILE securitygroup firewall_driver neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +090060 else
Mark McClainb05c8762013-07-06 23:29:39 -040061 iniset /$Q_PLUGIN_CONF_FILE securitygroup firewall_driver neutron.agent.firewall.NoopFirewallDriver
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +090062 fi
63}
64
Ian Wienandaee18c72014-02-21 15:35:08 +110065function _neutron_ovs_base_configure_l3_agent {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090066 iniset $Q_L3_CONF_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE
67
Mark McClainb05c8762013-07-06 23:29:39 -040068 neutron-ovs-cleanup
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090069 sudo ovs-vsctl --no-wait -- --may-exist add-br $PUBLIC_BRIDGE
Gary Kotton503e9ac2013-07-15 09:41:25 -070070 sudo ovs-vsctl --no-wait 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 Troyer8d55be32013-02-07 17:16:35 -060080$MY_XTRACE