~openstack-charmers-archive/charms/trusty/neutron-api-odl/next

« back to all changes in this revision

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

  • Committer: David Ames
  • Date: 2016-02-12 19:51:22 UTC
  • mfrom: (11.1.1 neutron-api-odl)
  • Revision ID: david.ames@canonical.com-20160212195122-3r9x8wdigj8e2m3j
[narindergupta, r=thedac] Charm-helpers sync to fix liberty version string handling

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
    get_nic_hwaddr,
58
58
    mkdir,
59
59
    write_file,
 
60
    pwgen,
60
61
)
61
62
from charmhelpers.contrib.hahelpers.cluster import (
62
63
    determine_apache_port,
87
88
    is_bridge_member,
88
89
)
89
90
from charmhelpers.contrib.openstack.utils import get_host_ip
 
91
from charmhelpers.core.unitdata import kv
 
92
 
 
93
try:
 
94
    import psutil
 
95
except ImportError:
 
96
    apt_install('python-psutil', fatal=True)
 
97
    import psutil
 
98
 
90
99
CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt'
91
100
ADDRESS_TYPES = ['admin', 'internal', 'public']
92
101
 
401
410
                auth_host = format_ipv6_addr(auth_host) or auth_host
402
411
                svc_protocol = rdata.get('service_protocol') or 'http'
403
412
                auth_protocol = rdata.get('auth_protocol') or 'http'
 
413
                api_version = rdata.get('api_version') or '2.0'
404
414
                ctxt.update({'service_port': rdata.get('service_port'),
405
415
                             'service_host': serv_host,
406
416
                             'auth_host': auth_host,
409
419
                             'admin_user': rdata.get('service_username'),
410
420
                             'admin_password': rdata.get('service_password'),
411
421
                             'service_protocol': svc_protocol,
412
 
                             'auth_protocol': auth_protocol})
 
422
                             'auth_protocol': auth_protocol,
 
423
                             'api_version': api_version})
413
424
 
414
425
                if self.context_complete(ctxt):
415
426
                    # NOTE(jamespage) this is required for >= icehouse
626
637
        if config('haproxy-client-timeout'):
627
638
            ctxt['haproxy_client_timeout'] = config('haproxy-client-timeout')
628
639
 
 
640
        if config('haproxy-queue-timeout'):
 
641
            ctxt['haproxy_queue_timeout'] = config('haproxy-queue-timeout')
 
642
 
 
643
        if config('haproxy-connect-timeout'):
 
644
            ctxt['haproxy_connect_timeout'] = config('haproxy-connect-timeout')
 
645
 
629
646
        if config('prefer-ipv6'):
630
647
            ctxt['ipv6'] = True
631
648
            ctxt['local_host'] = 'ip6-localhost'
632
649
            ctxt['haproxy_host'] = '::'
633
 
            ctxt['stat_port'] = ':::8888'
634
650
        else:
635
651
            ctxt['local_host'] = '127.0.0.1'
636
652
            ctxt['haproxy_host'] = '0.0.0.0'
637
 
            ctxt['stat_port'] = ':8888'
 
653
 
 
654
        ctxt['stat_port'] = '8888'
 
655
 
 
656
        db = kv()
 
657
        ctxt['stat_password'] = db.get('stat-password')
 
658
        if not ctxt['stat_password']:
 
659
            ctxt['stat_password'] = db.set('stat-password',
 
660
                                           pwgen(32))
 
661
            db.flush()
638
662
 
639
663
        for frontend in cluster_hosts:
640
664
            if (len(cluster_hosts[frontend]['backends']) > 1 or
1088
1112
                config_flags_parser(config_flags)}
1089
1113
 
1090
1114
 
 
1115
class LibvirtConfigFlagsContext(OSContextGenerator):
 
1116
    """
 
1117
    This context provides support for extending
 
1118
    the libvirt section through user-defined flags.
 
1119
    """
 
1120
    def __call__(self):
 
1121
        ctxt = {}
 
1122
        libvirt_flags = config('libvirt-flags')
 
1123
        if libvirt_flags:
 
1124
            ctxt['libvirt_flags'] = config_flags_parser(
 
1125
                libvirt_flags)
 
1126
        return ctxt
 
1127
 
 
1128
 
1091
1129
class SubordinateConfigContext(OSContextGenerator):
1092
1130
 
1093
1131
    """
1228
1266
 
1229
1267
    @property
1230
1268
    def num_cpus(self):
1231
 
        try:
1232
 
            from psutil import NUM_CPUS
1233
 
        except ImportError:
1234
 
            apt_install('python-psutil', fatal=True)
1235
 
            from psutil import NUM_CPUS
1236
 
 
1237
 
        return NUM_CPUS
 
1269
        # NOTE: use cpu_count if present (16.04 support)
 
1270
        if hasattr(psutil, 'cpu_count'):
 
1271
            return psutil.cpu_count()
 
1272
        else:
 
1273
            return psutil.NUM_CPUS
1238
1274
 
1239
1275
    def __call__(self):
1240
1276
        multiplier = config('worker-multiplier') or 0
1437
1473
                    rdata.get('service_protocol') or 'http',
1438
1474
                    'auth_protocol':
1439
1475
                    rdata.get('auth_protocol') or 'http',
 
1476
                    'api_version':
 
1477
                    rdata.get('api_version') or '2.0',
1440
1478
                }
1441
1479
                if self.context_complete(ctxt):
1442
1480
                    return ctxt