Fix bind IP config for REST
[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   # Configuration of ODL NB REST port to listen on
23   augeas {'ODL REST Port':
24     incl    => '/opt/opendaylight/etc/jetty.xml',
25     context => '/files/opt/opendaylight/etc/jetty.xml/Configure',
26     lens    => 'Xml.lns',
27     changes => [
28       "set Call[2]/Arg/New/Set[#attribute[name='port']]/Property/#attribute/default ${opendaylight::odl_rest_port}"]
29   }
30
31   if $opendaylight::odl_bind_ip != '0.0.0.0' {
32     # Configuration of ODL NB REST IP to listen on
33     augeas { 'ODL REST IP':
34       incl    => '/opt/opendaylight/etc/jetty.xml',
35       context => '/files/opt/opendaylight/etc/jetty.xml/Configure',
36       lens    => 'Xml.lns',
37       changes => [
38         "set Call[1]/Arg/New/Set[#attribute[name='host']]/Property/#attribute/default ${opendaylight::odl_bind_ip}",
39         "set Call[2]/Arg/New/Set[#attribute[name='host']]/Property/#attribute/default ${opendaylight::odl_bind_ip}"]
40     }
41
42     file { 'org.ops4j.pax.web.cfg':
43       ensure => file,
44       path   => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
45       # Set user:group owners
46       owner  => 'odl',
47       group  => 'odl',
48     }
49     -> file_line { 'org.ops4j.pax.web.cfg':
50       ensure => present,
51       path   => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
52       line   => "org.ops4j.pax.web.listening.addresses = ${opendaylight::odl_bind_ip}"
53     }
54   }
55
56   # Set any custom log levels
57   $opendaylight::log_levels.each |$log_name, $logging_level| {
58     file_line {"logger-${log_name}":
59       ensure => present,
60       path   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
61       line   => "log4j.logger.${log_name}=${logging_level}"
62     }
63   }
64
65   # Set maximum ODL log file size
66   file_line { 'logmaxsize':
67     ensure => present,
68     path   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
69     line   => "log4j.appender.out.maxFileSize=${::opendaylight::log_max_size}",
70     match  => '^log4j.appender.out.maxFileSize.*$'
71   }
72
73   # Set maximum number of ODL log file rollovers to preserve
74   file_line { 'logmaxrollover':
75     ensure => present,
76     path   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
77     line   => "log4j.appender.out.maxBackupIndex=${::opendaylight::log_max_rollover}",
78     match  => '^log4j.appender.out.maxBackupIndex.*$'
79   }
80
81   # Configure ODL HA if enabled
82   $ha_node_count = count($::opendaylight::ha_node_ips)
83   if $::opendaylight::enable_ha {
84     if $ha_node_count >= 2 {
85       # Configure ODL OSVDB Clustering
86       $cluster_config_dir = '/opt/opendaylight/configuration/initial'
87
88       file { $cluster_config_dir:
89         ensure => directory,
90         mode   => '0755',
91         owner  => 'odl',
92         group  => 'odl',
93       }
94
95       file {'akka.conf':
96         ensure  => file,
97         path    => "${cluster_config_dir}/akka.conf",
98         owner   => 'odl',
99         group   => 'odl',
100         content => template('opendaylight/akka.conf.erb'),
101         require => File[$cluster_config_dir]
102       }
103
104       file {'modules.conf':
105         ensure  => file,
106         path    => "${cluster_config_dir}/modules.conf",
107         owner   => 'odl',
108         group   => 'odl',
109         content => template('opendaylight/modules.conf.erb'),
110         require => File[$cluster_config_dir]
111       }
112
113       file {'module-shards.conf':
114         ensure  => file,
115         path    => "${cluster_config_dir}/module-shards.conf",
116         owner   => 'odl',
117         group   => 'odl',
118         content => template('opendaylight/module-shards.conf.erb'),
119         require => File[$cluster_config_dir]
120       }
121
122     } else {
123       fail("Number of HA nodes less than 2: ${ha_node_count} and HA Enabled")
124     }
125   }
126
127   if ('odl-netvirt-openstack' in $opendaylight::features or 'odl-netvirt-sfc' in $opendaylight::features) {
128     # Configure ACL security group
129     # Requires at least CentOS 7.3 for RHEL/CentOS systems
130     if $opendaylight::security_group_mode == 'stateful' {
131       if defined('$opendaylight::stateful_unsupported') and $opendaylight::stateful_unsupported {
132           warning("Stateful is unsupported in ${::operatingsystemrelease} setting to 'learn'")
133           $sg_mode = 'learn'
134       } else {
135         $sg_mode = 'stateful'
136       }
137     } else {
138       $sg_mode = $opendaylight::security_group_mode
139     }
140
141     $odl_datastore = [
142       '/opt/opendaylight/etc/opendaylight',
143       '/opt/opendaylight/etc/opendaylight/datastore',
144       '/opt/opendaylight/etc/opendaylight/datastore/initial',
145       '/opt/opendaylight/etc/opendaylight/datastore/initial/config',
146     ]
147
148     file { $odl_datastore:
149       ensure => directory,
150       mode   => '0755',
151       owner  => 'odl',
152       group  => 'odl',
153     }
154     -> file { 'netvirt-aclservice-config.xml':
155       ensure  => file,
156       path    => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-aclservice-config.xml',
157       owner   => 'odl',
158       group   => 'odl',
159       content => template('opendaylight/netvirt-aclservice-config.xml.erb'),
160     }
161
162     # Configure SNAT
163     file { 'netvirt-natservice-config.xml':
164       ensure  => file,
165       path    => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-natservice-config.xml',
166       owner   => 'odl',
167       group   => 'odl',
168       content => template('opendaylight/netvirt-natservice-config.xml.erb'),
169       require => File['/opt/opendaylight/etc/opendaylight/datastore/initial/config'],
170     }
171   }
172
173   # SFC Config
174   if ('odl-netvirt-sfc' in $opendaylight::features) {
175     file { 'netvirt-elanmanager-config.xml':
176       ensure  => file,
177       path    => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-elanmanager-config.xml',
178       owner   => 'odl',
179       group   => 'odl',
180       source  => 'puppet:///modules/opendaylight/netvirt-elanmanager-config.xml',
181       require => File['/opt/opendaylight/etc/opendaylight/datastore/initial/config'],
182     }
183
184     file { 'genius-itm-config.xml':
185       ensure  => file,
186       path    => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/genius-itm-config.xml',
187       owner   => 'odl',
188       group   => 'odl',
189       source  => 'puppet:///modules/opendaylight/genius-itm-config.xml',
190       require => File['/opt/opendaylight/etc/opendaylight/datastore/initial/config'],
191     }
192   }
193
194   #configure VPP routing node
195   if ! empty($::opendaylight::vpp_routing_node) {
196     file { 'org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.startup.cfg':
197       ensure => file,
198       path   => '/opt/opendaylight/etc/org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.startup.cfg',
199       owner  => 'odl',
200       group  => 'odl',
201     }
202     file_line { 'routing-node':
203       path  => '/opt/opendaylight/etc/org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.startup.cfg',
204       line  => "routing-node=${::opendaylight::vpp_routing_node}",
205       match => '^routing-node=.*$',
206     }
207   }
208
209   # Configure username/password
210   odl_user { $::opendaylight::username:
211     password => $::opendaylight::password,
212     before   => Service['opendaylight'],
213   }
214 }