~heut2008/charms/trusty/keystone/ldap-support-backend

« back to all changes in this revision

Viewing changes to hooks/lib/haproxy_utils.py

  • Committer: James Page
  • Date: 2014-04-16 08:20:08 UTC
  • mfrom: (52.2.30 keystone)
  • Revision ID: james.page@canonical.com-20140416082008-34w0nyak0y571tfp
[james-page,ivoks,hazmat,yolanda.robla,r=james-page,t=*]

Redux to used charm helpers
Support for Icehouse on 12.04 and 14.04
Support for Active/Active and SSL RabbitMQ
Support for SSL MySQL
Support for SSL endpoints
Support for PostgreSQL

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# Copyright 2012 Canonical Ltd.
3
 
#
4
 
# This file is sourced from lp:openstack-charm-helpers
5
 
#
6
 
# Authors:
7
 
#  James Page <james.page@ubuntu.com>
8
 
#  Adam Gandelman <adamg@ubuntu.com>
9
 
#
10
 
 
11
 
from lib.utils import (
12
 
    relation_ids,
13
 
    relation_list,
14
 
    relation_get,
15
 
    unit_get,
16
 
    reload,
17
 
    render_template
18
 
    )
19
 
import os
20
 
 
21
 
HAPROXY_CONF = '/etc/haproxy/haproxy.cfg'
22
 
HAPROXY_DEFAULT = '/etc/default/haproxy'
23
 
 
24
 
 
25
 
def configure_haproxy(service_ports):
26
 
    '''
27
 
    Configure HAProxy based on the current peers in the service
28
 
    cluster using the provided port map:
29
 
 
30
 
        "swift": [ 8080, 8070 ]
31
 
 
32
 
    HAproxy will also be reloaded/started if required
33
 
 
34
 
    service_ports: dict: dict of lists of [ frontend, backend ]
35
 
    '''
36
 
    cluster_hosts = {}
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',
43
 
                             rid=r_id,
44
 
                             unit=unit)
45
 
    context = {
46
 
        'units': cluster_hosts,
47
 
        'service_ports': service_ports
48
 
        }
49
 
    with open(HAPROXY_CONF, 'w') as f:
50
 
        f.write(render_template(os.path.basename(HAPROXY_CONF),
51
 
                                context))
52
 
    with open(HAPROXY_DEFAULT, 'w') as f:
53
 
        f.write('ENABLED=1')
54
 
 
55
 
    reload('haproxy')