-
Notifications
You must be signed in to change notification settings - Fork 0
/
provides.py
53 lines (40 loc) · 1.3 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
41
42
43
44
45
46
47
48
49
50
51
52
53
from charms.reactive import RelationBase
from charms.reactive import scopes
from charms.reactive import hook
class RebacaProvider(RelationBase):
''' Idempotent method to deal with data for the relationship.
You should only be communicating with the remote application
in this class. Actions that need to be taken on the host
are written in decorated methods'''
# Define a service level communication scope.
scope = scopes.SERVICE
auto_accessors=['private-address', 'client']
@hook('{provides:rebaca}-relation-{joined,changed}')
def joined_and_changed(self):
'''
Implement this behavior like so:
`metadata.yaml`
provides:
server:
interface: rebaca
`reactive/module.py`
@when('server.connected')
def do_something(server):
print(server.private_address())
'''
self.set_state('{relation_name}.connected')
@hook('{provides:rebaca}-relation-{broken,departed}')
def broken_and_departed(self):
'''
Implement this behavior like so:
`metadata.yaml`
provides:
server:
interface: rebaca
`reactive/module.py`
@when_not('server.connected')
def cleanup(server):
# do something here to cleanup after the connection is broken
'''
self.remove_state('{relation_name}.connected')
pass