Import haproxyadmin package


In [1]:
from pprint import pprint
from haproxyadmin import (haproxy, exceptions)
hap = haproxy.HAProxy(socket_dir='/run/haproxy')

In [3]:
f = hap.frontend('frontend2_proc34')
f.status


Out[3]:
'OPEN'

HAProxy operations

Change global settings


In [2]:
print(hap.maxconn)
print(hap.setmaxconn(5000))
print(hap.maxconn)


40000
True
20000

In [3]:
print(hap.ratelimitconn)
hap.setratelimitconn(99999)
print(hap.ratelimitconn)


0
399996

In [4]:
print(hap.ratelimitsslsess)
print(hap.setratelimitsslsess(99999))
print(hap.ratelimitsslsess)


0
True
399996

Clear counters


In [5]:
hap.clearcounters()


Out[5]:
True

In [6]:
hap.clearcounters(all=True)


Out[6]:
True

ACLs


In [7]:
pprint(hap.show_acl())


['# id (file) description',
 "1 () acl 'ssl_fc' file '/etc/haproxy/haproxy.cfg' line 83",
 '2 (/etc/haproxy/bl_frontend) pattern loaded from file '
 "'/etc/haproxy/bl_frontend' used by acl at file '/etc/haproxy/haproxy.cfg' "
 'line 95',
 "3 () acl 'src' file '/etc/haproxy/haproxy.cfg' line 95",
 "4 () acl 'path_beg' file '/etc/haproxy/haproxy.cfg' line 97",
 "5 () acl 'req.cook' file '/etc/haproxy/haproxy.cfg' line 111",
 "6 () acl 'req.cook' file '/etc/haproxy/haproxy.cfg' line 112",
 "7 () acl 'req.cook' file '/etc/haproxy/haproxy.cfg' line 113",
 '']

In [8]:
pprint(hap.show_acl(acl=2))
hap.del_acl(acl=2, key='11.155.183.41')
pprint(hap.show_acl(acl=2))


['0x1a95fa0 11.155.183.41', '']
['']

In [ ]:
pprint(hap.show_acl(acl=4))
print(hap.del_acl(acl=4, key='/foo'))
pprint(hap.show_acl(acl=4))
#hap.clear_acl(acl=4)
pprint(hap.show_acl(acl=4))
hap.get_acl(acl=4, value='/foo')

Show session errors


In [33]:
pprint(hap.errors())


[('4', ['Total events captured on [03/May/2015:22:24:08.119] : 0', '']),
 ('3', ['Total events captured on [03/May/2015:22:24:08.120] : 0', '']),
 ('2', ['Total events captured on [03/May/2015:22:24:08.120] : 0', '']),
 ('1', ['Total events captured on [03/May/2015:22:24:08.120] : 0', ''])]

Show HAProxy process information


In [34]:
pprint(hap.info())


[{'CompressBpsIn': '0',
  'CompressBpsOut': '0',
  'CompressBpsRateLim': '0',
  'ConnRate': '0',
  'ConnRateLimit': '99999',
  'CumConns': '68',
  'CumReq': '68',
  'CumSslConns': '0',
  'CurrConns': '0',
  'CurrSslConns': '0',
  'Hard_maxconn': '10000',
  'Idle_pct': '100',
  'MaxConnRate': '0',
  'MaxSessRate': '0',
  'MaxSslConns': '0',
  'MaxSslRate': '0',
  'MaxZlibMemUsage': '0',
  'Maxconn': '5000',
  'Maxpipes': '0',
  'Maxsock': '20072',
  'Memmax_MB': '0',
  'Name': 'HAProxy',
  'Nbproc': '4',
  'Pid': '2232',
  'PipesFree': '0',
  'PipesUsed': '0',
  'Process_num': '4',
  'Release_date': '2014/10/31',
  'Run_queue': '1',
  'SessRate': '0',
  'SessRateLimit': '0',
  'SslBackendKeyRate': '0',
  'SslBackendMaxKeyRate': '0',
  'SslCacheLookups': '0',
  'SslCacheMisses': '0',
  'SslFrontendKeyRate': '0',
  'SslFrontendMaxKeyRate': '0',
  'SslFrontendSessionReuse_pct': '0',
  'SslRate': '0',
  'SslRateLimit': '99999',
  'Tasks': '17',
  'Ulimit-n': '20072',
  'Uptime': '0d 0h07m22s',
  'Uptime_sec': '442',
  'Version': '1.5.8',
  'ZlibMemUsage': '0',
  'node': 'axilleas'},
 {'CompressBpsIn': '0',
  'CompressBpsOut': '0',
  'CompressBpsRateLim': '0',
  'ConnRate': '0',
  'ConnRateLimit': '99999',
  'CumConns': '68',
  'CumReq': '68',
  'CumSslConns': '0',
  'CurrConns': '0',
  'CurrSslConns': '0',
  'Hard_maxconn': '10000',
  'Idle_pct': '100',
  'MaxConnRate': '0',
  'MaxSessRate': '0',
  'MaxSslConns': '0',
  'MaxSslRate': '0',
  'MaxZlibMemUsage': '0',
  'Maxconn': '5000',
  'Maxpipes': '0',
  'Maxsock': '20072',
  'Memmax_MB': '0',
  'Name': 'HAProxy',
  'Nbproc': '4',
  'Pid': '2231',
  'PipesFree': '0',
  'PipesUsed': '0',
  'Process_num': '3',
  'Release_date': '2014/10/31',
  'Run_queue': '1',
  'SessRate': '0',
  'SessRateLimit': '0',
  'SslBackendKeyRate': '0',
  'SslBackendMaxKeyRate': '0',
  'SslCacheLookups': '0',
  'SslCacheMisses': '0',
  'SslFrontendKeyRate': '0',
  'SslFrontendMaxKeyRate': '0',
  'SslFrontendSessionReuse_pct': '0',
  'SslRate': '0',
  'SslRateLimit': '99999',
  'Tasks': '17',
  'Ulimit-n': '20072',
  'Uptime': '0d 0h07m22s',
  'Uptime_sec': '442',
  'Version': '1.5.8',
  'ZlibMemUsage': '0',
  'node': 'axilleas'},
 {'CompressBpsIn': '0',
  'CompressBpsOut': '0',
  'CompressBpsRateLim': '0',
  'ConnRate': '0',
  'ConnRateLimit': '99999',
  'CumConns': '25',
  'CumReq': '25',
  'CumSslConns': '0',
  'CurrConns': '0',
  'CurrSslConns': '0',
  'Hard_maxconn': '10000',
  'Idle_pct': '100',
  'MaxConnRate': '0',
  'MaxSessRate': '0',
  'MaxSslConns': '0',
  'MaxSslRate': '0',
  'MaxZlibMemUsage': '0',
  'Maxconn': '5000',
  'Maxpipes': '0',
  'Maxsock': '20072',
  'Memmax_MB': '0',
  'Name': 'HAProxy',
  'Nbproc': '4',
  'Pid': '2230',
  'PipesFree': '0',
  'PipesUsed': '0',
  'Process_num': '2',
  'Release_date': '2014/10/31',
  'Run_queue': '1',
  'SessRate': '0',
  'SessRateLimit': '0',
  'SslBackendKeyRate': '0',
  'SslBackendMaxKeyRate': '0',
  'SslCacheLookups': '0',
  'SslCacheMisses': '0',
  'SslFrontendKeyRate': '0',
  'SslFrontendMaxKeyRate': '0',
  'SslFrontendSessionReuse_pct': '0',
  'SslRate': '0',
  'SslRateLimit': '99999',
  'Tasks': '17',
  'Ulimit-n': '20072',
  'Uptime': '0d 0h07m22s',
  'Uptime_sec': '442',
  'Version': '1.5.8',
  'ZlibMemUsage': '0',
  'node': 'axilleas'},
 {'CompressBpsIn': '0',
  'CompressBpsOut': '0',
  'CompressBpsRateLim': '0',
  'ConnRate': '0',
  'ConnRateLimit': '99999',
  'CumConns': '25',
  'CumReq': '25',
  'CumSslConns': '0',
  'CurrConns': '0',
  'CurrSslConns': '0',
  'Hard_maxconn': '10000',
  'Idle_pct': '100',
  'MaxConnRate': '0',
  'MaxSessRate': '0',
  'MaxSslConns': '0',
  'MaxSslRate': '0',
  'MaxZlibMemUsage': '0',
  'Maxconn': '5000',
  'Maxpipes': '0',
  'Maxsock': '20072',
  'Memmax_MB': '0',
  'Name': 'HAProxy',
  'Nbproc': '4',
  'Pid': '2229',
  'PipesFree': '0',
  'PipesUsed': '0',
  'Process_num': '1',
  'Release_date': '2014/10/31',
  'Run_queue': '1',
  'SessRate': '0',
  'SessRateLimit': '0',
  'SslBackendKeyRate': '0',
  'SslBackendMaxKeyRate': '0',
  'SslCacheLookups': '0',
  'SslCacheMisses': '0',
  'SslFrontendKeyRate': '0',
  'SslFrontendMaxKeyRate': '0',
  'SslFrontendSessionReuse_pct': '0',
  'SslRate': '0',
  'SslRateLimit': '99999',
  'Tasks': '17',
  'Ulimit-n': '20072',
  'Uptime': '0d 0h07m22s',
  'Uptime_sec': '442',
  'Version': '1.5.8',
  'ZlibMemUsage': '0',
  'node': 'axilleas'}]

Show total requests served by processes


In [9]:
print(hap.requests)


11

Show HAProxy process metrics


In [10]:
for metric in hap.HAPROXY_METRICS:
    print("{}={}".format(metric, hap.metric(metric)))


SslFrontendMaxKeyRate=0
Hard_maxconn=40000
SessRateLimit=0
Process_num=10
Memmax_MB=0
CompressBpsRateLim=0
MaxSslConns=0
ConnRateLimit=399996
SslRateLimit=399996
MaxConnRate=3
CumConns=843
SslBackendKeyRate=0
SslCacheLookups=0
CurrSslConns=0
Run_queue=4
Maxpipes=0
Idle_pct=400
SslFrontendKeyRate=0
Tasks=68
MaxZlibMemUsage=0
SslFrontendSessionReuse_pct=0
CurrConns=0
SslCacheMisses=0
SslRate=0
CumSslConns=0
PipesUsed=0
Maxconn=20000
CompressBpsIn=0
ConnRate=0
Ulimit-n=80288
SessRate=0
SslBackendMaxKeyRate=0
CumReq=942
PipesFree=0
ZlibMemUsage=0
Uptime_sec=11530.0
CompressBpsOut=0
Maxsock=80288
MaxSslRate=0
MaxSessRate=3

Frontend operations

List all frontends


In [11]:
frontends = hap.frontends()
for f in frontends:
    print("Frontend {} status {} requests {} referenced by processes {}".format(f.name,
                                                                                f.status,
                                                                                f.requests,
                                                                                f.process_nb))


Frontend frontend_proc1 status OPEN requests 3 referenced by processes [1]
Frontend haproxy status OPEN requests 0 referenced by processes [4, 3, 2, 1]
Frontend frontend2_proc34 status STOP requests 0 referenced by processes [4, 3]
Frontend frontend1_proc34 status OPEN requests 8 referenced by processes [4, 3]
Frontend frontend_proc2 status STOP requests 0 referenced by processes [2]

Disable frontend


In [42]:
f1 = hap.frontend('frontend_proc2')
print(f1.status)
try:
    f1.disable()
except exceptions.CommandFailed as error:
    print(error)
print(f1.status)


OPEN
STOP

Handle exception in a different way


In [44]:
f1 = hap.frontend('frontend_proc2')
print(f1.status)
if not f1.disable(die=False):
    print("Failed to disable frontend")

    if f1.status == 'STOP':
        print("oops it is already disabled, no worries")
    else:
        print("Arg, status{}".format(f1.status))


STOP
Failed to disable frontend
oops it is already disabled, no worries

Shutdown frontend


In [40]:
print(f1.status)
f1.shutdown()
# Frontend is now removed, any futher operations on it will return KeyError exception
# except for enable() method which returns
# exceptions.CommandFailed: Frontend was previously shut down, cannot enable


STOP
Out[40]:
True

Set some settings


In [45]:
print("Max connnections {}".format(f1.maxconn))
if f1.setmaxconn(50000):
    print("New max connnections {}".format(f1.maxconn))


Max connnections 1000000
New max connnections 50000

Get metrics


In [46]:
for m in haproxy.FRONTEND_METRICS:
    print("{}={}".format(m, f1.metric(m)))


bin=0
bout=0
comp_byp=0
comp_in=0
comp_out=0
comp_rsp=0
dreq=0
dresp=0
ereq=0
hrsp_1xx=0
hrsp_2xx=0
hrsp_3xx=0
hrsp_4xx=0
hrsp_5xx=0
hrsp_other=0
rate=0
rate_lim=100000
rate_max=0
req_rate=0
req_rate_max=0
req_tot=0
scur=0
slim=50000
smax=0
stot=0

Get requests per process


In [12]:
f2 = hap.frontend('frontend1_proc34')
pprint(f2.requests_per_process())


[(4, 3), (3, 5)]

Get all statistics per process


In [13]:
pprint(f2.stats_per_process())


[(4,
  {'': '',
   'act': '',
   'bck': '',
   'bin': '228',
   'bout': '3645',
   'check_code': '',
   'check_duration': '',
   'check_status': '',
   'chkdown': '',
   'chkfail': '',
   'cli_abrt': '',
   'comp_byp': '0',
   'comp_in': '0',
   'comp_out': '0',
   'comp_rsp': '0',
   'ctime': '',
   'downtime': '',
   'dreq': '0',
   'dresp': '0',
   'econ': '',
   'ereq': '0',
   'eresp': '',
   'hanafail': '',
   'hrsp_1xx': '0',
   'hrsp_2xx': '3',
   'hrsp_3xx': '0',
   'hrsp_4xx': '0',
   'hrsp_5xx': '0',
   'hrsp_other': '0',
   'iid': '10',
   'last_agt': '',
   'last_chk': '',
   'lastchg': '',
   'lastsess': '',
   'lbtot': '',
   'pid': '4',
   'pxname': 'frontend1_proc34',
   'qcur': '',
   'qlimit': '',
   'qmax': '',
   'qtime': '',
   'rate': '0',
   'rate_lim': '100000',
   'rate_max': '1',
   'req_rate': '0',
   'req_rate_max': '1',
   'req_tot': '3',
   'rtime': '',
   'scur': '0',
   'sid': '0',
   'slim': '1000000',
   'smax': '1',
   'srv_abrt': '',
   'status': 'OPEN',
   'stot': '3',
   'svname': 'FRONTEND',
   'throttle': '',
   'tracked': '',
   'ttime': '',
   'type': '0',
   'weight': '',
   'wredis': '',
   'wretr': ''}),
 (3,
  {'': '',
   'act': '',
   'bck': '',
   'bin': '380',
   'bout': '6075',
   'check_code': '',
   'check_duration': '',
   'check_status': '',
   'chkdown': '',
   'chkfail': '',
   'cli_abrt': '',
   'comp_byp': '0',
   'comp_in': '0',
   'comp_out': '0',
   'comp_rsp': '0',
   'ctime': '',
   'downtime': '',
   'dreq': '0',
   'dresp': '0',
   'econ': '',
   'ereq': '0',
   'eresp': '',
   'hanafail': '',
   'hrsp_1xx': '0',
   'hrsp_2xx': '5',
   'hrsp_3xx': '0',
   'hrsp_4xx': '0',
   'hrsp_5xx': '0',
   'hrsp_other': '0',
   'iid': '10',
   'last_agt': '',
   'last_chk': '',
   'lastchg': '',
   'lastsess': '',
   'lbtot': '',
   'pid': '3',
   'pxname': 'frontend1_proc34',
   'qcur': '',
   'qlimit': '',
   'qmax': '',
   'qtime': '',
   'rate': '0',
   'rate_lim': '100000',
   'rate_max': '1',
   'req_rate': '0',
   'req_rate_max': '1',
   'req_tot': '5',
   'rtime': '',
   'scur': '0',
   'sid': '0',
   'slim': '1000000',
   'smax': '1',
   'srv_abrt': '',
   'status': 'OPEN',
   'stot': '5',
   'svname': 'FRONTEND',
   'throttle': '',
   'tracked': '',
   'ttime': '',
   'type': '0',
   'weight': '',
   'wredis': '',
   'wretr': ''})]

Pool operations

List members


In [14]:
pools = hap.pools()
for pool in pools:
    print("{:*^30}".format(pool.name))
    for member in pool.members():
        print("{:<30}".format(member.name))


*******backend2_proc34********
member1_bk2_proc34            
member2_bk2_proce34           
member_bkall                  
********backend_proc2*********
member1_proc2                 
member_bkall                  
member2_proc2                 
*******backend1_proc34********
member1_proc34                
member2_proc34                
member_bkall                  
********backend_proc1*********
member1_proc1                 
member_bkall                  
member2_proc1                 
***********haproxy************

Pool information


In [15]:
pools = hap.pools()
for pool in pools:
    print("Pool {} status {} requests {} referenced by processes {}".format(pool.name,
                                                                            pool.status,
                                                                            pool.requests,
                                                                            pool.process_nb))


Pool backend2_proc34 status UP requests 0 referenced by processes [4, 3]
Pool backend_proc2 status UP requests 0 referenced by processes [2]
Pool backend1_proc34 status UP requests 8 referenced by processes [4, 3]
Pool backend_proc1 status UP requests 3 referenced by processes [1]
Pool haproxy status UP requests 0 referenced by processes [4, 3, 2, 1]

Get requests for a certain pool


In [20]:
p1 = hap.pool('backend2_proc34')
print(p1.requests)


0

Get requests per process


In [18]:
pprint(p1.requests_per_process())


[(4, 0), (3, 0)]

Get all statistics per process


In [19]:
pprint(p1.stats_per_process())


[(4,
  {'': '',
   'act': '3',
   'bck': '0',
   'bin': '0',
   'bout': '0',
   'check_code': '',
   'check_duration': '',
   'check_status': '',
   'chkdown': '0',
   'chkfail': '',
   'cli_abrt': '0',
   'comp_byp': '0',
   'comp_in': '0',
   'comp_out': '0',
   'comp_rsp': '0',
   'ctime': '0',
   'downtime': '0',
   'dreq': '0',
   'dresp': '0',
   'econ': '0',
   'ereq': '',
   'eresp': '0',
   'hanafail': '',
   'hrsp_1xx': '0',
   'hrsp_2xx': '0',
   'hrsp_3xx': '0',
   'hrsp_4xx': '0',
   'hrsp_5xx': '0',
   'hrsp_other': '0',
   'iid': '13',
   'last_agt': '',
   'last_chk': '',
   'lastchg': '11602',
   'lastsess': '-1',
   'lbtot': '0',
   'pid': '4',
   'pxname': 'backend2_proc34',
   'qcur': '0',
   'qlimit': '',
   'qmax': '0',
   'qtime': '0',
   'rate': '0',
   'rate_lim': '',
   'rate_max': '0',
   'req_rate': '',
   'req_rate_max': '',
   'req_tot': '',
   'rtime': '0',
   'scur': '0',
   'sid': '0',
   'slim': '100000',
   'smax': '0',
   'srv_abrt': '0',
   'status': 'UP',
   'stot': '0',
   'svname': 'BACKEND',
   'throttle': '',
   'tracked': '',
   'ttime': '0',
   'type': '1',
   'weight': '202',
   'wredis': '0',
   'wretr': '0'}),
 (3,
  {'': '',
   'act': '3',
   'bck': '0',
   'bin': '0',
   'bout': '0',
   'check_code': '',
   'check_duration': '',
   'check_status': '',
   'chkdown': '0',
   'chkfail': '',
   'cli_abrt': '0',
   'comp_byp': '0',
   'comp_in': '0',
   'comp_out': '0',
   'comp_rsp': '0',
   'ctime': '0',
   'downtime': '0',
   'dreq': '0',
   'dresp': '0',
   'econ': '0',
   'ereq': '',
   'eresp': '0',
   'hanafail': '',
   'hrsp_1xx': '0',
   'hrsp_2xx': '0',
   'hrsp_3xx': '0',
   'hrsp_4xx': '0',
   'hrsp_5xx': '0',
   'hrsp_other': '0',
   'iid': '13',
   'last_agt': '',
   'last_chk': '',
   'lastchg': '11602',
   'lastsess': '-1',
   'lbtot': '0',
   'pid': '3',
   'pxname': 'backend2_proc34',
   'qcur': '0',
   'qlimit': '',
   'qmax': '0',
   'qtime': '0',
   'rate': '0',
   'rate_lim': '',
   'rate_max': '0',
   'req_rate': '',
   'req_rate_max': '',
   'req_tot': '',
   'rtime': '0',
   'scur': '0',
   'sid': '0',
   'slim': '100000',
   'smax': '0',
   'srv_abrt': '0',
   'status': 'UP',
   'stot': '0',
   'svname': 'BACKEND',
   'throttle': '',
   'tracked': '',
   'ttime': '0',
   'type': '1',
   'weight': '202',
   'wredis': '0',
   'wretr': '0'})]

Get members


In [21]:
members = p1.members()
for m in members:
    print("pool {}, member {}, status {}, requests {}, processes {}".format(m.poolname,
                                                                            m.name,
                                                                            m.status,
                                                                            m.requests,
                                                                            m.process_nb))


pool backend2_proc34, member member1_bk2_proc34, status no check, requests 0, processes [4, 3]
pool backend2_proc34, member member2_bk2_proce34, status UP, requests 0, processes [4, 3]
pool backend2_proc34, member member_bkall, status no check, requests 0, processes [4, 3]

Member operations


In [2]:
m1 = hap.member('member_bkall')
print("Found in {} pool(s)".format(len(m1)))
print(m1)


Found in 3 pool(s)
[<haproxyadmin.poolmember.PoolMember object at 0x7f63b40fef98>, <haproxyadmin.poolmember.PoolMember object at 0x7f63b40fcb70>, <haproxyadmin.poolmember.PoolMember object at 0x7f63b4100e10>]

In [3]:
m = m1[0]
print("requests {}, status {}, processes {}".format(m.requests, m.status, m.process_nb))
print("check code {}, check status {}, last status {}, last agent check {}".format(m.check_code,
                                                                                   m.check_status,
                                                                                   m.last_status,
                                                                                   m.last_agent_check))


requests 0, status no check, processes [4, 3]
check code , check status , last status , last agent check 

Change weight


In [18]:
print(m.weight)
m.setweight('20%')
print(m.weight)
m.setweight(200)
print(m.weight)


200
20
200

Shutdown all sessions


In [ ]:
print(m.status)
m.shutdown()

Change state


In [ ]:
for state in haproxy.VALID_STATES:
    print("state before {}".format(m.status))
    print("Change state to {}".format(state))
    m.setstate(state)
    print("state after {}".format(m.status))

Get metrics


In [21]:
for metric in haproxy.SERVER_METRICS:
    print("{}={}".format(metric, m.metric(metric)))


qcur=0
qmax=0
scur=0
smax=0
stot=0
bin=0
bout=0
dresp=0
econ=0
eresp=0
wretr=0
wredis=0
weight=200.0
act=1.0
bck=0.0
chkfail=0
chkdown=0
lastchg=226.0
downtime=0.0
qlimit=0.0
throttle=0.0
lbtot=0
rate=0
rate_max=0
check_duration=132.5
hrsp_1xx=0
hrsp_2xx=0
hrsp_3xx=0
hrsp_4xx=0
hrsp_5xx=0
hrsp_other=0
cli_abrt=0
srv_abrt=0
lastsess=-1.0
qtime=0.0
ctime=0.0
rtime=0.0
ttime=0.0

Get requests per process


In [19]:
pprint(m.requests_per_process())


[(4, 0), (3, 0)]

Get all statistics per process


In [20]:
pprint(m.stats_per_process())


[(4,
  {'': '',
   'act': '1',
   'bck': '0',
   'bin': '0',
   'bout': '0',
   'check_code': '200',
   'check_duration': '124',
   'check_status': 'L7OK',
   'chkdown': '0',
   'chkfail': '0',
   'cli_abrt': '0',
   'comp_byp': '',
   'comp_in': '',
   'comp_out': '',
   'comp_rsp': '',
   'ctime': '0',
   'downtime': '0',
   'dreq': '',
   'dresp': '0',
   'econ': '0',
   'ereq': '',
   'eresp': '0',
   'hanafail': '0',
   'hrsp_1xx': '0',
   'hrsp_2xx': '0',
   'hrsp_3xx': '0',
   'hrsp_4xx': '0',
   'hrsp_5xx': '0',
   'hrsp_other': '0',
   'iid': '13',
   'last_agt': '',
   'last_chk': 'OK',
   'lastchg': '222',
   'lastsess': '-1',
   'lbtot': '0',
   'pid': '4',
   'pxname': 'backend2_proc34',
   'qcur': '0',
   'qlimit': '',
   'qmax': '0',
   'qtime': '0',
   'rate': '0',
   'rate_lim': '',
   'rate_max': '0',
   'req_rate': '',
   'req_rate_max': '',
   'req_tot': '',
   'rtime': '0',
   'scur': '0',
   'sid': '2',
   'slim': '',
   'smax': '0',
   'srv_abrt': '0',
   'status': 'UP',
   'stot': '0',
   'svname': 'member2_bk2_proce34',
   'throttle': '',
   'tracked': '',
   'ttime': '0',
   'type': '2',
   'weight': '200',
   'wredis': '0',
   'wretr': '0'}),
 (3,
  {'': '',
   'act': '1',
   'bck': '0',
   'bin': '0',
   'bout': '0',
   'check_code': '200',
   'check_duration': '126',
   'check_status': 'L7OK',
   'chkdown': '0',
   'chkfail': '0',
   'cli_abrt': '0',
   'comp_byp': '',
   'comp_in': '',
   'comp_out': '',
   'comp_rsp': '',
   'ctime': '0',
   'downtime': '0',
   'dreq': '',
   'dresp': '0',
   'econ': '0',
   'ereq': '',
   'eresp': '0',
   'hanafail': '0',
   'hrsp_1xx': '0',
   'hrsp_2xx': '0',
   'hrsp_3xx': '0',
   'hrsp_4xx': '0',
   'hrsp_5xx': '0',
   'hrsp_other': '0',
   'iid': '13',
   'last_agt': '',
   'last_chk': 'OK',
   'lastchg': '222',
   'lastsess': '-1',
   'lbtot': '0',
   'pid': '3',
   'pxname': 'backend2_proc34',
   'qcur': '0',
   'qlimit': '',
   'qmax': '0',
   'qtime': '0',
   'rate': '0',
   'rate_lim': '',
   'rate_max': '0',
   'req_rate': '',
   'req_rate_max': '',
   'req_tot': '',
   'rtime': '0',
   'scur': '0',
   'sid': '2',
   'slim': '',
   'smax': '0',
   'srv_abrt': '0',
   'status': 'UP',
   'stot': '0',
   'svname': 'member2_bk2_proce34',
   'throttle': '',
   'tracked': '',
   'ttime': '0',
   'type': '2',
   'weight': '200',
   'wredis': '0',
   'wretr': '0'})]

Handle exceptions during operations


In [22]:
frontend = hap.frontend('frontend2_proc34')
print(frontend.name)
print(frontend.maxconn)
try:
    print(frontend.status)
except exceptions.IncosistentData as error:
    print(error, error.results)

print('disabling')
if frontend.disable():
    print("ok")
print('disalbing2')
try:
    d = frontend.disable()
except exceptions.MultipleCommandResults as error:
    print(error, error.results, 'die')
except exceptions.CommandFailed as error:
    print(error)


try:
    print(frontend.status)
except exceptions.IncosistentData as error:
    print(error, error.results)


frontend2_proc34
2000000
OPEN
disabling
ok
disalbing2
Frontend is already disabled.
STOP

In [23]:
frontend = hap.frontend('frontend2_proc34')
print(frontend.name)
print(frontend.maxconn)
try:
    print(frontend.status)
except exceptions.IncosistentData as error:
    print(error, error.results)

print('disabling')
if frontend.disable(die=False):
    print("disabled")
else:
    print("oops")


try:
    print(frontend.status)
except exceptions.IncosistentData as error:
    print(error, error.results)


frontend2_proc34
2000000
STOP
disabling
oops
STOP

In [ ]: