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 (
21
HAPROXY_CONF = '/etc/haproxy/haproxy.cfg'
22
HAPROXY_DEFAULT = '/etc/default/haproxy'
25
def configure_haproxy(service_ports):
27
Configure HAProxy based on the current peers in the service
28
cluster using the provided port map:
30
"swift": [ 8080, 8070 ]
32
HAproxy will also be reloaded/started if required
34
service_ports: dict: dict of lists of [ frontend, backend ]
37
cluster_hosts[os.getenv('JUJU_UNIT_NAME').replace('/', '-')] = \
38
unit_get('private-address')
39
for r_id in relation_ids('cluster'):
40
for unit in relation_list(r_id):
41
cluster_hosts[unit.replace('/', '-')] = \
42
relation_get(attribute='private-address',
46
'units': cluster_hosts,
47
'service_ports': service_ports
49
with open(HAPROXY_CONF, 'w') as f:
50
f.write(render_template(os.path.basename(HAPROXY_CONF),
52
with open(HAPROXY_DEFAULT, 'w') as f: