~johnsca/charm-helpers/hook-context

« back to all changes in this revision

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

  • Committer: Liam Young
  • Date: 2014-10-20 09:39:31 UTC
  • mfrom: (202.3.11 charm-helpers-0mq)
  • Revision ID: liam.young@canonical.com-20141020093931-m8eiogi1u36zxsuv
[gnuoy,r=jamespage] Add 0mq support to charmhelpers/contrib/openstack

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
from charmhelpers.core.hookenv import (
17
17
    config,
 
18
    is_relation_made,
18
19
    local_unit,
19
20
    log,
20
21
    relation_get,
57
58
    is_address_in_network
58
59
)
59
60
 
60
 
from charmhelpers.contrib.openstack.utils import get_host_ip
61
 
 
 
61
from charmhelpers.contrib.openstack.utils import (
 
62
    get_host_ip,
 
63
    get_matchmaker_map,
 
64
)
62
65
CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt'
63
66
 
64
67
 
922
925
            "workers": self.num_cpus * multiplier
923
926
        }
924
927
        return ctxt
 
928
 
 
929
 
 
930
class ZeroMQContext(OSContextGenerator):
 
931
    interfaces = ['zeromq-configuration']
 
932
 
 
933
    def __call__(self):
 
934
        ctxt = {}
 
935
        if is_relation_made('zeromq-configuration', 'host'):
 
936
            for rid in relation_ids('zeromq-configuration'):
 
937
                    for unit in related_units(rid):
 
938
                        ctxt['zmq_nonce'] = relation_get('nonce', unit, rid)
 
939
                        ctxt['zmq_host'] = relation_get('host', unit, rid)
 
940
        return ctxt
 
941
 
 
942
 
 
943
class NotificationDriverContext(OSContextGenerator):
 
944
 
 
945
    def __init__(self, zmq_relation='zeromq-configuration', amqp_relation='amqp'):
 
946
        """
 
947
        :param zmq_relation   : Name of Zeromq relation to check
 
948
        """
 
949
        self.zmq_relation = zmq_relation
 
950
        self.amqp_relation = amqp_relation
 
951
 
 
952
    def __call__(self):
 
953
        ctxt = {
 
954
            'notifications': "False",
 
955
        }
 
956
        if is_relation_made(self.zmq_relation):
 
957
            matchmaker_data = get_matchmaker_map()
 
958
            if 'notifications-info' in matchmaker_data:
 
959
                ctxt['notifications'] = "True"
 
960
        elif is_relation_made(self.amqp_relation):
 
961
            ctxt['notifications'] = "True"
 
962
        return ctxt