77da9ca15da587abafb02badcf0bf487cd1a7255
1 from charms
.reactive
import hook
2 from charms
.reactive
import RelationBase
3 from charms
.reactive
import scopes
6 class OpenVimRequires(RelationBase
):
9 @hook('{requires:openvim}-relation-{joined,changed}')
11 conv
= self
.conversation()
12 if conv
.get_remote('port'):
13 # this unit's conversation has a port, so
14 # it is part of the set of available units
15 conv
.set_state('{relation_name}.available')
17 @hook('{requires:openvim}-relation-{departed,broken}')
19 conv
= self
.conversation()
20 conv
.remove_state('{relation_name}.available')
24 Returns a list of available openvim services and their associated hosts
27 The return value is a list of dicts of the following form::
31 'service_name': name_of_service,
34 'hostname': address_of_host,
35 'port': port_for_host,
36 'user': user_for_host,
45 for conv
in self
.conversations():
46 service_name
= conv
.scope
.split('/')[0]
47 service
= services
.setdefault(service_name
, {
48 'service_name': service_name
,
51 host
= conv
.get_remote('hostname') or \
52 conv
.get_remote('private-address')
53 port
= conv
.get_remote('port')
54 user
= conv
.get_remote('user')
56 service
['hosts'].append({
61 return [s
for s
in services
.values() if s
['hosts']]