~openstack-charmers-next/charms/wily/heat/trunk

« back to all changes in this revision

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

  • Committer: Edward Hope-Morley
  • Date: 2016-02-18 13:47:28 UTC
  • mfrom: (68.1.9 trunk)
  • Revision ID: edward.hope-morley@canonical.com-20160218134728-8u8l51lv7y72iy2c
[hopem,r=jamespage]
 
Sync charmhelpers to get support for supplying a Ascii Armor PGP key to
openstack-origin (currently only supports Radix64)
Closes-Bug: 1518975

Show diffs side-by-side

added added

removed removed

Lines of Context:
90
90
from charmhelpers.contrib.openstack.utils import get_host_ip
91
91
from charmhelpers.core.unitdata import kv
92
92
 
 
93
try:
 
94
    import psutil
 
95
except ImportError:
 
96
    apt_install('python-psutil', fatal=True)
 
97
    import psutil
 
98
 
93
99
CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt'
94
100
ADDRESS_TYPES = ['admin', 'internal', 'public']
95
101
 
404
410
                auth_host = format_ipv6_addr(auth_host) or auth_host
405
411
                svc_protocol = rdata.get('service_protocol') or 'http'
406
412
                auth_protocol = rdata.get('auth_protocol') or 'http'
 
413
                api_version = rdata.get('api_version') or '2.0'
407
414
                ctxt.update({'service_port': rdata.get('service_port'),
408
415
                             'service_host': serv_host,
409
416
                             'auth_host': auth_host,
412
419
                             'admin_user': rdata.get('service_username'),
413
420
                             'admin_password': rdata.get('service_password'),
414
421
                             'service_protocol': svc_protocol,
415
 
                             'auth_protocol': auth_protocol})
 
422
                             'auth_protocol': auth_protocol,
 
423
                             'api_version': api_version})
416
424
 
417
425
                if self.context_complete(ctxt):
418
426
                    # NOTE(jamespage) this is required for >= icehouse
1258
1266
 
1259
1267
    @property
1260
1268
    def num_cpus(self):
1261
 
        try:
1262
 
            from psutil import NUM_CPUS
1263
 
        except ImportError:
1264
 
            apt_install('python-psutil', fatal=True)
1265
 
            from psutil import NUM_CPUS
1266
 
 
1267
 
        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
1268
1274
 
1269
1275
    def __call__(self):
1270
1276
        multiplier = config('worker-multiplier') or 0
1467
1473
                    rdata.get('service_protocol') or 'http',
1468
1474
                    'auth_protocol':
1469
1475
                    rdata.get('auth_protocol') or 'http',
 
1476
                    'api_version':
 
1477
                    rdata.get('api_version') or '2.0',
1470
1478
                }
1471
1479
                if self.context_complete(ctxt):
1472
1480
                    return ctxt