File: northd.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 (273 lines) | stat: -rw-r--r-- 9,356 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
# ovn northd
# == Class: ovn::northd
#
# installs ovn package starts the ovn-northd service
#
# [*package_name*]
#   (required) Name of ovn-northd package.
#
# [*service_name*]
#   (required) Name of ovn-northd 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.
#
# [*package_ensure*]
#   (Optional) State of the ovn-northd package
#   Defaults to 'present'.
#
# [*dbs_listen_ip*]
#   The IP-Address where OVN DBs should be listening
#   Defaults to '0.0.0.0'
#
# [*dbs_cluster_local_addr*]
#   The IP-Address where OVN Clustered DBs should be listening
#   Defaults to undef
#
# [*dbs_cluster_remote_addr*]
#   The IP-Address where OVN Clustered DBs sync from
#   Defaults to undef
#
# [*ovn_northd_nb_db*]
#   NB DB address(es)
#   Defaults to undef
#
# [*ovn_northd_sb_db*]
#   SB DB address(es)
#   Defaults to undef
#
# [*ovn_northd_ssl_key*]
#   OVN Northd SSL private key file
#   Defaults to undef
#
# [*ovn_northd_ssl_cert*]
#   OVN Northd SSL certificate file
#   Defaults to undef
#
# [*ovn_northd_ssl_ca_cert*]
#   OVN Northd SSL CA certificate file
#   Defaults to undef
#
# [*ovn_nb_db_ssl_key*]
#   OVN NB DB SSL private key file
#   Defaults to undef
#
# [*ovn_nb_db_ssl_cert*]
#   OVN NB DB SSL certificate file
#   Defaults to undef
#
# [*ovn_nb_db_ssl_ca_cert*]
#   OVN NB DB SSL CA certificate file
#   Defaults to undef
#
# [*ovn_sb_db_ssl_key*]
#   OVN SB DB SSL private key file
#   Defaults to undef
#
# [*ovn_sb_db_ssl_cert*]
#   OVN SB DB SSL certificate file
#   Defaults to undef
#
# [*ovn_sb_db_ssl_ca_cert*]
#   OVN SB DB SSL CA certificate file
#   Defaults to undef
#
# [*ovn_northd_extra_opts*]
#   Additional command line options for ovn-northd service
#   Defaults to []
#
class ovn::northd(
  String[1] $package_name,
  String[1] $service_name,
  Stdlib::Absolutepath $environment_file_path,
  String[1] $opts_envvar_name,
  String $package_ensure = 'present',
  String $dbs_listen_ip = '0.0.0.0',
  Optional[String] $dbs_cluster_local_addr = undef,
  Optional[String] $dbs_cluster_remote_addr = undef,
  Optional[Variant[String, Array[String]]] $ovn_northd_nb_db = undef,
  Optional[Variant[String, Array[String]]] $ovn_northd_sb_db = undef,
  Optional[Stdlib::Absolutepath] $ovn_northd_ssl_key = undef,
  Optional[Stdlib::Absolutepath] $ovn_northd_ssl_cert = undef,
  Optional[Stdlib::Absolutepath] $ovn_northd_ssl_ca_cert = undef,
  Optional[Stdlib::Absolutepath] $ovn_nb_db_ssl_key = undef,
  Optional[Stdlib::Absolutepath] $ovn_nb_db_ssl_cert = undef,
  Optional[Stdlib::Absolutepath] $ovn_nb_db_ssl_ca_cert = undef,
  Optional[Stdlib::Absolutepath] $ovn_sb_db_ssl_key = undef,
  Optional[Stdlib::Absolutepath] $ovn_sb_db_ssl_cert = undef,
  Optional[Stdlib::Absolutepath] $ovn_sb_db_ssl_ca_cert = undef,
  Array[String] $ovn_northd_extra_opts = [],
) {
  include vswitch::ovs

  $dbs_listen_ip_real = normalize_ip_for_uri($dbs_listen_ip)

  $ovn_northd_opts_addr = [
    "--db-nb-addr=${dbs_listen_ip_real}",
    "--db-sb-addr=${dbs_listen_ip_real}",
  ]

  # NOTE(tkajinam): --db-(n|s)b-create-insecure-remote enables remote without
  #                 ssl ( ptcp:<port>:<ip> ).
  $ovn_northd_opts_nb_create_insecure_remote = $ovn_nb_db_ssl_key ? {
    undef   => ['--db-nb-create-insecure-remote=yes'],
    default => ['--db-nb-create-insecure-remote=no']
  }
  $ovn_northd_opts_sb_create_insecure_remote = $ovn_sb_db_ssl_key ? {
    undef   => ['--db-sb-create-insecure-remote=yes'],
    default => ['--db-sb-create-insecure-remote=no']
  }

  if $dbs_cluster_local_addr {
    $ovn_northd_opts_nb_cluster_local_proto = $ovn_nb_db_ssl_key ? {
      undef   => [],
      default => ['--db-nb-cluster-local-proto=ssl'],
    }
    $ovn_northd_opts_sb_cluster_local_proto = $ovn_nb_db_ssl_key ? {
      undef   => [],
      default => ['--db-sb-cluster-local-proto=ssl'],
    }
    $ovn_northd_opts_cluster_local_addr = [
      "--db-nb-cluster-local-addr=${dbs_cluster_local_addr}",
      "--db-sb-cluster-local-addr=${dbs_cluster_local_addr}"
    ]
  } else {
    $ovn_northd_opts_nb_cluster_local_proto = []
    $ovn_northd_opts_sb_cluster_local_proto = []
    $ovn_northd_opts_cluster_local_addr = []
  }

  if $dbs_cluster_remote_addr {
    $ovn_northd_opts_nb_cluster_remote_proto = $ovn_nb_db_ssl_key ? {
      undef   => [],
      default => ['--db-nb-cluster-remote-proto=ssl']
    }
    $ovn_northd_opts_sb_cluster_remote_proto = $ovn_sb_db_ssl_key ? {
      undef   => [],
      default => ['--db-sb-cluster-remote-proto=ssl']
    }
    $ovn_northd_opts_cluster_remote_addr = [
      "--db-nb-cluster-remote-addr=${dbs_cluster_remote_addr}",
      "--db-sb-cluster-remote-addr=${dbs_cluster_remote_addr}"
    ]
  } else {
    $ovn_northd_opts_nb_cluster_remote_proto = []
    $ovn_northd_opts_sb_cluster_remote_proto = []
    $ovn_northd_opts_cluster_remote_addr = []
  }

  $ovn_northd_nb_db_opts = $ovn_northd_nb_db ? {
    String        => ["--ovn-northd-nb-db=${ovn_northd_nb_db}"],
    Array[String] => ["--ovn-northd-nb-db=${join($ovn_northd_nb_db, ',')}"],
    default       => [],
  }

  $ovn_northd_sb_db_opts = $ovn_northd_sb_db ? {
    String        => ["--ovn-northd-sb-db=${ovn_northd_sb_db}"],
    Array[String] => ["--ovn-northd-sb-db=${join($ovn_northd_sb_db, ',')}"],
    default       => [],
  }

  if $ovn_northd_ssl_key and $ovn_northd_ssl_cert and $ovn_northd_ssl_ca_cert {
    $ovn_northd_ssl_opts = [
      "--ovn-northd-ssl-key=${ovn_northd_ssl_key}",
      "--ovn-northd-ssl-cert=${ovn_northd_ssl_cert}",
      "--ovn-northd-ssl-ca-cert=${ovn_northd_ssl_ca_cert}"
    ]
  } elsif ! ($ovn_northd_ssl_key or $ovn_northd_ssl_cert or $ovn_northd_ssl_ca_cert) {
    $ovn_northd_ssl_opts = []
  } else {
    fail('The ovn_northd_ssl_key, cert and ca_cert are required to use SSL.')
  }

  if $ovn_nb_db_ssl_key and $ovn_nb_db_ssl_cert and $ovn_nb_db_ssl_ca_cert {
    $ovn_nb_db_ssl_opts = [
      "--ovn-nb-db-ssl-key=${ovn_nb_db_ssl_key}",
      "--ovn-nb-db-ssl-cert=${ovn_nb_db_ssl_cert}",
      "--ovn-nb-db-ssl-ca-cert=${ovn_nb_db_ssl_ca_cert}"
    ]
  } elsif ! ($ovn_nb_db_ssl_key or $ovn_nb_db_ssl_cert or $ovn_nb_db_ssl_ca_cert) {
    $ovn_nb_db_ssl_opts = []
  } else {
    fail('The ovn_nb_db_ssl_key, cert and ca_cert are required to use SSL.')
  }

  if $ovn_sb_db_ssl_key and $ovn_sb_db_ssl_cert and $ovn_sb_db_ssl_ca_cert {
    $ovn_sb_db_ssl_opts = [
      "--ovn-sb-db-ssl-key=${ovn_sb_db_ssl_key}",
      "--ovn-sb-db-ssl-cert=${ovn_sb_db_ssl_cert}",
      "--ovn-sb-db-ssl-ca-cert=${ovn_sb_db_ssl_ca_cert}"
    ]
  } elsif ! ($ovn_sb_db_ssl_key or $ovn_sb_db_ssl_cert or $ovn_sb_db_ssl_ca_cert) {
    $ovn_sb_db_ssl_opts = []
  } else {
    fail('The ovn_sb_db_ssl_key, cert and ca_cert are required to use SSL.')
  }

  $ovn_northd_opts = join($ovn_northd_opts_addr +
                          $ovn_northd_opts_nb_create_insecure_remote +
                          $ovn_northd_opts_sb_create_insecure_remote +
                          $ovn_northd_opts_nb_cluster_local_proto +
                          $ovn_northd_opts_sb_cluster_local_proto +
                          $ovn_northd_opts_cluster_local_addr +
                          $ovn_northd_opts_nb_cluster_remote_proto +
                          $ovn_northd_opts_sb_cluster_remote_proto +
                          $ovn_northd_opts_cluster_remote_addr +
                          $ovn_northd_nb_db_opts +
                          $ovn_northd_sb_db_opts +
                          $ovn_northd_ssl_opts +
                          $ovn_nb_db_ssl_opts +
                          $ovn_sb_db_ssl_opts +
                          $ovn_northd_extra_opts,
                          ' ')

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

  service { 'northd':
    ensure  => true,
    enable  => true,
    name    => $service_name,
    require => Service['openvswitch'],
    tag     => 'ovn',
  }

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

  # NOTE(tkajinam): We have to escapte [ and ] otherwise egrep intereprets
  #                 these wrongly.
  $dbs_listen_ip_reg = regsubst(regsubst($dbs_listen_ip_real, '\]$', '\\]'), '^\[', '\\[')

  if $ovn_nb_db_ssl_key {
    exec { 'ovn-nb-set-connection':
      command => "ovn-nbctl set-connection pssl:6641:${dbs_listen_ip_real}",
      path    => ['/sbin', '/usr/sbin', '/bin', '/usr/bin'],
      unless  => "ovn-nbctl get-connection | egrep -e '^pssl:6641:${dbs_listen_ip_reg}$'",
      tag     => 'ovn-db-set-connections',
      require => Service['northd']
    }
  }
  if $ovn_sb_db_ssl_key {
    exec { 'ovn-sb-set-connection':
      command => "ovn-sbctl set-connection pssl:6642:${dbs_listen_ip_real}",
      path    => ['/sbin', '/usr/sbin', '/bin', '/usr/bin'],
      unless  => "ovn-sbctl get-connection | egrep -e ' pssl:6642:${dbs_listen_ip_reg}$'",
      tag     => 'ovn-db-set-connections',
      require => Service['northd']
    }
  }
}