Ubuntu Pastebin

Paste from jamespage at Thu, 3 Dec 2015 08:26:14 +0000

Download as text
 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
51
diff --git a/requires.py b/requires.py
index b118668..cdd2e8a 100644
--- a/requires.py
+++ b/requires.py
@@ -14,14 +14,15 @@
 from charms.reactive import RelationBase
 from charms.reactive import hook
 from charms.reactive import scopes
+from charmhelpers.core import hookenv
 
 
 class RabbitMQRequires(RelationBase):
-    scope = scopes.GLOBAL
+    scope = scopes.SERVICE
 
     # These remote data fields will be automatically mapped to accessors
     # with a basic documentation string provided.
-    auto_accessors = ['hostname', 'password']
+    auto_accessors = ['hostname', 'password', 'private-address']
 
     def vhost(self):
         return self.get_local('vhost')
@@ -50,7 +51,7 @@ class RabbitMQRequires(RelationBase):
         Get the connection string, if available, or None.
         """
         data = {
-            'host': self.hostname(),
+            'host': self.private_address(),
             'vhost': self.vhost(),
             'username': self.username(),
             'password': self.password(),
@@ -67,3 +68,19 @@ class RabbitMQRequires(RelationBase):
         self.set_local('username', username)
         self.set_local('vhost', vhost)
         self.set_remote(**relation_info)
+
+    def get_remote_all(self, key, default=None):
+        '''Return a list of all values presented by remote units for key'''
+        values = []
+        for conversation in self.conversations():
+            for relation_id in conversation.relation_ids:
+                for unit in hookenv.related_units(relation_id):
+                    value = hookenv.relation_get(key,
+                                                 unit,
+                                                 relation_id) or default
+                    if value:
+                        values.append(value)
+        return list(set(values))
+
+    def rabbitmq_hosts(self):
+        return ','.join(self.get_remote_all('private-address'))
Download as text