~ibmcharmers/interface-ibm-mq/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from charms.reactive import hook
from charms.reactive import RelationBase
from charms.reactive import scopes


class mqProvides(RelationBase):
    # Every unit connecting will get the same information
    scope = scopes.SERVICE

    @hook('{provides:ibm-mq}-relation-joined')
    def joined(self):
        conversation = self.conversation()
        conversation.remove_state('{relation_name}.departed')
        conversation.set_state('{relation_name}.connected')

    @hook('{provides:ibm-mq}-relation-departed')
    def departed(self):
        conversation = self.conversation()
        conversation.remove_state('{relation_name}.connected')
        conversation.set_state('{relation_name}.departed')

    def dismiss(self, service):
        conversation = self.conversation(service)
        conversation.remove_state('{relation_name}.departed')

    def reset_states(self, service):
        conversation = self.conversation(service)
        conversation.remove_state('{relation_name}.connected')
        conversation.remove_state('{relation_name}.departed')

    def set_mq_details(self, service, QM_Name, Qname, host, port):
        conversation = self.conversation(service)
        conversation.set_remote(data={
            'QM_Name': QM_Name,
            'Qname': Qname,
            'host': host,
            'port': port,
        })

    def get_consumer_hostname(self):
        return self.get_remote('host')

    def services(self):
        """
        Return a list of services requesting MQ.
        """
        service = []
        for conversation in self.conversations():
            service.append(conversation.scope)
        return service