~alai/charms/trusty/nova-compute/contrail

« back to all changes in this revision

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

  • Committer: Robert Ayres
  • Date: 2014-09-12 19:02:18 UTC
  • Revision ID: robert.ayres@canonical.com-20140912190218-b99nuzqhi0l936iz
Add contrail plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
    neutron_plugin_attribute,
45
45
)
46
46
 
47
 
from charmhelpers.contrib.network.ip import (
48
 
    get_address_in_network,
49
 
    get_ipv6_addr,
50
 
)
 
47
from charmhelpers.contrib.network.ip import get_address_in_network
51
48
 
52
49
CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt'
53
50
 
404
401
 
405
402
        cluster_hosts = {}
406
403
        l_unit = local_unit().replace('/', '-')
407
 
        if config('prefer-ipv6'):
408
 
            addr = get_ipv6_addr()
409
 
        else:
410
 
            addr = unit_get('private-address')
411
 
        cluster_hosts[l_unit] = get_address_in_network(config('os-internal-network'),
412
 
                                                       addr)
 
404
        cluster_hosts[l_unit] = \
 
405
            get_address_in_network(config('os-internal-network'),
 
406
                                   unit_get('private-address'))
413
407
 
414
408
        for rid in relation_ids('cluster'):
415
409
            for unit in related_units(rid):
420
414
        ctxt = {
421
415
            'units': cluster_hosts,
422
416
        }
423
 
 
424
 
        if config('prefer-ipv6'):
425
 
            ctxt['local_host'] = 'ip6-localhost'
426
 
            ctxt['haproxy_host'] = '::'
427
 
            ctxt['stat_port'] = ':::8888'
428
 
        else:
429
 
            ctxt['local_host'] = '127.0.0.1'
430
 
            ctxt['haproxy_host'] = '0.0.0.0'
431
 
            ctxt['stat_port'] = ':8888'
432
 
 
433
417
        if len(cluster_hosts.keys()) > 1:
434
418
            # Enable haproxy when we have enough peers.
435
419
            log('Ensuring haproxy enabled in /etc/default/haproxy.')
612
596
 
613
597
        return n1kv_ctxt
614
598
 
 
599
    def contrail_ctxt(self):
 
600
        driver = neutron_plugin_attribute(self.plugin, 'driver',
 
601
                                          self.network_manager)
 
602
        contrail_ctxt = {
 
603
            'core_plugin': driver,
 
604
            'api_extensions_path': '/usr/lib/python2.7/dist-packages/neutron_plugin_contrail/extensions'
 
605
        }
 
606
 
 
607
        return contrail_ctxt
 
608
 
615
609
    def neutron_ctxt(self):
616
610
        if https():
617
611
            proto = 'https'
645
639
            ctxt.update(self.nvp_ctxt())
646
640
        elif self.plugin == 'n1kv':
647
641
            ctxt.update(self.n1kv_ctxt())
 
642
        elif self.plugin == 'contrail':
 
643
            ctxt.update(self.contrail_ctxt())
648
644
 
649
645
        alchemy_flags = config('neutron-alchemy-flags')
650
646
        if alchemy_flags:
769
765
        return ctxt
770
766
 
771
767
 
772
 
class LogLevelContext(OSContextGenerator):
773
 
 
774
 
    def __call__(self):
775
 
        ctxt = {}
776
 
        ctxt['debug'] = \
777
 
            False if config('debug') is None else config('debug')
778
 
        ctxt['verbose'] = \
779
 
            False if config('verbose') is None else config('verbose')
780
 
        return ctxt
781
 
 
782
 
 
783
768
class SyslogContext(OSContextGenerator):
784
769
 
785
770
    def __call__(self):
787
772
            'use_syslog': config('use-syslog')
788
773
        }
789
774
        return ctxt
 
775
 
 
776
class ContrailApiContext(OSContextGenerator):
 
777
 
 
778
    def __call__(self):
 
779
        ctxs = [ { 'api_server': relation_get('private-address', unit, rid) }
 
780
                 for rid in relation_ids('contrail-api')
 
781
                 for unit in related_units(rid) ]
 
782
        return ctxs[0] if ctxs else {}