File: haproxy.rst

package info (click to toggle)
python-haproxyadmin 0.2.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 436 kB
  • sloc: python: 1,500; makefile: 165; sh: 1
file content (235 lines) | stat: -rw-r--r-- 5,820 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
.. _haproxy:

HAProxy Operations
------------------

Get some information about the running processes

.. code:: python

    >>> hap.processids
    [871, 870, 869, 868]
    >>>
    >>> hap.description
    'Test server'
    >>>
    >>> hap.releasedate
    '2014/10/31'
    >>>
    >>> hap.version
    '1.5.8'
    >>>
    >>> hap.uptime
    '2d 0h55m09s'
    >>>
    >>> hap.uptimesec
    176112
    >>>
    >>> hap.nodename
    'test.foo.com'
    >>>
    >>> hap.totalrequests
    796

.. note::
    ``totalrequests`` returns the total number of requests that are processed
    by HAProxy. It counts requests for frontends and backends. Don't forget that
    a single client request passes HAProxy twice.

Dynamically change the specified global maxconn setting.

.. code:: python

    >>> print(hap.maxconn)
    40000
    >>> hap.setmaxconn(5000)
    True
    >>> print(hap.maxconn)
    20000
    >>>

.. note:: New setting is applied per process and the sum is returned.


Get a list of :class:`Frontend <.Frontend>` objects for all frontends

.. code:: python

    >>> frontends = hap.frontends()
    >>> for f in frontends:
    ...    print(f.name)
    ...
    frontend_proc1
    haproxy
    frontend1_proc34
    frontend2_proc34
    frontend_proc2


Get a :class:`Frontend <.Frontend>` object for a single frontend

.. code:: python

    >>> frontend1 = hap.frontend('frontend1_proc34')
    >>> frontend1.name, frontend1.process_nb
    ('frontend1_proc34', [4, 3])

Get a list of :class:`Backend <.Backend>` objects for all backends

.. code:: python

    >>> backends = hap.backends()
    >>> for b in backends:
    ...    print(b.name)
    ...
    haproxy
    backend1_proc34
    backend_proc2
    backend_proc1
    backend2_proc34

Get a :class:`Backend <.Backend>` object for a single backend

.. code:: python

    >>> backend1 = hap.backend('backend1_proc34')
    >>> backend1.name, backend1.process_nb
    ('backend1_proc34', [4, 3])

Get a list of :class:`Server <.Server>` objects for each server

.. code:: python

    >>> servers = hap.servers()
    >>> for s in servers:
    ...    print(s.name, s.backendname)
    ...
    bck1_proc34_srv1 backend1_proc34
    bck1_proc34_srv2 backend1_proc34
    bck_all_srv1 backend1_proc34
    bck_proc2_srv3_proc2 backend_proc2
    bck_proc2_srv1_proc2 backend_proc2
    bck_proc2_srv4_proc2 backend_proc2
    bck_proc2_srv2_proc2 backend_proc2
    member1_proc1 backend_proc1
    bck_all_srv1 backend_proc1
    member2_proc1 backend_proc1
    bck2_proc34_srv1 backend2_proc34
    bck_all_srv1 backend2_proc34
    bck2_proc34_srv2 backend2_proc34

.. note::
     if a server is member of more than 1 backends then muliple
     :class:`Server <.Server>` objects for the server is returned

Limit the list of server for a specific pool

.. code:: python

    >>> servers = hap.servers(backend='backend1_proc34')
    >>> for s in servers:
    ...    print(s.name, s.backendname)
    ...
    bck1_proc34_srv1 backend1_proc34
    bck1_proc34_srv2 backend1_proc34
    bck_all_srv1 backend1_proc34

Work on specific server across all backends

.. code:: python

    >>> s1 = hap.server(hostname='bck_all_srv1')
    >>> for x in s1:
    ...    print(x.name, x.backendname, x.status)
    ...    x.setstate(haproxy.STATE_DISABLE)
    ...    print(x.status)
    ...
    bck_all_srv1 backend1_proc34 DOWN
    True
    MAINT
    bck_all_srv1 backend_proc1 DOWN
    True
    MAINT
    bck_all_srv1 backend2_proc34 no check
    True
    MAINT


Examples for ACLs

.. code:: python

    >>> from pprint import pprint
    >>> pprint(hap.show_acl())
    ['# id (file) description',
    "0 (/etc/haproxy/wl_stats) pattern loaded from file '/etc/haproxy/wl_stats' "
    "used by acl at file '/etc/haproxy/haproxy.cfg' line 53",
    "1 () acl 'src' file '/etc/haproxy/haproxy.cfg' line 53",
    "3 () acl 'ssl_fc' file '/etc/haproxy/haproxy.cfg' line 85",
    '4 (/etc/haproxy/bl_frontend) pattern loaded from file '
    "'/etc/haproxy/bl_frontend' used by acl at file '/etc/haproxy/haproxy.cfg' "
    'line 97',
    "5 () acl 'src' file '/etc/haproxy/haproxy.cfg' line 97",
    "6 () acl 'path_beg' file '/etc/haproxy/haproxy.cfg' line 99",
    "7 () acl 'req.cook' file '/etc/haproxy/haproxy.cfg' line 114",
    "8 () acl 'req.cook' file '/etc/haproxy/haproxy.cfg' line 115",
    "9 () acl 'req.cook' file '/etc/haproxy/haproxy.cfg' line 116",
    '']
    >>> hap.show_acl(6)
    ['0x12ea940 /static/css/', '']
    >>> hap.add_acl(6, '/foobar')
    True
    >>> hap.show_acl(6)
    ['0x12ea940 /static/css/', '0x13a38b0 /foobar', '']
    >>> hap.add_acl(6, '/foobar')
    True
    >>> hap.show_acl(6)
    ['0x12ea940 /static/css/', '0x13a38b0 /foobar', '0x13a3930 /foobar', '']
    >>> hap.del_acl(6, '/foobar')
    True
    >>> hap.show_acl(6)
    ['0x12ea8a0 /static/js/', '0x12ea940 /static/css/', '']


Examples for MAPs

.. code:: python

    >>> from haproxyadmin import haproxy
    >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy')
    >>> hap.show_map(map=6)
    ['# id (file) description',
    "0 (/etc/haproxy/v-m1-bk) pattern loaded ...... line 82",
    '']
    >>> hap.show_map(0)
    ['0x1a78ab0 0 www.foo.com-0', '0x1a78b20 1 www.foo.com-1', '']


Manage MAPs

.. code:: python

    >>> hap.show_map(0)
    ['0x1a78b20 1 www.foo.com-1', '']
    >>> hap.add_map(0, '9', 'foo')
    True
    >>> hap.show_map(0)
    ['0x1a78b20 1 www.foo.com-1', '0x1b15c80 9 foo', '']

.. code:: python

    >>> hap.show_map(0)
    ['0x1b15cd0 9 foo', '0x1a78980 11 bar', '']
    >>> hap.del_map(0, '0x1b15cd0')
    True
    >>> hap.show_map(0)
    ['0x1a78980 11 bar', '']
    >>> hap.add_map(0, '22', 'bar22')
    True
    >>> hap.show_map(0)
    ['0x1a78980 11 bar', '0x1b15c00 22 bar22', '']
    >>> hap.del_map(0, '22')
    True
    >>> hap.show_map(0)
    ['0x1a78980 11 bar', '']