9560ff538153481672c1567911478516210c19f5
[integration/packaging/puppet-opendaylight.git] / manifests / config.pp
1 # == Class opendaylight::config
2 #
3 # This class handles ODL config changes.
4 # It's called from the opendaylight class.
5 #
6 class opendaylight::config {
7   # Configuration of Karaf features to install
8   file { 'org.apache.karaf.features.cfg':
9     ensure => file,
10     path   => '/opt/opendaylight/etc/org.apache.karaf.features.cfg',
11     # Set user:group owners
12     owner  => 'odl',
13     group  => 'odl',
14   }
15   $features_csv = join($opendaylight::features, ',')
16   file_line { 'featuresBoot':
17     path  => '/opt/opendaylight/etc/org.apache.karaf.features.cfg',
18     line  => "featuresBoot=${features_csv}",
19     match => '^featuresBoot=.*$',
20   }
21
22   # Modify karaf to include Java options
23   file_line {'Karaf Java Options':
24     ensure => present,
25     path   => '/opt/opendaylight/bin/karaf',
26     line   => "EXTRA_JAVA_OPTS=${opendaylight::java_opts}",
27     match  => '^EXTRA_JAVA_OPTS=.*$',
28     after  => '^PROGNAME=.*$'
29   }
30
31   file { 'org.ops4j.pax.web.cfg':
32     ensure => file,
33     path   => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
34     # Set user:group owners
35     owner  => 'odl',
36     group  => 'odl',
37   }
38
39   $ha_node_count = count($::opendaylight::ha_node_ips)
40   if $::opendaylight::enable_ha and $ha_node_count < 2 {
41     fail("Number of HA nodes less than 2: ${ha_node_count} and HA Enabled")
42   }
43
44   # Configuration of ODL NB REST port to listen on
45   if $opendaylight::enable_tls {
46
47     if $::opendaylight::tls_keystore_password == undef {
48       fail('Enabling TLS requires setting a TLS password for the ODL keystore')
49     }
50
51     if $::opendaylight::tls_key_file or $::opendaylight::tls_cert_file {
52       if $::opendaylight::tls_key_file and $::opendaylight::tls_cert_file {
53         odl_keystore { 'controller':
54           password  => $::opendaylight::tls_keystore_password,
55           cert_file => $::opendaylight::tls_cert_file,
56           key_file  => $::opendaylight::tls_key_file,
57           ca_file   => $::opendaylight::tls_ca_cert_file,
58           require   => File['/opt/opendaylight/configuration/ssl']
59         }
60       } else {
61         fail('Must specify both TLS key file path AND certificate file path')
62       }
63     }
64
65     augeas {'Remove HTTP ODL REST Port':
66       incl    => '/opt/opendaylight/etc/jetty.xml',
67       context => '/files/opt/opendaylight/etc/jetty.xml/Configure',
68       lens    => 'Xml.lns',
69       changes => ["rm Call[1]/Arg/New/Set[#attribute[name='port']]"]
70     }
71
72     augeas {'ODL SSL REST Port':
73       incl    => '/opt/opendaylight/etc/jetty.xml',
74       context => '/files/opt/opendaylight/etc/jetty.xml/Configure',
75       lens    => 'Xml.lns',
76       changes => ["set New[1]/Set[#attribute[name='securePort']]/Property/#attribute/default ${opendaylight::odl_rest_port}"]
77     }
78
79     file_line { 'set pax TLS port':
80       ensure  => present,
81       path    => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
82       line    => "org.osgi.service.http.port.secure = ${opendaylight::odl_rest_port}",
83       match   => '^#?org.osgi.service.http.port.secure.*$',
84       require => File['org.ops4j.pax.web.cfg']
85     }
86
87     file_line { 'enable pax TLS':
88       ensure  => present,
89       path    => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
90       line    => 'org.osgi.service.http.secure.enabled = true',
91       match   => '^#?org.osgi.service.http.secure.enabled.*$',
92       require => File['org.ops4j.pax.web.cfg']
93     }
94
95     file_line { 'disable pax HTTP':
96       ensure  => present,
97       path    => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
98       line    => 'org.osgi.service.http.enabled = false',
99       match   => '^#?org.osgi.service.http.enabled.*$',
100       require => File['org.ops4j.pax.web.cfg']
101     }
102
103     file {'aaa-cert-config.xml':
104       ensure  => file,
105       path    => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/aaa-cert-config.xml',
106       owner   => 'odl',
107       group   => 'odl',
108       content => template('opendaylight/aaa-cert-config.xml.erb'),
109     }
110
111     file_line {'set pax TLS keystore location':
112       ensure  => present,
113       path    => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
114       line    => 'org.ops4j.pax.web.ssl.keystore = configuration/ssl/ctl.jks',
115       match   => '^#?org.ops4j.pax.web.ssl.keystore.*$',
116       require => File['org.ops4j.pax.web.cfg']
117     }
118     file_line {'set pax TLS keystore integrity password':
119       ensure  => present,
120       path    => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
121       line    => "org.ops4j.pax.web.ssl.password = ${opendaylight::tls_keystore_password}",
122       match   => '^#?org.ops4j.pax.web.ssl.password.*$',
123       require => File['org.ops4j.pax.web.cfg']
124     }
125
126     file_line {'set pax TLS keystore password':
127       ensure  => present,
128       path    => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
129       line    => "org.ops4j.pax.web.ssl.keypassword = ${opendaylight::tls_keystore_password}",
130       match   => '^#?org.ops4j.pax.web.ssl.keypassword.*$',
131       require => File['org.ops4j.pax.web.cfg']
132     }
133
134     # Enable TLS with OVSDB
135     file { 'org.opendaylight.ovsdb.library.cfg':
136       ensure => file,
137       path   => '/opt/opendaylight/etc/org.opendaylight.ovsdb.library.cfg',
138       owner  => 'odl',
139       group  => 'odl',
140       source => 'puppet:///modules/opendaylight/org.opendaylight.ovsdb.library.cfg',
141     }
142
143     # Configure OpenFlow plugin to use TLS
144     $transport_protocol = 'TLS'
145   } else {
146     $transport_protocol = 'TCP'
147     augeas { 'ODL REST Port':
148       incl    => '/opt/opendaylight/etc/jetty.xml',
149       context => '/files/opt/opendaylight/etc/jetty.xml/Configure',
150       lens    => 'Xml.lns',
151       changes => [
152         "set Call[1]/Arg/New/Set[#attribute[name='port']]/Property/#attribute/default
153           ${opendaylight::odl_rest_port}"]
154     }
155
156     file_line { 'set pax bind port':
157       ensure  => present,
158       path    => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
159       line    => "org.osgi.service.http.port = ${opendaylight::odl_rest_port}",
160       match   => '^#?org.osgi.service.http.port\s.*$',
161       require => File['org.ops4j.pax.web.cfg']
162     }
163   }
164   # Configure OpenFlow plugin to use TCP/TLS
165   file { 'default-openflow-connection-config.xml':
166     ensure  => file,
167     path    => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/default-openflow-connection-config.xml',
168     # Set user:group owners
169     owner   => 'odl',
170     group   => 'odl',
171     content => template('opendaylight/default-openflow-connection-config.xml.erb'),
172   }
173   $initial_config_dir = '/opt/opendaylight/configuration/initial'
174
175   file { $initial_config_dir:
176         ensure => directory,
177         mode   => '0755',
178         owner  => 'odl',
179         group  => 'odl',
180   }
181
182   if $opendaylight::odl_bind_ip != '0.0.0.0' {
183     # Configuration of ODL NB REST IP to listen on
184     augeas { 'ODL REST IP':
185       incl    => '/opt/opendaylight/etc/jetty.xml',
186       context => '/files/opt/opendaylight/etc/jetty.xml/Configure',
187       lens    => 'Xml.lns',
188       changes => [
189         "set Call[1]/Arg/New/Set[#attribute[name='host']]/Property/#attribute/default ${opendaylight::odl_bind_ip}"
190       ]
191     }
192
193     file_line { 'set pax bind IP':
194       ensure  => present,
195       path    => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
196       line    => "org.ops4j.pax.web.listening.addresses = ${opendaylight::odl_bind_ip}",
197       require => File['org.ops4j.pax.web.cfg']
198     }
199
200     # Configure websocket address
201     file { '/opt/opendaylight/etc/org.opendaylight.restconf.cfg':
202       ensure => file,
203       path   => '/opt/opendaylight/etc/org.opendaylight.restconf.cfg',
204       owner  => 'odl',
205       group  => 'odl',
206     }
207     -> file_line { 'websocket-address':
208       ensure => present,
209       path   => '/opt/opendaylight/etc/org.opendaylight.restconf.cfg',
210       line   => "websocket-address=${::opendaylight::odl_bind_ip}",
211       match  => '^websocket-address=.*$',
212     }
213   }
214
215   # Set any custom log levels
216   $opendaylight::log_levels.each |$log_name, $logging_level| {
217     $underscored_version = regsubst($log_name, '\.', '_', 'G')
218     file_line {"logger-${log_name}-level":
219       ensure => present,
220       path   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
221       line   => "log4j2.logger.${underscored_version}.level = ${logging_level}",
222       match  => "log4j2.logger.${underscored_version}.level = .*$"
223     }
224     file_line {"logger-${log_name}-name":
225       ensure => present,
226       path   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
227       line   => "log4j2.logger.${underscored_version}.name = ${log_name}",
228       match  => "log4j2.logger.${underscored_version}.name = .*$"
229     }
230   }
231
232   # set logging mechanism
233   if $opendaylight::log_mechanism == 'console' {
234     file_line { 'consoleappender':
235       ensure => present,
236       path   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
237       line   => 'karaf.log.console=INFO',
238       after  => 'log4j2.rootLogger.appenderRef.Console.filter.threshold.type = ThresholdFilter',
239       match  => '^karaf.log.console.*$'
240     }
241   } else {
242     # Set maximum ODL log file size
243     file_line { 'logmaxsize':
244       ensure => present,
245       path   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
246       line   => "log4j2.appender.rolling.policies.size.size = ${::opendaylight::log_max_size}",
247       match  => '^log4j2.appender.rolling.policies.size.size.*$'
248     }
249
250     file_line { 'rolloverstrategy':
251       ensure => present,
252       path   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
253       line   => 'log4j2.appender.rolling.strategy.type = DefaultRolloverStrategy'
254     }
255
256     # Set maximum number of ODL log file rollovers to preserve
257     -> file_line { 'logmaxrollover':
258       ensure => present,
259       path   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
260       line   => "log4j2.appender.rolling.strategy.max = ${::opendaylight::log_max_rollover}",
261       match  => '^log4j2.appender.rolling.strategy.max.*$'
262     }
263   }
264
265   # Configure ODL HA if enabled
266   if $::opendaylight::enable_ha {
267     # Configure ODL OSVDB Clustering
268
269     file {'akka.conf':
270       ensure  => file,
271       path    => "${initial_config_dir}/akka.conf",
272       owner   => 'odl',
273       group   => 'odl',
274       content => template('opendaylight/akka.conf.erb'),
275       require => File[$initial_config_dir]
276     }
277
278     file {'modules.conf':
279       ensure  => file,
280       path    => "${initial_config_dir}/modules.conf",
281       owner   => 'odl',
282       group   => 'odl',
283       content => template('opendaylight/modules.conf.erb'),
284       require => File[$initial_config_dir]
285     }
286
287     file {'module-shards.conf':
288       ensure  => file,
289       path    => "${initial_config_dir}/module-shards.conf",
290       owner   => 'odl',
291       group   => 'odl',
292       content => template('opendaylight/module-shards.conf.erb'),
293       require => File[$initial_config_dir]
294     }
295   }
296
297   $odl_dirs = [
298     '/opt/opendaylight/etc/opendaylight',
299     '/opt/opendaylight/etc/opendaylight/karaf',
300     '/opt/opendaylight/etc/opendaylight/datastore',
301     '/opt/opendaylight/etc/opendaylight/datastore/initial',
302     '/opt/opendaylight/etc/opendaylight/datastore/initial/config',
303     '/opt/opendaylight/configuration/ssl'
304   ]
305
306   file { $odl_dirs:
307     ensure => directory,
308     mode   => '0755',
309     owner  => 'odl',
310     group  => 'odl',
311   }
312
313   if ('odl-netvirt-openstack' in $opendaylight::features or 'odl-netvirt-sfc' in $opendaylight::features) {
314     # Configure SNAT
315
316     file { 'netvirt-natservice-config.xml':
317       ensure  => file,
318       path    => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-natservice-config.xml',
319       owner   => 'odl',
320       group   => 'odl',
321       content => template('opendaylight/netvirt-natservice-config.xml.erb'),
322       require => File['/opt/opendaylight/etc/opendaylight/datastore/initial/config'],
323     }
324   }
325
326   # SFC Config
327   if ('odl-netvirt-sfc' in $opendaylight::features) {
328     file { 'netvirt-elanmanager-config.xml':
329       ensure  => file,
330       path    => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-elanmanager-config.xml',
331       owner   => 'odl',
332       group   => 'odl',
333       source  => 'puppet:///modules/opendaylight/netvirt-elanmanager-config.xml',
334       require => File['/opt/opendaylight/etc/opendaylight/datastore/initial/config'],
335     }
336
337     file { 'genius-itm-config.xml':
338       ensure  => file,
339       path    => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/genius-itm-config.xml',
340       owner   => 'odl',
341       group   => 'odl',
342       source  => 'puppet:///modules/opendaylight/genius-itm-config.xml',
343       require => File['/opt/opendaylight/etc/opendaylight/datastore/initial/config'],
344     }
345   }
346
347   #configure VPP routing node
348   if ! empty($::opendaylight::vpp_routing_node) {
349     file { 'org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.startup.cfg':
350       ensure => file,
351       path   => '/opt/opendaylight/etc/org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.startup.cfg',
352       owner  => 'odl',
353       group  => 'odl',
354     }
355     file_line { 'routing-node':
356       path  => '/opt/opendaylight/etc/org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.startup.cfg',
357       line  => "routing-node=${::opendaylight::vpp_routing_node}",
358       match => '^routing-node=.*$',
359     }
360   }
361
362   # Configure username/password
363   odl_user { $::opendaylight::username:
364     password => $::opendaylight::password,
365     before   => Service['opendaylight'],
366   }
367 }