blob: 19178f9fd2b83732ac49ed1460e930e8f7083347 [file] [log] [blame]
Filip Pytloun78944bc2016-04-13 13:03:54 +02001{%- from "haproxy/map.jinja" import proxy with context -%}
Filip Pytloun48d38302015-10-06 16:28:31 +02002
3global
Filip Pytloun78944bc2016-04-13 13:03:54 +02004 log /dev/log local0
5 log /dev/log local1 notice
6 chroot /var/lib/haproxy
7 stats socket {{ proxy.stats_socket }} mode 660 level admin
8 stats timeout 30s
Filip Pytloun48d38302015-10-06 16:28:31 +02009 user haproxy
Filip Pytloun78944bc2016-04-13 13:03:54 +020010 group haproxy
11 daemon
12 pidfile /var/run/haproxy.pid
Filip Pytloun48d38302015-10-06 16:28:31 +020013 spread-checks 4
14 tune.maxrewrite 1024
15 tune.bufsize 32768
Filip Pytloun78944bc2016-04-13 13:03:54 +020016 maxconn 16000
Filip Pytloun48d38302015-10-06 16:28:31 +020017
18defaults
19 log global
20 mode http
Filip Pytloun48d38302015-10-06 16:28:31 +020021
22 maxconn 8000
23 {#
24 timeout connect {{ proxy.get('connect_timeout', '5000') }}ms
25 timeout client {{ proxy.get('client_timeout', '50000ms') }}ms
26 timeout server {{ proxy.get('server_timeout', '50000ms') }}ms
27 #}
28 option redispatch
29 retries 3
30 stats enable
31 timeout http-request 10s
32 timeout queue 1m
33 timeout connect 10s
34 timeout client 1m
35 timeout server 1m
36 timeout check 10s
37
Jiri Konecny371c6de2016-03-02 11:32:46 +010038{%- if proxy.listen.admin_page is defined and proxy.listen.admin_page.user is defined %}
Filip Pytloun48d38302015-10-06 16:28:31 +020039
40userlist STATSUSERS
41 group admin users admin
42 user {{ proxy.listen.admin_page.user }} insecure-password {{ proxy.listen.admin_page.password }}
43 user stats insecure-password {{ proxy.listen.admin_page.password }}
44{#
45{%- for listen_name, listen in proxy.get('listen', {}).iteritems() %}
46{%- if listen.user is defined %}
47 user {{ listen.user }} insecure-password {{ listen.password }}
48{%- endif %}
49{%- endfor %}
50#}
51
52{%- endif %}
53
54{%- for listen_name, listen in proxy.get('listen', {}).iteritems() %}
55{%- if listen.get('format', 'listen') == 'listen' %}
56
57listen {{ listen_name }}
58 {%- for bind in listen.binds %}
59 bind {{ bind.address }}:{{ bind.port }}
60 {%- endfor %}
Filip Pytloun70473662016-08-25 17:08:20 +020061 {%- if listen.get('type', None) == 'http' %}
Filip Pytloun48d38302015-10-06 16:28:31 +020062 mode http
63 balance roundrobin
64 option httplog
Filip Pytloun70473662016-08-25 17:08:20 +020065 {%- elif listen.get('type', None) == 'rabbitmq' %}
Filip Pytloun48d38302015-10-06 16:28:31 +020066 balance roundrobin
67 mode tcp
68 option tcpka
69 timeout client 48h
70 timeout server 48h
Filip Pytloun70473662016-08-25 17:08:20 +020071 {%- elif listen.get('type', None) == 'mysql' %}
Filip Pytloun48d38302015-10-06 16:28:31 +020072 balance leastconn
73 mode tcp
74 option httpchk
75 option tcplog
76 option clitcpka
77 option srvtcpka
78 timeout client 28801s
79 timeout server 28801s
80 option mysql-check user haproxy
Filip Pytloun70473662016-08-25 17:08:20 +020081 {%- elif listen.get('type', None) == 'horizon' %}
Filip Pytloun48d38302015-10-06 16:28:31 +020082 balance source
83 capture cookie vgnvisitor= len 32
84 cookie SERVERID insert indirect nocache
85 mode http
86 option forwardfor
87 option httpchk
88 option httpclose
89 option httplog
90 rspidel ^Set-cookie:\ IP=
Filip Pytloun70473662016-08-25 17:08:20 +020091 {%- elif listen.get('type', None) == 'general-service' %}
Filip Pytloun48d38302015-10-06 16:28:31 +020092 mode http
93 balance roundrobin
94 option httplog
Filip Pytloun70473662016-08-25 17:08:20 +020095 {%- elif listen.get('type', None) == 'openstack-service' %}
Filip Pytloun48d38302015-10-06 16:28:31 +020096 option httpchk
97 option httplog
98 option httpclose
Filip Pytloun70473662016-08-25 17:08:20 +020099 {%- elif listen.get('type', None) == 'heat' %}
Filip Pytloun48d38302015-10-06 16:28:31 +0200100 balance source
101 option tcpka
102 option httpchk
103 option tcplog
Filip Pytloun70473662016-08-25 17:08:20 +0200104 {%- elif listen.get('type', None) == 'contrail-config' %}
Filip Pytloun48d38302015-10-06 16:28:31 +0200105 mode http
106 stats enable
107 stats uri /
108 stats auth {{ listen.user }}:{{ listen.password }}
Filip Pytloun70473662016-08-25 17:08:20 +0200109 {%- elif listen.get('type', None) == 'contrail-api' %}
Filip Pytloun48d38302015-10-06 16:28:31 +0200110 option nolinger
111 balance roundrobin
Filip Pytloun70473662016-08-25 17:08:20 +0200112 {%- elif listen.get('type', None) == 'contrail-analytics' %}
Filip Pytloun48d38302015-10-06 16:28:31 +0200113 option nolinger
114 balance roundrobin
115 option tcp-check
116 tcp-check connect port 6379
117 default-server error-limit 1 on-error mark-down
Filip Pytloun70473662016-08-25 17:08:20 +0200118 {%- elif listen.get('type', None) == 'stats' %}
Filip Pytloun48d38302015-10-06 16:28:31 +0200119 mode http
120 stats enable
121 stats uri /
Jiri Konecny371c6de2016-03-02 11:32:46 +0100122 {%- if listen.user is defined %}
Filip Pytloun48d38302015-10-06 16:28:31 +0200123 stats auth {{ listen.user }}:{{ listen.password }}
124 {%- endif %}
Filip Pytloun70473662016-08-25 17:08:20 +0200125 {%- elif listen.get('type', None) == 'admin' %}
Filip Pytloun48d38302015-10-06 16:28:31 +0200126 mode http
127 acl AuthOkay_ReadOnly http_auth(STATSUSERS)
128 acl AuthOkay_Admin http_auth_group(STATSUSERS) {{ listen.user }}
129 stats enable
130 stats refresh 60s
131 stats uri /
132 stats http-request auth realm admin_page unless AuthOkay_ReadOnly
133 stats admin if AuthOkay_Admin
Filip Pytloun70473662016-08-25 17:08:20 +0200134 {%- else %}
135 {# no type specified #}
136 mode {{ listen.mode|default('tcp') }}
137 {%- for acl in listen.get('acl', []) %}
138 acl {{ acl }}
139 {%- endfor %}
140 balance {{ listen.balance|default('roundrobin') }}
141 {%- for option in listen.get('options', []) %}
142 option {{ option }}
143 {%- endfor %}
Filip Pytloun161572b2016-08-26 10:28:29 +0200144 {%- for reqadd in listen.get('reqadd', []) %}
Filip Pytloune9e246f2016-08-26 09:44:51 +0200145 reqadd {{ reqadd }}
146 {%- endfor %}
Filip Pytloun161572b2016-08-26 10:28:29 +0200147 {%- for reqirep in listen.get('reqirep', []) %}
Filip Pytloune9e246f2016-08-26 09:44:51 +0200148 reqirep {{ reqirep }}
149 {%- endfor %}
Filip Pytloun48d38302015-10-06 16:28:31 +0200150 {%- endif %}
151 {%- for server in listen.get('servers', []) %}
152 server {{ server.name }} {{ server.host }}:{{ server.port }} {{ server.get('params', '') }}
153 {%- endfor %}
154{%- endif %}
155{%- endfor %}
156
157{%- for listen_name, listen in proxy.get('listen', {}).iteritems() %}
158{%- if listen.get('format', 'listen') == 'end' %}
159
160frontend {{ listen_name }} {{ listen.binds[0].address }}:{{ listen.binds[0].port }}
161 {%- for acl in listen.get('acls', []) %}
162 {%- for condition in acl.get('conditions', []) %}
163 acl {{ acl.name }} {{ condition.type }} {{ condition.condition }}
164 {%- endfor %}
165 use_backend {{ acl.name }}-backend if {{ acl.name }}
166 {%- endfor %}
167 default_backend {{ listen_name }}-backend
168
169backend {{ listen_name }}-backend
Filip Pytloun70473662016-08-25 17:08:20 +0200170 {%- if listen.get('type', None) == 'http' %}
Filip Pytloun48d38302015-10-06 16:28:31 +0200171 balance roundrobin
172 {%- endif %}
173 {%- for server in listen.get('servers', []) %}
174 server {{ server.get('name', server.host) }} {{ server.host }}:{{ server.port }} {{ server.get('params', '') }}
175 {%- endfor %}
176{%- for acl in listen.get('acls', []) %}
177
178backend {{ acl.name }}-backend
179 balance roundrobin
180 {%- for server in acl.get('servers', []) %}
181 server {{ server.get('name', server.host) }} {{ server.host }}:{{ server.port }} {{ server.get('params', '') }}
182 {%- endfor %}
183{%- endfor %}
184{%- endif %}
185{%- endfor %}