~james-page/charms/trusty/cinder/https-multi-network

« back to all changes in this revision

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

  • Committer: james.page at ubuntu
  • Date: 2014-10-01 22:07:44 UTC
  • mfrom: (45.1.1 cinder)
  • Revision ID: james.page@ubuntu.com-20141001220744-v35hu9iblt15phc7
Rebase and resync

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
from charmhelpers.contrib.network.ip import (
53
53
    get_address_in_network,
54
54
    get_ipv6_addr,
55
 
    is_address_in_network,
56
 
    get_netmask_for_address
 
55
    get_netmask_for_address,
 
56
    format_ipv6_addr,
 
57
    is_address_in_network
57
58
)
58
59
 
59
60
CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt'
175
176
        for rid in relation_ids('shared-db'):
176
177
            for unit in related_units(rid):
177
178
                rdata = relation_get(rid=rid, unit=unit)
 
179
                host = rdata.get('db_host')
 
180
                host = format_ipv6_addr(host) or host
178
181
                ctxt = {
179
 
                    'database_host': rdata.get('db_host'),
 
182
                    'database_host': host,
180
183
                    'database': self.database,
181
184
                    'database_user': self.user,
182
185
                    'database_password': rdata.get(password_setting),
252
255
        for rid in relation_ids('identity-service'):
253
256
            for unit in related_units(rid):
254
257
                rdata = relation_get(rid=rid, unit=unit)
 
258
                serv_host = rdata.get('service_host')
 
259
                serv_host = format_ipv6_addr(serv_host) or serv_host
 
260
                auth_host = rdata.get('auth_host')
 
261
                auth_host = format_ipv6_addr(auth_host) or auth_host
 
262
 
255
263
                ctxt = {
256
264
                    'service_port': rdata.get('service_port'),
257
 
                    'service_host': rdata.get('service_host'),
258
 
                    'auth_host': rdata.get('auth_host'),
 
265
                    'service_host': serv_host,
 
266
                    'auth_host': auth_host,
259
267
                    'auth_port': rdata.get('auth_port'),
260
268
                    'admin_tenant_name': rdata.get('service_tenant'),
261
269
                    'admin_user': rdata.get('service_username'),
304
312
            for unit in related_units(rid):
305
313
                if relation_get('clustered', rid=rid, unit=unit):
306
314
                    ctxt['clustered'] = True
307
 
                    ctxt['rabbitmq_host'] = relation_get('vip', rid=rid,
308
 
                                                         unit=unit)
 
315
                    vip = relation_get('vip', rid=rid, unit=unit)
 
316
                    vip = format_ipv6_addr(vip) or vip
 
317
                    ctxt['rabbitmq_host'] = vip
309
318
                else:
310
 
                    ctxt['rabbitmq_host'] = relation_get('private-address',
311
 
                                                         rid=rid, unit=unit)
 
319
                    host = relation_get('private-address', rid=rid, unit=unit)
 
320
                    host = format_ipv6_addr(host) or host
 
321
                    ctxt['rabbitmq_host'] = host
312
322
                ctxt.update({
313
323
                    'rabbitmq_user': username,
314
324
                    'rabbitmq_password': relation_get('password', rid=rid,
347
357
                    and len(related_units(rid)) > 1:
348
358
                rabbitmq_hosts = []
349
359
                for unit in related_units(rid):
350
 
                    rabbitmq_hosts.append(relation_get('private-address',
351
 
                                                       rid=rid, unit=unit))
 
360
                    host = relation_get('private-address', rid=rid, unit=unit)
 
361
                    host = format_ipv6_addr(host) or host
 
362
                    rabbitmq_hosts.append(host)
352
363
                ctxt['rabbitmq_hosts'] = ','.join(rabbitmq_hosts)
353
364
        if not context_complete(ctxt):
354
365
            return {}
377
388
                ceph_addr = \
378
389
                    relation_get('ceph-public-address', rid=rid, unit=unit) or \
379
390
                    relation_get('private-address', rid=rid, unit=unit)
 
391
                ceph_addr = format_ipv6_addr(ceph_addr) or ceph_addr
380
392
                mon_hosts.append(ceph_addr)
381
393
 
382
394
        ctxt = {
413
425
            return {}
414
426
 
415
427
        l_unit = local_unit().replace('/', '-')
 
428
 
416
429
        if config('prefer-ipv6'):
417
 
            addr = get_ipv6_addr()
 
430
            addr = get_ipv6_addr(exc_list=[config('vip')])[0]
418
431
        else:
419
432
            addr = unit_get('private-address')
420
433
 
443
456
 
444
457
        # NOTE(jamespage) no split configurations found, just use
445
458
        # private addresses
446
 
        if len(cluster_hosts) < 1:
 
459
        if not cluster_hosts:
447
460
            cluster_hosts[addr] = {}
448
461
            cluster_hosts[addr]['network'] = "{}/{}".format(
449
462
                addr,
463
476
            'frontends': cluster_hosts,
464
477
        }
465
478
 
 
479
        if config('haproxy-server-timeout'):
 
480
            ctxt['haproxy_server_timeout'] = config('haproxy-server-timeout')
 
481
        if config('haproxy-client-timeout'):
 
482
            ctxt['haproxy_client_timeout'] = config('haproxy-client-timeout')
 
483
 
466
484
        if config('prefer-ipv6'):
467
485
            ctxt['local_host'] = 'ip6-localhost'
468
486
            ctxt['haproxy_host'] = '::'
870
888
            'use_syslog': config('use-syslog')
871
889
        }
872
890
        return ctxt
 
891
 
 
892
 
 
893
class BindHostContext(OSContextGenerator):
 
894
 
 
895
    def __call__(self):
 
896
        if config('prefer-ipv6'):
 
897
            return {
 
898
                'bind_host': '::'
 
899
            }
 
900
        else:
 
901
            return {
 
902
                'bind_host': '0.0.0.0'
 
903
            }