File: controller.pp

package info (click to toggle)
puppet-module-ovn 25.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 428 kB
  • sloc: ruby: 588; python: 41; sh: 10; makefile: 10
file content (328 lines) | stat: -rw-r--r-- 11,452 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# ovn controller
# == Class: ovn::controller
#
# installs ovn and starts the ovn-controller service
#
# === Parameters:
#
# [*package_name*]
#   (required) Name of ovn-controller package.
#
# [*service_name*]
#   (required) Name of ovn-controller service.
#
# [*environment_file_path*]
#   (required) File path of the ovn-controller environment file
#
# [*opts_envvar_name*]
#   (required) Name of the environment variable to customize options to launch
#   the ovn-controller service.
#
# [*ovn_remote*]
#   (Required) URL of the remote ovn southbound db.
#   Example: 'tcp:127.0.0.1:6642'
#
# [*ovn_encap_ip*]
#   (Required) IP address of the hypervisor(in which this module is installed)
#   to which the other controllers would use to create a tunnel to this
#   controller
#
# [*package_ensure*]
#   (Optional) State of the openvswitch package
#   Defaults to 'present'.
#
# [*ovn_encap_type*]
#   (Optional) The encapsulation type to be used
#   Defaults to 'geneve'
#
# [*ovn_encap_tos*]
#   (Optional) The value to be applied to OVN tunnel interface's option:tos.
#   Defaults to undef
#
# [*ovn_bridge_mappings*]
#   (optional) List of <ovn-network-name>:<bridge-name>
#   Defaults to empty list
#
# [*bridge_interface_mappings*]
#   (optional) List of <bridge-name>:<interface-name> when doing bridge mapping
#   Defaults to empty list
#
# [*hostname*]
#   (optional) The hostname to use with the external id
#   Defaults to $facts['networking']['fqdn']
#
# [*ovn_bridge*]
#   (optional) Name of the integration bridge.
#   Defaults to 'br-int'
#
# [*mac_table_size*]
#  Set the mac table size for the provider bridges if defined in ovn_bridge_mappings
#  Defaults to undef
#
# [*datapath_type*]
#   (optional) Datapath type for ovs bridges
#   Defaults to undef
#
# [*enable_dpdk*]
#   (optional) Enable or not DPDK with OVS
#   Defaults to false.
#
# [*ovn_cms_options*]
#   (optional) A list of options that will be consumed by the CMS Plugin and
#   which specific to this particular chassis.
#   Defaults to undef
#
# [*ovn_remote_probe_interval*]
#  (optional) Set probe interval, based on user configuration, value is in ms
#  Defaults to 60000
#
# [*ovn_openflow_probe_interval*]
#  (optional) The inactivity probe interval of the OpenFlow
#  connection to the OpenvSwitch integration bridge, in
#  seconds. If the value is zero, it disables the connection keepalive feature.
#  If the value is nonzero, then it will be forced to a value of at least 5s.
#  Defaults to 60
#
# [*ovn_transport_zones*]
#  (optional) List of the transport zones to which the chassis belongs to.
#  Defaults to empty list
#
# [*enable_ovn_match_northd*]
#  (optional) When set to true, enable update of ovn_controller after
#  ovn-northd by blocking new message from the ovn-northd to be
#  accepted by the ovn_controller until they have the same version.
#  This need >= ovn2.13-20.09.0-17.
#  Default to false (keep the original behavior)
#
# [*ovn_chassis_mac_map*]
#  (optional) A list or a hash of key-value pairs that map a chassis specific mac to
#  a physical network name. An example value mapping two chassis macs to
#  two physical network names would be:
#  physnet1:aa:bb:cc:dd:ee:ff,physnet2:a1:b2:c3:d4:e5:f6 or
#  {
#    physnet1 => aa:bb:cc:dd:ee:ff,
#    physnet2 => a1:b2:c3:d4:e5:f6
#  }
#  These are the macs that ovn-controller will replace a router port
#  mac with, if packet is going from a distributed router port on
#  vlan type logical switch.
#  Defaults to empty list
#
# [*ovn_monitor_all*]
#  (optional) A boolean value that tells if ovn-controller should monitor all
#  records of tables in ovs-database. If set to false, it will conditionally
#  monitor the records that is needed in the current chassis.
#  Default to false (keep the original behavior)
#
# [*manage_ovs_bridge*]
#  (optional) Create ovs bridges according to ovn_bridge_mappings.
#  Defaults to true
#
# [*ovn_ofctrl_wait_before_clear*]
#  (optional) Time (ms) to wait at startup before clearing openflow rules and
#  install new ones.
#  Defaults to 8000
#
# [*ovn_controller_ssl_key*]
#   OVN Controller SSL private key file
#   Defaults to undef
#
# [*ovn_controller_ssl_cert*]
#   OVN Controller SSL certificate file
#   Defaults to undef
#
# [*ovn_controller_ssl_ca_cert*]
#   OVN Controller SSL CA certificate file
#   Defaults to undef
#
# [*ovn_controller_extra_opts*]
#   Additional command line options for ovn-controller service
#   Defaults to []
#
class ovn::controller(
  String[1] $service_name,
  String[1] $package_name,
  Stdlib::Absolutepath $environment_file_path,
  String[1] $opts_envvar_name,
  String $ovn_remote,
  String $ovn_encap_ip,
  String $package_ensure                                            = 'present',
  Variant[String[1], Array[String[1]]] $ovn_encap_type              = 'geneve',
  Optional[Variant[String, Integer]] $ovn_encap_tos                 = undef,
  Ovn::BridgeMappings $ovn_bridge_mappings                          = [],
  Array[String[1]] $bridge_interface_mappings                       = [],
  String[1] $hostname                                               = $facts['networking']['fqdn'],
  String[1] $ovn_bridge                                             = 'br-int',
  Optional[Integer[0]] $mac_table_size                              = undef,
  Optional[String[1]] $datapath_type                                = undef,
  Boolean $enable_dpdk                                              = false,
  Optional[Variant[String[1], Array[String[1]]]] $ovn_cms_options   = undef,
  Integer[0] $ovn_remote_probe_interval                             = 60000,
  Integer[0] $ovn_openflow_probe_interval                           = 60,
  Array[String[1]] $ovn_transport_zones                                = [],
  Boolean $enable_ovn_match_northd                                  = false,
  Variant[Array[String], Hash[String, String]] $ovn_chassis_mac_map = [],
  Boolean $ovn_monitor_all                                          = false,
  Boolean $manage_ovs_bridge                                        = true,
  Integer[0] $ovn_ofctrl_wait_before_clear                          = 8000,
  Optional[Stdlib::Absolutepath] $ovn_controller_ssl_key            = undef,
  Optional[Stdlib::Absolutepath] $ovn_controller_ssl_cert           = undef,
  Optional[Stdlib::Absolutepath] $ovn_controller_ssl_ca_cert        = undef,
  Array[String[1]] $ovn_controller_extra_opts                       = [],
) {

  if $enable_dpdk and ! $datapath_type {
    fail('Datapath type must be set when DPDK is enabled')
  }

  if $enable_dpdk {
    require vswitch::dpdk
  } else {
    require vswitch::ovs
  }

  include stdlib

  service { 'controller':
    ensure    => true,
    name      => $service_name,
    enable    => true,
    subscribe => Vs_config['external_ids:ovn-remote'],
    tag       => 'ovn',
  }

  package { 'ovn-controller':
    ensure => $package_ensure,
    notify => Service['controller'],
    name   => $package_name,
    tag    => 'ovn',
  }

  if $ovn_controller_ssl_key and $ovn_controller_ssl_cert and $ovn_controller_ssl_ca_cert {
    $ovn_controller_ssl_opts = [
      "--ovn-controller-ssl-key=${ovn_controller_ssl_key}",
      "--ovn-controller-ssl-cert=${ovn_controller_ssl_cert}",
      "--ovn-controller-ssl-ca-cert=${ovn_controller_ssl_ca_cert}"
    ]
  } elsif ! ($ovn_controller_ssl_key or $ovn_controller_ssl_cert or $ovn_controller_ssl_ca_cert) {
    $ovn_controller_ssl_opts = []
  } else {
    fail('The ovn_controller_ssl_key, cert and ca_cert are required to use SSL.')
  }

  $ovn_controller_opts = join($ovn_controller_ssl_opts + $ovn_controller_extra_opts, ' ')

  augeas { 'config-ovn-controller':
    context => "/files${environment_file_path}",
    changes => "set ${opts_envvar_name} '\"${ovn_controller_opts}\"'",
    require => Package['ovn-controller'],
    notify  => Service['controller'],
  }

  $config_items = {
    'external_ids:ovn-remote'                   => { 'value' => $ovn_remote },
    'external_ids:ovn-encap-type'               => { 'value' => join(any2array($ovn_encap_type), ',') },
    'external_ids:ovn-encap-ip'                 => { 'value' => $ovn_encap_ip },
    'external_ids:hostname'                     => { 'value' => $hostname },
    'external_ids:ovn-bridge'                   => { 'value' => $ovn_bridge },
    'external_ids:ovn-remote-probe-interval'    => { 'value' => $ovn_remote_probe_interval },
    'external_ids:ovn-openflow-probe-interval'  => { 'value' => $ovn_openflow_probe_interval },
    'external_ids:ovn-monitor-all'              => { 'value' => $ovn_monitor_all },
    'external_ids:ovn-ofctrl-wait-before-clear' => { 'value' => $ovn_ofctrl_wait_before_clear },
  }

  if $ovn_cms_options {
    $cms_options = {
      'external_ids:ovn-cms-options' => { 'value' => join(any2array($ovn_cms_options), ',') }
    }
  } else {
    $cms_options = {
      'external_ids:ovn-cms-options' => { 'ensure' => 'absent' }
    }
  }

  if $ovn_encap_tos {
    $encap_tos = {
      'external_ids:ovn-encap-tos' => { 'value' => $ovn_encap_tos }
    }
  } else {
    $encap_tos = {
      'external_ids:ovn-encap-tos' => { 'ensure' => 'absent' }
    }
  }

  if !empty($ovn_chassis_mac_map) {
    if $ovn_chassis_mac_map =~ Hash {
      $chassis_mac_map = {
        'external_ids:ovn-chassis-mac-mappings' => { 'value' => join(join_keys_to_values($ovn_chassis_mac_map, ':'), ',') }
      }
    } else {
      $chassis_mac_map = {
        'external_ids:ovn-chassis-mac-mappings' => { 'value' => join(any2array($ovn_chassis_mac_map), ',') }
      }
    }
  } else {
    $chassis_mac_map = {
      'external_ids:ovn-chassis-mac-mappings' => { 'ensure' => 'absent' }
    }
  }

  if !empty($ovn_bridge_mappings) {

    $ovn_bridge_mappings_real = $ovn_bridge_mappings ? {
      Hash    => join_keys_to_values($ovn_bridge_mappings, ':'),
      String  => $ovn_bridge_mappings.split(',').strip(),
      default => $ovn_bridge_mappings,
    }

    $bridge_items = {
      'external_ids:ovn-bridge-mappings' => { 'value' => join(any2array($ovn_bridge_mappings_real), ',') }
    }

    if $manage_ovs_bridge {
      ovn::controller::bridge { $ovn_bridge_mappings_real:
        mac_table_size => $mac_table_size,
        before         => Service['controller'],
        require        => Service['openvswitch']
      }
      ovn::controller::port { $bridge_interface_mappings:
        before  => Service['controller'],
        require => Service['openvswitch']
      }
    }
  } else {
    $bridge_items = {
      'external_ids:ovn-bridge-mappings' => { 'ensure' => 'absent' }
    }
  }

  if !empty($ovn_transport_zones) {
    $tz_items = {
      'external_ids:ovn-transport-zones' => { 'value' => join(any2array($ovn_transport_zones), ',') }
    }
  } else {
    $tz_items = {
      'external_ids:ovn-transport-zones' => { 'ensure' => 'absent' }
    }
  }

  if $datapath_type {
    $datapath_config = {
      'external_ids:ovn-bridge-datapath-type' => { 'value' => $datapath_type }
    }
  } else {
    $datapath_config = {
      'external_ids:ovn-bridge-datapath-type' => { 'ensure' => 'absent' }
    }
  }

  $ovn_match_northd = {
    'external_ids:ovn-match-northd-version' => { 'value' => $enable_ovn_match_northd }
  }
  create_resources(
    'vs_config',
    merge($config_items, $cms_options, $encap_tos, $chassis_mac_map, $bridge_items, $tz_items, $datapath_config, $ovn_match_northd)
  )

  Vs_config<||> -> Service['controller']
}