2
# Copyright 2012 Canonical Ltd.
4
# This file is sourced from lp:openstack-charm-helpers
7
# James Page <james.page@ubuntu.com>
8
# Adam Gandelman <adamg@ubuntu.com>
11
from lib.utils import (
20
HAPROXY_CONF = '/etc/haproxy/haproxy.cfg'
21
HAPROXY_DEFAULT = '/etc/default/haproxy'
24
def configure_haproxy(service_ports):
26
Configure HAProxy based on the current peers in the service
27
cluster using the provided port map:
29
"swift": [ 8080, 8070 ]
31
HAproxy will also be reloaded/started if required
33
service_ports: dict: dict of lists of [ frontend, backend ]
36
cluster_hosts[os.getenv('JUJU_UNIT_NAME').replace('/', '-')] = \
37
unit_get('private-address')
38
for r_id in relation_ids('cluster'):
39
for unit in relation_list(r_id):
40
cluster_hosts[unit.replace('/', '-')] = \
41
relation_get(attribute='private-address',
45
'units': cluster_hosts,
46
'service_ports': service_ports}
47
with open(HAPROXY_CONF, 'w') as f:
48
f.write(render_template(os.path.basename(HAPROXY_CONF),
50
with open(HAPROXY_DEFAULT, 'w') as f: