This repository has been archived by the owner on Mar 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
provides.py
40 lines (35 loc) · 1.62 KB
/
provides.py
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
from charmhelpers.core import hookenv
from charms.reactive import hook
from charms.reactive import RelationBase
from charms.reactive import scopes
class InfluxdbApi(RelationBase):
# We expect multiple, separate services to be related, but all units of a
# given service will share the same database name and connection info.
# Thus, we use SERVICE scope and will have one converstaion per service.
scope = scopes.SERVICE
@hook('{provides:influxdb-api}-relation-{joined,changed}')
def changed(self):
for conversation in self.conversations():
hookenv.log("Setting api.available for conversation: {}"
.format(conversation))
conversation.set_state('{relation_name}.api.available')
@hook('{provides:influxdb-api}-relation-{departed,broken}')
def gone(self):
for conversation in self.conversations():
hookenv.log("Removing api.available for conversation: {}"
.format(conversation))
conversation.remove_state('{relation_name}.api.available')
def configure(self, port, username=None, password=None):
hookenv.log('setting up influx')
config = {
'hostname': hookenv.unit_get('private-address'),
'port': port,
}
if username is not None:
config['user'] = username
if password is not None:
config['password'] = password
for conversation in self.conversations():
hookenv.log("Setting up influx for conversation: {}"
.format(conversation))
conversation.set_remote(**config)