INTPAK-117 Fixes configuring Java Opts
[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   => "JAVA_OPTS=${opendaylight::java_opts}",
27     match  => '^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 {'aaa-cert-config.xml':
96       ensure  => file,
97       path    => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/aaa-cert-config.xml',
98       owner   => 'odl',
99       group   => 'odl',
100       content => template('opendaylight/aaa-cert-config.xml.erb'),
101     }
102
103     file_line {'set pax TLS keystore location':
104       ensure  => present,
105       path    => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
106       line    => 'org.ops4j.pax.web.ssl.keystore = configuration/ssl/ctl.jks',
107       match   => '^#?org.ops4j.pax.web.ssl.keystore.*$',
108       require => File['org.ops4j.pax.web.cfg']
109     }
110     file_line {'set pax TLS keystore integrity password':
111       ensure  => present,
112       path    => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
113       line    => "org.ops4j.pax.web.ssl.password = ${opendaylight::tls_keystore_password}",
114       match   => '^#?org.ops4j.pax.web.ssl.password.*$',
115       require => File['org.ops4j.pax.web.cfg']
116     }
117
118     file_line {'set pax TLS keystore password':
119       ensure  => present,
120       path    => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
121       line    => "org.ops4j.pax.web.ssl.keypassword = ${opendaylight::tls_keystore_password}",
122       match   => '^#?org.ops4j.pax.web.ssl.keypassword.*$',
123       require => File['org.ops4j.pax.web.cfg']
124     }
125
126     # Enable TLS with OVSDB
127     file { 'org.opendaylight.ovsdb.library.cfg':
128       ensure => file,
129       path   => '/opt/opendaylight/etc/org.opendaylight.ovsdb.library.cfg',
130       owner  => 'odl',
131       group  => 'odl',
132       source => 'puppet:///modules/opendaylight/org.opendaylight.ovsdb.library.cfg',
133     }
134
135     # Configure OpenFlow plugin to use TLS
136     $transport_protocol = 'TLS'
137   } else {
138     $transport_protocol = 'TCP'
139     augeas { 'ODL REST Port':
140       incl    => '/opt/opendaylight/etc/jetty.xml',
141       context => '/files/opt/opendaylight/etc/jetty.xml/Configure',
142       lens    => 'Xml.lns',
143       changes => [
144         "set Call[1]/Arg/New/Set[#attribute[name='port']]/Property/#attribute/default
145           ${opendaylight::odl_rest_port}"]
146     }
147   }
148   # Configure OpenFlow plugin to use TCP/TLS
149   file { 'default-openflow-connection-config.xml':
150     ensure  => file,
151     path    => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/default-openflow-connection-config.xml',
152     # Set user:group owners
153     owner   => 'odl',
154     group   => 'odl',
155     content => template('opendaylight/default-openflow-connection-config.xml.erb'),
156   }
157   $initial_config_dir = '/opt/opendaylight/configuration/initial'
158
159   file { $initial_config_dir:
160         ensure => directory,
161         mode   => '0755',
162         owner  => 'odl',
163         group  => 'odl',
164   }
165
166   if $opendaylight::odl_bind_ip != '0.0.0.0' {
167     # Configuration of ODL NB REST IP to listen on
168     augeas { 'ODL REST IP':
169       incl    => '/opt/opendaylight/etc/jetty.xml',
170       context => '/files/opt/opendaylight/etc/jetty.xml/Configure',
171       lens    => 'Xml.lns',
172       changes => [
173         "set Call[1]/Arg/New/Set[#attribute[name='host']]/Property/#attribute/default ${opendaylight::odl_bind_ip}"
174       ]
175     }
176
177     file_line { 'set pax bind IP':
178       ensure  => present,
179       path    => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
180       line    => "org.ops4j.pax.web.listening.addresses = ${opendaylight::odl_bind_ip}",
181       require => File['org.ops4j.pax.web.cfg']
182     }
183
184     # Configure websocket address
185     file { '/opt/opendaylight/etc/org.opendaylight.restconf.cfg':
186       ensure => file,
187       path   => '/opt/opendaylight/etc/org.opendaylight.restconf.cfg',
188       owner  => 'odl',
189       group  => 'odl',
190     }
191     -> file_line { 'websocket-address':
192       ensure => present,
193       path   => '/opt/opendaylight/etc/org.opendaylight.restconf.cfg',
194       line   => "websocket-address=${::opendaylight::odl_bind_ip}",
195       match  => '^websocket-address=.*$',
196     }
197   }
198
199   file_line { 'set pax bind port':
200     ensure  => present,
201     path    => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
202     line    => "org.osgi.service.http.port = ${opendaylight::odl_rest_port}",
203     require => File['org.ops4j.pax.web.cfg']
204   }
205
206   # Set any custom log levels
207   $opendaylight::log_levels.each |$log_name, $logging_level| {
208     $underscored_version = regsubst($log_name, '\.', '_', 'G')
209     file_line {"logger-${log_name}-level":
210       ensure => present,
211       path   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
212       line   => "log4j2.logger.${underscored_version}.level = ${logging_level}",
213       match  => "log4j2.logger.${underscored_version}.level = .*$"
214     }
215     file_line {"logger-${log_name}-name":
216       ensure => present,
217       path   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
218       line   => "log4j2.logger.${underscored_version}.name = ${log_name}",
219       match  => "log4j2.logger.${underscored_version}.name = .*$"
220     }
221   }
222
223   # set logging mechanism
224   if $opendaylight::log_mechanism == 'console' {
225     file_line { 'consoleappender':
226       ensure => present,
227       path   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
228       line   => 'karaf.log.console=INFO',
229       after  => 'log4j2.rootLogger.appenderRef.Console.filter.threshold.type = ThresholdFilter',
230       match  => '^karaf.log.console.*$'
231     }
232   } else {
233     # Set maximum ODL log file size
234     file_line { 'logmaxsize':
235       ensure => present,
236       path   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
237       line   => "log4j2.appender.rolling.policies.size.size = ${::opendaylight::log_max_size}",
238       match  => '^log4j2.appender.rolling.policies.size.size.*$'
239     }
240
241     file_line { 'rolloverstrategy':
242       ensure => present,
243       path   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
244       line   => 'log4j2.appender.rolling.strategy.type = DefaultRolloverStrategy'
245     }
246
247     # Set maximum number of ODL log file rollovers to preserve
248     -> file_line { 'logmaxrollover':
249       ensure => present,
250       path   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
251       line   => "log4j2.appender.rolling.strategy.max = ${::opendaylight::log_max_rollover}",
252       match  => '^log4j2.appender.rolling.strategy.max.*$'
253     }
254   }
255
256   # Configure ODL HA if enabled
257   if $::opendaylight::enable_ha {
258     # Configure ODL OSVDB Clustering
259
260     file {'akka.conf':
261       ensure  => file,
262       path    => "${initial_config_dir}/akka.conf",
263       owner   => 'odl',
264       group   => 'odl',
265       content => template('opendaylight/akka.conf.erb'),
266       require => File[$initial_config_dir]
267     }
268
269     file {'modules.conf':
270       ensure  => file,
271       path    => "${initial_config_dir}/modules.conf",
272       owner   => 'odl',
273       group   => 'odl',
274       content => template('opendaylight/modules.conf.erb'),
275       require => File[$initial_config_dir]
276     }
277
278     file {'module-shards.conf':
279       ensure  => file,
280       path    => "${initial_config_dir}/module-shards.conf",
281       owner   => 'odl',
282       group   => 'odl',
283       content => template('opendaylight/module-shards.conf.erb'),
284       require => File[$initial_config_dir]
285     }
286   }
287
288   $odl_dirs = [
289     '/opt/opendaylight/etc/opendaylight',
290     '/opt/opendaylight/etc/opendaylight/karaf',
291     '/opt/opendaylight/etc/opendaylight/datastore',
292     '/opt/opendaylight/etc/opendaylight/datastore/initial',
293     '/opt/opendaylight/etc/opendaylight/datastore/initial/config',
294     '/opt/opendaylight/configuration/ssl'
295   ]
296
297   file { $odl_dirs:
298     ensure => directory,
299     mode   => '0755',
300     owner  => 'odl',
301     group  => 'odl',
302   }
303
304   if ('odl-netvirt-openstack' in $opendaylight::features or 'odl-netvirt-sfc' in $opendaylight::features) {
305     # Configure SNAT
306
307     file { 'netvirt-natservice-config.xml':
308       ensure  => file,
309       path    => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-natservice-config.xml',
310       owner   => 'odl',
311       group   => 'odl',
312       content => template('opendaylight/netvirt-natservice-config.xml.erb'),
313       require => File['/opt/opendaylight/etc/opendaylight/datastore/initial/config'],
314     }
315   }
316
317   # SFC Config
318   if ('odl-netvirt-sfc' in $opendaylight::features) {
319     file { 'netvirt-elanmanager-config.xml':
320       ensure  => file,
321       path    => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-elanmanager-config.xml',
322       owner   => 'odl',
323       group   => 'odl',
324       source  => 'puppet:///modules/opendaylight/netvirt-elanmanager-config.xml',
325       require => File['/opt/opendaylight/etc/opendaylight/datastore/initial/config'],
326     }
327
328     file { 'genius-itm-config.xml':
329       ensure  => file,
330       path    => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/genius-itm-config.xml',
331       owner   => 'odl',
332       group   => 'odl',
333       source  => 'puppet:///modules/opendaylight/genius-itm-config.xml',
334       require => File['/opt/opendaylight/etc/opendaylight/datastore/initial/config'],
335     }
336   }
337
338   #configure VPP routing node
339   if ! empty($::opendaylight::vpp_routing_node) {
340     file { 'org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.startup.cfg':
341       ensure => file,
342       path   => '/opt/opendaylight/etc/org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.startup.cfg',
343       owner  => 'odl',
344       group  => 'odl',
345     }
346     file_line { 'routing-node':
347       path  => '/opt/opendaylight/etc/org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.startup.cfg',
348       line  => "routing-node=${::opendaylight::vpp_routing_node}",
349       match => '^routing-node=.*$',
350     }
351   }
352
353   # Configure username/password
354   odl_user { $::opendaylight::username:
355     password => $::opendaylight::password,
356     before   => Service['opendaylight'],
357   }
358 }