Puppet: overcloud controller config
[apex-tripleo-heat-templates.git] / puppet / loadbalancer.pp
1 # Copyright 2014 Red Hat, Inc.
2 # All Rights Reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
15
16 class tripleo::loadbalancer (
17   $keystone_admin     = false,
18   $keystone_public    = false,
19   $neutron            = false,
20   $cinder             = false,
21   $glance_api         = false,
22   $glance_registry    = false,
23   $nova_ec2           = false,
24   $nova_osapi         = false,
25   $nova_metadata      = false,
26   $nova_novncproxy    = false,
27   $ceilometer         = false,
28   $swift_proxy_server = false,
29   $heat_api           = false,
30   $heat_cloudwatch    = false,
31   $heat_cfn           = false,
32   $horizon            = false,
33   $mysql              = false,
34   $rabbitmq           = false,
35 ) {
36
37   case $::osfamily {
38     'RedHat': {
39       $keepalived_name_is_process = false
40       $keepalived_vrrp_script     = 'systemctl status haproxy.service'
41     } # RedHat
42     'Debian': {
43       $keepalived_name_is_process = true
44       $keepalived_vrrp_script     = undef
45     }
46   }
47
48   class { 'keepalived': }
49   keepalived::vrrp_script { 'haproxy':
50     name_is_process => $keepalived_name_is_process,
51     script          => $keepalived_vrrp_script,
52   }
53
54   # KEEPALIVE INSTANCE CONTROL
55   keepalived::instance { '51':
56     interface     => hiera('control_virtual_interface'),
57     virtual_ips   => [join([hiera('controller_virtual_ip'), ' dev ', hiera('control_virtual_interface')])],
58     state         => 'MASTER',
59     track_script  => ['haproxy'],
60     priority      => 101,
61   }
62
63   # KEEPALIVE INSTANCE PUBLIC
64   keepalived::instance { '52':
65     interface     => hiera('public_virtual_interface'),
66     virtual_ips   => [join([hiera('public_virtual_ip'), ' dev ', hiera('public_virtual_interface')])],
67     state         => 'MASTER',
68     track_script  => ['haproxy'],
69     priority      => 101,
70   }
71
72   sysctl::value { 'net.ipv4.ip_nonlocal_bind': value => '1' }
73
74   class { 'haproxy':
75     global_options   => {
76       'log'     => '/dev/log local0',
77       'pidfile' => '/var/run/haproxy.pid',
78       'user'    => 'haproxy',
79       'group'   => 'haproxy',
80       'daemon'  => '',
81       'maxconn' => '4000',
82     },
83     defaults_options => {
84       'mode'    => 'tcp',
85       'log'     => 'global',
86       'retries' => '3',
87       'maxconn' => '150',
88       'option'  => [ 'tcpka', 'tcplog' ],
89       'timeout' => [ 'http-request 10s', 'queue 1m', 'connect 10s', 'client 1m', 'server 1m', 'check 10s' ],
90     },
91   }
92
93   haproxy::listen { 'haproxy.stats':
94     ipaddress        => '*',
95     ports            => '1993',
96     mode             => 'http',
97     options          => {
98       'stats' => 'enable',
99     },
100     collect_exported => false,
101   }
102
103   if $keystone_admin {
104     haproxy::listen { 'keystone_admin':
105       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
106       ports            => 35357,
107       options          => { 'option' => [ 'httpchk GET /' ] },
108       collect_exported => false,
109     }
110     haproxy::balancermember { 'keystone_admin':
111       listening_service => 'keystone_admin',
112       ports             => '35357',
113       ipaddresses       => hiera('controller_host'),
114       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
115     }
116   }
117
118   if $keystone_public {
119     haproxy::listen { 'keystone_public':
120       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
121       ports            => 5000,
122       options          => { 'option' => [ 'httpchk GET /' ] },
123       collect_exported => false,
124     }
125     haproxy::balancermember { 'keystone_public':
126       listening_service => 'keystone_public',
127       ports             => '5000',
128       ipaddresses       => hiera('controller_host'),
129       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
130     }
131   }
132
133   if $neutron {
134     haproxy::listen { 'neutron':
135       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
136       ports            => 9696,
137       options          => { 'option' => [ 'httpchk GET /' ] },
138       collect_exported => false,
139     }
140     haproxy::balancermember { 'neutron':
141       listening_service => 'neutron',
142       ports             => '9696',
143       ipaddresses       => hiera('controller_host'),
144       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
145     }
146   }
147
148   if $cinder {
149     haproxy::listen { 'cinder':
150       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
151       ports            => 8776,
152       options          => { 'option' => [ 'httpchk GET /' ] },
153       collect_exported => false,
154     }
155     haproxy::balancermember { 'cinder':
156       listening_service => 'cinder',
157       ports             => '8776',
158       ipaddresses       => hiera('controller_host'),
159       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
160     }
161   }
162
163   if $glance_api {
164     haproxy::listen { 'glance_api':
165       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
166       ports            => 9292,
167       options          => { 'option' => [ 'httpchk GET /' ] },
168       collect_exported => false,
169     }
170     haproxy::balancermember { 'glance_api':
171       listening_service => 'glance_api',
172       ports             => '9292',
173       ipaddresses       => hiera('controller_host'),
174       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
175     }
176   }
177
178
179   if $glance_registry {
180     haproxy::listen { 'glance_registry':
181       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
182       ports            => 9191,
183       options          => { 'option' => [ 'httpchk GET /' ] },
184       collect_exported => false,
185     }
186     haproxy::balancermember { 'glance_registry':
187       listening_service => 'glance_registry',
188       ports             => '9191',
189       ipaddresses       => hiera('controller_host'),
190       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
191     }
192   }
193
194   if $nova_ec2 {
195     haproxy::listen { 'nova_ec2':
196       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
197       ports            => 8773,
198       options          => { 'option' => [ 'httpchk GET /' ] },
199       collect_exported => false,
200     }
201     haproxy::balancermember { 'nova_ec2':
202       listening_service => 'nova_ec2',
203       ports             => '8773',
204       ipaddresses       => hiera('controller_host'),
205       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
206     }
207   }
208
209   if $nova_osapi {
210     haproxy::listen { 'nova_osapi':
211       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
212       ports            => 8774,
213       options          => { 'option' => [ 'httpchk GET /' ] },
214       collect_exported => false,
215     }
216     haproxy::balancermember { 'nova_osapi':
217       listening_service => 'nova_osapi',
218       ports             => '8774',
219       ipaddresses       => hiera('controller_host'),
220       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
221     }
222   }
223
224   if $nova_metadata {
225     haproxy::listen { 'nova_metadata':
226       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
227       ports            => 8775,
228       options          => { 'option' => [ 'httpchk GET /' ] },
229       collect_exported => false,
230     }
231     haproxy::balancermember { 'nova_metadata':
232       listening_service => 'nova_metadata',
233       ports             => '8775',
234       ipaddresses       => hiera('controller_host'),
235       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
236     }
237   }
238
239   if $nova_novncproxy {
240     haproxy::listen { 'nova_novncproxy':
241       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
242       ports            => 6080,
243       options          => { 'option' => [ 'httpchk GET /' ] },
244       collect_exported => false,
245     }
246     haproxy::balancermember { 'nova_novncproxy':
247       listening_service => 'nova_novncproxy',
248       ports             => '6080',
249       ipaddresses       => hiera('controller_host'),
250       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
251     }
252   }
253
254   if $ceilometer {
255     haproxy::listen { 'ceilometer':
256       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
257       ports            => 8777,
258       collect_exported => false,
259     }
260     haproxy::balancermember { 'ceilometer':
261       listening_service => 'ceilometer',
262       ports             => '8777',
263       ipaddresses       => hiera('controller_host'),
264       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
265     }
266   }
267
268   if $swift_proxy_server {
269     haproxy::listen { 'swift_proxy_server':
270       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
271       ports            => 8080,
272       options          => { 'option' => [ 'httpchk GET /info' ] },
273       collect_exported => false,
274     }
275     haproxy::balancermember { 'swift_proxy_server':
276       listening_service => 'swift_proxy_server',
277       ports             => '8080',
278       ipaddresses       => hiera('controller_host'),
279       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
280     }
281   }
282
283   if $heat_api {
284     haproxy::listen { 'heat_api':
285       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
286       ports            => 8004,
287       options          => { 'option' => [ 'httpchk GET /' ] },
288       collect_exported => false,
289     }
290     haproxy::balancermember { 'heat_api':
291       listening_service => 'heat_api',
292       ports             => '8004',
293       ipaddresses       => hiera('controller_host'),
294       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
295     }
296   }
297
298   if $heat_cloudwatch {
299     haproxy::listen { 'heat_cloudwatch':
300       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
301       ports            => 8003,
302       options          => { 'option' => [ 'httpchk GET /' ] },
303       collect_exported => false,
304     }
305     haproxy::balancermember { 'heat_cloudwatch':
306       listening_service => 'heat_cloudwatch',
307       ports             => '8003',
308       ipaddresses       => hiera('controller_host'),
309       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
310     }
311   }
312
313   if $heat_cfn {
314     haproxy::listen { 'heat_cfn':
315       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
316       ports            => 8000,
317       options          => { 'option' => [ 'httpchk GET /' ] },
318       collect_exported => false,
319     }
320     haproxy::balancermember { 'heat_cfn':
321       listening_service => 'heat_cfn',
322       ports             => '8000',
323       ipaddresses       => hiera('controller_host'),
324       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
325     }
326   }
327
328   if $horizon {
329     haproxy::listen { 'horizon':
330       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
331       ports            => 80,
332       options          => { 'option' => [ 'httpchk GET /' ] },
333       collect_exported => false,
334     }
335     haproxy::balancermember { 'horizon':
336       listening_service => 'horizon',
337       ports             => '80',
338       ipaddresses       => hiera('controller_host'),
339       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
340     }
341   }
342
343   if $mysql {
344     haproxy::listen { 'mysql':
345       ipaddress        => [hiera('controller_virtual_ip')],
346       ports            => 3306,
347       options          => { 'timeout' => [ 'client 0', 'server 0' ] },
348       collect_exported => false,
349     }
350     haproxy::balancermember { 'mysql':
351       listening_service => 'mysql',
352       ports             => '3306',
353       ipaddresses       => hiera('controller_host'),
354       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
355     }
356   }
357
358   if $rabbitmq {
359     haproxy::listen { 'rabbitmq':
360       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
361       ports            => 5672,
362       options          => { 'timeout' => [ 'client 0', 'server 0' ] },
363       collect_exported => false,
364     }
365     haproxy::balancermember { 'rabbitmq':
366       listening_service => 'rabbitmq',
367       ports             => '5672',
368       ipaddresses       => hiera('controller_host'),
369       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
370     }
371   }
372
373 }
374
375 include ::tripleo::loadbalancer