~heut2008/charms/trusty/glance/sync-charmhelpers-haproxy

« back to all changes in this revision

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

  • Committer: Liam Young
  • Date: 2014-09-10 17:15:07 UTC
  • Revision ID: liam.young@canonical.com-20140910171507-oe369tyhc8otrwex
Add support for notifications with zmq

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
    relation_get,
22
22
    relation_ids,
23
23
    related_units,
 
24
    is_relation_made,
24
25
    relation_set,
25
26
    unit_get,
26
27
    unit_private_ip,
49
50
    get_ipv6_addr,
50
51
)
51
52
 
 
53
from charmhelpers.contrib.openstack.utils import (
 
54
    get_matchmaker_map,
 
55
)
52
56
CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt'
53
57
 
54
58
 
787
791
            'use_syslog': config('use-syslog')
788
792
        }
789
793
        return ctxt
 
794
 
 
795
 
 
796
class ZeroMQContext(OSContextGenerator):
 
797
    interfaces = ['zeromq-configuration']
 
798
 
 
799
    def __call__(self):
 
800
        ctxt = {}
 
801
        if is_relation_made('zeromq-configuration', 'host'):
 
802
            for rid in relation_ids('zeromq-configuration'):
 
803
                    for unit in related_units(rid):
 
804
                        ctxt['zmq_nonce'] = relation_get('nonce', unit, rid)
 
805
                        ctxt['zmq_host'] = relation_get('host', unit, rid)
 
806
        return ctxt
 
807
 
 
808
class NotificationDriverContext(OSContextGenerator):
 
809
 
 
810
    def __init__(self, zmq_relation='zeromq-configuration', amqp_relation='amqp'):
 
811
        """
 
812
        :param zmq_relation   : Name of Zeromq relation to check
 
813
        """
 
814
        self.zmq_relation = zmq_relation
 
815
        self.amqp_relation = amqp_relation
 
816
 
 
817
    def __call__(self):
 
818
        ctxt = {
 
819
            'notifications': "False",
 
820
        }
 
821
        if is_relation_made(self.zmq_relation):
 
822
            matchmaker_data = get_matchmaker_map()
 
823
            if 'notifications-info' in matchmaker_data:
 
824
                ctxt['notifications'] = "True"
 
825
        elif is_relation_made(self.amqp_relation):
 
826
            ctxt['notifications'] = "True"
 
827
        return ctxt