~canonical-is-sa/charms/trusty/grafana/interface-grafana-source

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
from charmhelpers.core import hookenv
from charms.reactive import hook
from charms.reactive import RelationBase
from charms.reactive import scopes


class GrafanaProvides(RelationBase):
    scope = scopes.GLOBAL

    @hook('{provides:grafana-source}-relation-{joined,changed}')
    def changed(self):
        self.set_state('{relation_name}.available')

    @hook('{provides:grafana-source}-relation-{broken,departed}')
    def broken(self):
        self.remove_state('{relation_name}.available')

    def provide(self, source_type, port, description, username=None, password=None):
        relation_info = {
            'type': source_type,
            'url': 'http://{}:{}'.format(hookenv.unit_get('private-address'), port),
            'description': description,
        }
        if username and password:
            relation_info['username'] = username
            relation_info['password'] = password

        self.set_remote(**relation_info)