~james-page/charms/trusty/swift-proxy/kilo

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/contrib/openstack/context.py

  • Committer: Liam Young
  • Date: 2015-01-26 09:45:43 UTC
  • Revision ID: liam.young@canonical.com-20150126094543-r9gy9y3tokm27otx
[gnuoy,trivial] Pre-release charmhelper sync

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2014-2015 Canonical Limited.
 
2
#
 
3
# This file is part of charm-helpers.
 
4
#
 
5
# charm-helpers is free software: you can redistribute it and/or modify
 
6
# it under the terms of the GNU Lesser General Public License version 3 as
 
7
# published by the Free Software Foundation.
 
8
#
 
9
# charm-helpers is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU Lesser General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU Lesser General Public License
 
15
# along with charm-helpers.  If not, see <http://www.gnu.org/licenses/>.
 
16
 
1
17
import json
2
18
import os
3
19
import time
468
484
                            _unit = unit.replace('/', '-')
469
485
                            cluster_hosts[laddr]['backends'][_unit] = _laddr
470
486
 
471
 
        # NOTE(jamespage) no split configurations found, just use
472
 
        # private addresses
473
 
        if not cluster_hosts:
474
 
            netmask = get_netmask_for_address(addr)
475
 
            cluster_hosts[addr] = {'network': "{}/{}".format(addr, netmask),
476
 
                                   'backends': {l_unit: addr}}
477
 
            for rid in relation_ids('cluster'):
478
 
                for unit in related_units(rid):
479
 
                    _laddr = relation_get('private-address',
480
 
                                          rid=rid, unit=unit)
481
 
                    if _laddr:
482
 
                        _unit = unit.replace('/', '-')
483
 
                        cluster_hosts[addr]['backends'][_unit] = _laddr
 
487
        # NOTE(jamespage) add backend based on private address - this
 
488
        # with either be the only backend or the fallback if no acls
 
489
        # match in the frontend
 
490
        cluster_hosts[addr] = {}
 
491
        netmask = get_netmask_for_address(addr)
 
492
        cluster_hosts[addr] = {'network': "{}/{}".format(addr, netmask),
 
493
                               'backends': {l_unit: addr}}
 
494
        for rid in relation_ids('cluster'):
 
495
            for unit in related_units(rid):
 
496
                _laddr = relation_get('private-address',
 
497
                                      rid=rid, unit=unit)
 
498
                if _laddr:
 
499
                    _unit = unit.replace('/', '-')
 
500
                    cluster_hosts[addr]['backends'][_unit] = _laddr
484
501
 
485
 
        ctxt = {'frontends': cluster_hosts}
 
502
        ctxt = {
 
503
            'frontends': cluster_hosts,
 
504
            'default_backend': addr
 
505
        }
486
506
 
487
507
        if config('haproxy-server-timeout'):
488
508
            ctxt['haproxy_server_timeout'] = config('haproxy-server-timeout')