blob: 0fa919890f3862fd38e563981bf661e2ff49cce4 [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}
James Chapmanc83cc752014-06-11 19:29:26 +010010OVS_DATAPATH_TYPE=${OVS_DATAPATH_TYPE:-""}
JordanP614202f2013-05-16 11:16:13 +020011
Ian Wienandaee18c72014-02-21 15:35:08 +110012function is_neutron_ovs_base_plugin {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090013 # Yes, we use OVS.
14 return 0
15}
16
Ian Wienandaee18c72014-02-21 15:35:08 +110017function _neutron_ovs_base_setup_bridge {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090018 local bridge=$1
Mark McClainb05c8762013-07-06 23:29:39 -040019 neutron-ovs-cleanup
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090020 sudo ovs-vsctl --no-wait -- --may-exist add-br $bridge
James Chapmanc83cc752014-06-11 19:29:26 +010021 if [[ $OVS_DATAPATH_TYPE != "" ]]; then
22 sudo ovs-vsctl set Bridge $bridge datapath_type=${OVS_DATAPATH_TYPE}
23 fi
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090024 sudo ovs-vsctl --no-wait br-set-external-id $bridge bridge-id $bridge
25}
26
Ian Wienandaee18c72014-02-21 15:35:08 +110027function neutron_ovs_base_cleanup {
Mark McClainb05c8762013-07-06 23:29:39 -040028 # remove all OVS ports that look like Neutron created ports
JordanP614202f2013-05-16 11:16:13 +020029 for port in $(sudo ovs-vsctl list port | grep -o -e tap[0-9a-f\-]* -e q[rg]-[0-9a-f\-]*); do
30 sudo ovs-vsctl del-port ${port}
31 done
32
Mark McClainb05c8762013-07-06 23:29:39 -040033 # remove all OVS bridges created by Neutron
JordanP614202f2013-05-16 11:16:13 +020034 for bridge in $(sudo ovs-vsctl list-br | grep -o -e ${OVS_BRIDGE} -e ${PUBLIC_BRIDGE}); do
35 sudo ovs-vsctl del-br ${bridge}
36 done
37}
38
Ian Wienandaee18c72014-02-21 15:35:08 +110039function _neutron_ovs_base_install_agent_packages {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090040 local kernel_version
41 # Install deps
Mark McClainb05c8762013-07-06 23:29:39 -040042 # FIXME add to ``files/apts/neutron``, but don't install if not needed!
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090043 if is_ubuntu; then
44 kernel_version=`cat /proc/version | cut -d " " -f3`
45 install_package make fakeroot dkms openvswitch-switch openvswitch-datapath-dkms linux-headers-$kernel_version
Gary Kotton5452b182013-02-25 13:02:38 +000046 elif is_fedora; then
47 install_package openvswitch
48 # Ensure that the service is started
49 restart_service openvswitch
50 elif is_suse; then
Ralf Haferkampce03d102014-04-07 17:01:53 +020051 install_package openvswitch-switch
Vincent Untzcf6d8092013-07-04 09:59:34 +020052 restart_service openvswitch-switch
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090053 fi
54}
55
Ian Wienandaee18c72014-02-21 15:35:08 +110056function _neutron_ovs_base_configure_debug_command {
Mark McClainb05c8762013-07-06 23:29:39 -040057 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090058}
59
Ian Wienandaee18c72014-02-21 15:35:08 +110060function _neutron_ovs_base_configure_firewall_driver {
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +090061 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -040062 iniset /$Q_PLUGIN_CONF_FILE securitygroup firewall_driver neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +090063 else
Mark McClainb05c8762013-07-06 23:29:39 -040064 iniset /$Q_PLUGIN_CONF_FILE securitygroup firewall_driver neutron.agent.firewall.NoopFirewallDriver
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +090065 fi
66}
67
Ian Wienandaee18c72014-02-21 15:35:08 +110068function _neutron_ovs_base_configure_l3_agent {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090069 iniset $Q_L3_CONF_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE
70
Mark McClainb05c8762013-07-06 23:29:39 -040071 neutron-ovs-cleanup
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090072 sudo ovs-vsctl --no-wait -- --may-exist add-br $PUBLIC_BRIDGE
Gary Kotton503e9ac2013-07-15 09:41:25 -070073 sudo ovs-vsctl --no-wait br-set-external-id $PUBLIC_BRIDGE bridge-id $PUBLIC_BRIDGE
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090074 # ensure no IP is configured on the public bridge
75 sudo ip addr flush dev $PUBLIC_BRIDGE
76}
77
Ian Wienandaee18c72014-02-21 15:35:08 +110078function _neutron_ovs_base_configure_nova_vif_driver {
Aaron Rosen4540d002013-10-24 13:59:33 -070079 :
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +090080}
81
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090082# Restore xtrace
Dean Troyere3a91602014-03-28 12:40:56 -050083$OVSB_XTRACE