~1chb1n/charms/trusty/nova-cloud-controller/15.10-stable-flip-tests-helper-syncs

« back to all changes in this revision

Viewing changes to hooks/nova_cc_context.py

  • Committer: james.page at ubuntu
  • Date: 2015-08-10 16:36:50 UTC
  • Revision ID: james.page@ubuntu.com-20150810163650-bpjo4l0dru4txcji
Tags: 15.07
[gnuoy] 15.07 Charm release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import os
2
2
 
 
3
from base64 import b64decode
3
4
from charmhelpers.core.hookenv import (
4
5
    config,
5
6
    relation_ids,
6
7
    relation_set,
7
8
    log,
 
9
    DEBUG,
8
10
    ERROR,
9
11
    related_units,
10
12
    relations_for_id,
11
13
    relation_get,
 
14
    unit_get,
12
15
)
13
16
from charmhelpers.fetch import (
14
17
    apt_install,
23
26
    determine_apache_port,
24
27
    determine_api_port,
25
28
    https,
 
29
    is_clustered,
26
30
)
27
31
from charmhelpers.contrib.network.ip import (
28
32
    format_ipv6_addr,
30
34
from charmhelpers.contrib.openstack.ip import (
31
35
    resolve_address,
32
36
    INTERNAL,
 
37
    PUBLIC,
33
38
)
34
39
 
35
40
 
350
355
                ctxt['ssl_key'] = key
351
356
 
352
357
        return ctxt
 
358
 
 
359
 
 
360
class ConsoleSSLContext(context.OSContextGenerator):
 
361
    interfaces = []
 
362
 
 
363
    def __call__(self):
 
364
        ctxt = {}
 
365
        from nova_cc_utils import console_attributes
 
366
 
 
367
        if (config('console-ssl-cert') and
 
368
            config('console-ssl-key') and
 
369
                config('console-access-protocol')):
 
370
            ssl_dir = '/etc/nova/ssl/'
 
371
            if not os.path.exists(ssl_dir):
 
372
                log('Creating %s.' % ssl_dir, level=DEBUG)
 
373
                os.mkdir(ssl_dir)
 
374
 
 
375
            cert_path = os.path.join(ssl_dir, 'nova_cert.pem')
 
376
            decode_ssl_cert = b64decode(config('console-ssl-cert'))
 
377
 
 
378
            key_path = os.path.join(ssl_dir, 'nova_key.pem')
 
379
            decode_ssl_key = b64decode(config('console-ssl-key'))
 
380
 
 
381
            with open(cert_path, 'w') as fh:
 
382
                fh.write(decode_ssl_cert)
 
383
            with open(key_path, 'w') as fh:
 
384
                fh.write(decode_ssl_key)
 
385
 
 
386
            ctxt['ssl_only'] = True
 
387
            ctxt['ssl_cert'] = cert_path
 
388
            ctxt['ssl_key'] = key_path
 
389
 
 
390
            if is_clustered():
 
391
                ip_addr = resolve_address(endpoint_type=PUBLIC)
 
392
            else:
 
393
                ip_addr = unit_get('private-address')
 
394
 
 
395
            ip_addr = format_ipv6_addr(ip_addr) or ip_addr
 
396
 
 
397
            _proto = config('console-access-protocol')
 
398
            url = "https://%s:%s%s" % (
 
399
                ip_addr,
 
400
                console_attributes('proxy-port', proto=_proto),
 
401
                console_attributes('proxy-page', proto=_proto))
 
402
 
 
403
            if _proto == 'novnc':
 
404
                ctxt['novncproxy_base_url'] = url
 
405
            elif _proto == 'spice':
 
406
                ctxt['html5proxy_base_url'] = url
 
407
 
 
408
        return ctxt