| 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 | 8d55be3 | 2013-02-07 17:16:35 -0600 | [diff] [blame] | 5 | MY_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 |  | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 11 | function is_quantum_ovs_base_plugin() { | 
|  | 12 | # Yes, we use OVS. | 
|  | 13 | return 0 | 
|  | 14 | } | 
|  | 15 |  | 
|  | 16 | function _quantum_ovs_base_setup_bridge() { | 
|  | 17 | local bridge=$1 | 
| Davanum Srinivas | 88a3bc1 | 2013-02-04 09:16:14 -0500 | [diff] [blame] | 18 | quantum-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 |  | 
| JordanP | 614202f | 2013-05-16 11:16:13 +0200 | [diff] [blame] | 23 | function quantum_ovs_base_cleanup() { | 
|  | 24 | # remove all OVS ports that look like Quantum created ports | 
|  | 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 |  | 
|  | 29 | # remove all OVS bridges created by Quantum | 
|  | 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 |  | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 35 | function _quantum_ovs_base_install_agent_packages() { | 
|  | 36 | local kernel_version | 
|  | 37 | # Install deps | 
|  | 38 | # FIXME add to ``files/apts/quantum``, but don't install if not needed! | 
|  | 39 | 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 Kotton | 5452b18 | 2013-02-25 13:02:38 +0000 | [diff] [blame] | 42 | 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 Untz | 3f34d9a | 2013-03-12 17:57:36 +0100 | [diff] [blame] | 47 | ### FIXME: Find out if package can be pushed to Factory | 
|  | 48 | echo "OpenVSwitch packages can be installed from Cloud:OpenStack:Master in OBS" | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 49 | restart_service openvswitch | 
|  | 50 | fi | 
|  | 51 | } | 
|  | 52 |  | 
|  | 53 | function _quantum_ovs_base_configure_debug_command() { | 
|  | 54 | iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE | 
|  | 55 | } | 
|  | 56 |  | 
| Akihiro MOTOKI | 3452f8e | 2013-03-21 14:11:27 +0900 | [diff] [blame] | 57 | function _quantum_ovs_base_configure_firewall_driver() { | 
|  | 58 | if [[ "$Q_USE_SECGROUP" == "True" ]]; then | 
|  | 59 | iniset /$Q_PLUGIN_CONF_FILE SECURITYGROUP firewall_driver quantum.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver | 
|  | 60 | else | 
|  | 61 | iniset /$Q_PLUGIN_CONF_FILE SECURITYGROUP firewall_driver quantum.agent.firewall.NoopFirewallDriver | 
|  | 62 | fi | 
|  | 63 | } | 
|  | 64 |  | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 65 | function _quantum_ovs_base_configure_l3_agent() { | 
|  | 66 | iniset $Q_L3_CONF_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE | 
|  | 67 |  | 
| Davanum Srinivas | 88a3bc1 | 2013-02-04 09:16:14 -0500 | [diff] [blame] | 68 | quantum-ovs-cleanup | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 69 | sudo ovs-vsctl --no-wait -- --may-exist add-br $PUBLIC_BRIDGE | 
|  | 70 | # ensure no IP is configured on the public bridge | 
|  | 71 | sudo ip addr flush dev $PUBLIC_BRIDGE | 
|  | 72 | } | 
|  | 73 |  | 
| Akihiro MOTOKI | 3452f8e | 2013-03-21 14:11:27 +0900 | [diff] [blame] | 74 | function _quantum_ovs_base_configure_nova_vif_driver() { | 
|  | 75 | # The hybrid VIF driver needs to be specified when Quantum Security Group | 
|  | 76 | # is enabled (until vif_security attributes are supported in VIF extension) | 
|  | 77 | if [[ "$Q_USE_SECGROUP" == "True" ]]; then | 
|  | 78 | NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.LibvirtHybridOVSBridgeDriver"} | 
|  | 79 | else | 
|  | 80 | NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.LibvirtGenericVIFDriver"} | 
|  | 81 | fi | 
|  | 82 | } | 
|  | 83 |  | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 84 | # Restore xtrace | 
| Dean Troyer | 8d55be3 | 2013-02-07 17:16:35 -0600 | [diff] [blame] | 85 | $MY_XTRACE |