-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure.py
More file actions
40 lines (31 loc) · 898 Bytes
/
configure.py
File metadata and controls
40 lines (31 loc) · 898 Bytes
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Convert a ECM Balancer hash to haproxy configuration file
# This file is just for testing purposes
from ecm_haproxy import ECMHAProxy
HAPROXY_CONFIG = '/etc/haproxy/haproxy_build.cfg'
ECM_TEST = {
'listeners': [
'HTTP::80::HTTP::80', 'TCP::443::TCP::443'
],
'backends': [
{'uuid': '62.97.115.10'}, {'uuid2': '62.97.115.12'}
],
'health': {
'timeout': 5,
'threshold': 2,
'interval': 10,
'check': 'HTTP::80::/check.php'
}
}
ha_config = ECMHAProxy(ECM_TEST)
# Show configuration
ha_config.show(as_json=True)
# Write new configuraion if is valid
if ha_config.valid():
ha_config.write(HAPROXY_CONFIG)
else:
raise Exception('Invalid configuration')
# Write ECM json hash from final configuration file
config = ha_config.read(HAPROXY_CONFIG, as_json=True)
print config