try again, with puppetforge modules, correctly included now
[mirror/dsa-puppet.git] / 3rdparty / modules / neutron / manifests / agents / ml2 / ovs.pp
1 #
2 # Copyright (C) 2014 eNovance SAS <licensing@enovance.com>
3 #
4 # Author: Emilien Macchi <emilien.macchi@enovance.com>
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License"); you may
7 # not use this file except in compliance with the License. You may obtain
8 # a copy of the License at
9 #
10 #      http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 # License for the specific language governing permissions and limitations
16 # under the License.
17 #
18 # == Class: neutron::agents::ml2::ovs
19 #
20 # Setups OVS neutron agent when using ML2 plugin
21 #
22 # === Parameters
23 #
24 # [*package_ensure*]
25 #   (optional) The state of the package
26 #   Defaults to 'present'
27 #
28 # [*enabled*]
29 #   (required) Whether or not to enable the OVS Agent
30 #   Defaults to true
31 #
32 # [*bridge_uplinks*]
33 #   (optional) List of interfaces to connect to the bridge when doing
34 #   bridge mapping.
35 #   Defaults to empty list
36 #
37 # [*bridge_mapping*]
38 #   (optional) List of <physical_network>:<bridge>
39 #   Defaults to empty list
40 #
41 # [*integration_bridge*]
42 #   (optional) Integration bridge in OVS
43 #   Defaults to 'br-int'
44 #
45 # [*enable_tunneling*]
46 #   (optional) Enable or not tunneling
47 #   Defaults to false
48 #
49 # [*tunnel_types*]
50 #   (optional) List of types of tunnels to use when utilizing tunnels,
51 #   either 'gre' or 'vxlan'.
52 #   Defaults to false
53 #
54 # [*local_ip*]
55 #   (optional) Local IP address of GRE tunnel endpoints.
56 #   Required when enabling tunneling
57 #   Defaults to false
58 #
59 # [*tunnel_bridge*]
60 #   (optional) Bridge used to transport tunnels
61 #   Defaults to 'br-tun'
62 #
63 # [*vxlan_udp_port*]
64 #   (optional) The UDP port to use for VXLAN tunnels.
65 #   Defaults to '4789'
66 #
67 # [*polling_interval*]
68 #   (optional) The number of seconds the agent will wait between
69 #   polling for local device changes.
70 #   Defaults to '2"
71 #
72 # [*l2_population*]
73 #   (optional) Extension to use alongside ml2 plugin's l2population
74 #   mechanism driver.
75 #   Defaults to false
76 #
77 # [*arp_responder*]
78 #   (optional) Enable or not the ARP responder.
79 #   Recommanded when using l2 population mechanism driver.
80 #   Defaults to false
81 #
82 # [*firewall_driver*]
83 #   (optional) Firewall driver for realizing neutron security group function.
84 #   Defaults to 'neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver'.
85 #
86 # [*enable_distributed_routing*]
87 #   (optional) Set to True on L2 agents to enable support
88 #   for distributed virtual routing.
89 #   Defaults to false
90 #
91 class neutron::agents::ml2::ovs (
92   $package_ensure             = 'present',
93   $enabled                    = true,
94   $bridge_uplinks             = [],
95   $bridge_mappings            = [],
96   $integration_bridge         = 'br-int',
97   $enable_tunneling           = false,
98   $tunnel_types               = [],
99   $local_ip                   = false,
100   $tunnel_bridge              = 'br-tun',
101   $vxlan_udp_port             = 4789,
102   $polling_interval           = 2,
103   $l2_population              = false,
104   $arp_responder              = false,
105   $firewall_driver            = 'neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver',
106   $enable_distributed_routing = false,
107 ) {
108
109   include neutron::params
110   require vswitch::ovs
111
112   if $enable_tunneling and ! $local_ip {
113     fail('Local ip for ovs agent must be set when tunneling is enabled')
114   }
115
116   if $enable_distributed_routing and ! $l2_population {
117     fail('L2 population must be enabled when DVR is enabled')
118   }
119
120   Neutron_plugin_ml2<||> ~> Service['neutron-ovs-agent-service']
121
122   if ($bridge_mappings != []) {
123     # bridge_mappings are used to describe external networks that are
124     # *directly* attached to this machine.
125     # (This has nothing to do with VM-VM comms over neutron virtual networks.)
126     # Typically, the network node - running L3 agent - will want one external
127     # network (often this is on the control node) and the other nodes (all the
128     # compute nodes) will want none at all.  The only other reason you will
129     # want to add networks here is if you're using provider networks, in which
130     # case you will name the network with bridge_mappings and add the server's
131     # interfaces that are attached to that network with bridge_uplinks.
132     # (The bridge names can be nearly anything, they just have to match between
133     # mappings and uplinks; they're what the OVS switches will get named.)
134
135     # Set config for bridges that we're going to create
136     # The OVS neutron plugin will talk in terms of the networks in the bridge_mappings
137     $br_map_str = join($bridge_mappings, ',')
138     neutron_plugin_ml2 {
139       'ovs/bridge_mappings': value => $br_map_str;
140     }
141     neutron::plugins::ovs::bridge{ $bridge_mappings:
142       before => Service['neutron-ovs-agent-service'],
143     }
144     neutron::plugins::ovs::port{ $bridge_uplinks:
145       before => Service['neutron-ovs-agent-service'],
146     }
147   }
148
149   neutron_plugin_ml2 {
150     'agent/polling_interval':           value => $polling_interval;
151     'agent/l2_population':              value => $l2_population;
152     'agent/arp_responder':              value => $arp_responder;
153     'agent/enable_distributed_routing': value => $enable_distributed_routing;
154     'ovs/integration_bridge':           value => $integration_bridge;
155   }
156
157   if ($firewall_driver) {
158     neutron_plugin_ml2 { 'securitygroup/firewall_driver':
159       value => $firewall_driver
160     }
161   } else {
162     neutron_plugin_ml2 { 'securitygroup/firewall_driver': ensure => absent }
163   }
164
165   vs_bridge { $integration_bridge:
166     ensure => present,
167     before => Service['neutron-ovs-agent-service'],
168   }
169
170   if $enable_tunneling {
171     vs_bridge { $tunnel_bridge:
172       ensure => present,
173       before => Service['neutron-ovs-agent-service'],
174     }
175     neutron_plugin_ml2 {
176       'ovs/enable_tunneling': value => true;
177       'ovs/tunnel_bridge':    value => $tunnel_bridge;
178       'ovs/local_ip':         value => $local_ip;
179     }
180
181     if size($tunnel_types) > 0 {
182       neutron_plugin_ml2 {
183         'agent/tunnel_types': value => join($tunnel_types, ',');
184       }
185     }
186     if 'vxlan' in $tunnel_types {
187       validate_vxlan_udp_port($vxlan_udp_port)
188       neutron_plugin_ml2 {
189         'agent/vxlan_udp_port': value => $vxlan_udp_port;
190       }
191     }
192   } else {
193     neutron_plugin_ml2 {
194       'ovs/enable_tunneling': value  => false;
195       'ovs/tunnel_bridge':    ensure => absent;
196       'ovs/local_ip':         ensure => absent;
197     }
198   }
199
200
201   if $::neutron::params::ovs_agent_package {
202     Package['neutron-ovs-agent'] -> Neutron_plugin_ml2<||>
203     package { 'neutron-ovs-agent':
204       ensure  => $package_ensure,
205       name    => $::neutron::params::ovs_agent_package,
206     }
207   } else {
208     # Some platforms (RedHat) do not provide a separate
209     # neutron plugin ovs agent package. The configuration file for
210     # the ovs agent is provided by the neutron ovs plugin package.
211     Package['neutron-ovs-agent'] -> Neutron_plugin_ml2<||>
212     Package['neutron-ovs-agent'] -> Service['ovs-cleanup-service']
213
214     if ! defined(Package['neutron-ovs-agent']) {
215       package { 'neutron-ovs-agent':
216         ensure  => $package_ensure,
217         name    => $::neutron::params::ovs_server_package,
218       } ->
219       # https://bugzilla.redhat.com/show_bug.cgi?id=1087647
220       # Causes init script for agent to load the old ovs file
221       # instead of the ml2 config file.
222       file { '/etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini':
223         ensure => link,
224         target => '/etc/neutron/plugins/ml2/ml2_conf.ini'
225       } ~> Service<| title == 'neutron-ovs-agent-service' |>
226     }
227   }
228
229   if $enabled {
230     $service_ensure = 'running'
231   } else {
232     $service_ensure = 'stopped'
233   }
234
235   service { 'neutron-ovs-agent-service':
236     ensure  => $service_ensure,
237     name    => $::neutron::params::ovs_agent_service,
238     enable  => $enabled,
239     require => Class['neutron'],
240   }
241
242   if $::neutron::params::ovs_cleanup_service {
243     Package['neutron-ovs-agent'] -> Service['ovs-cleanup-service']
244     service { 'ovs-cleanup-service':
245       name   => $::neutron::params::ovs_cleanup_service,
246       enable => $enabled,
247     }
248   }
249 }