Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from charms.reactive import hook
- from charms.reactive import RelationBase
- from charms.reactive import scopes
- from charmhelpers.core.hookenv import log
- class DcosRequires(RelationBase):
- scope = scopes.UNIT
- @hook('{requires:docs}-relation-{joined,changed}')
- def changed(self):
- #conv = self.conversation()
- #conv.set_state('{relation_name}.available')
- log("here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
- @hook('{requires:dcos}-relation-{departed,broken}')
- def broken(self):
- #conv = self.conversation()
- #conv.remove_state('{relation_name}.available')
- log("not here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
- def services(self):
- """
- Returns a list of available HTTP services and their associated hosts
- and ports.
- The return value is a list of dicts of the following form::
- [
- {
- 'service_name': name_of_service,
- 'hosts': [
- {
- 'hostname': address_of_host,
- 'port': port_for_host,
- },
- # ...
- ],
- },
- # ...
- ]
- """
- services = {}
- for conv in self.conversations():
- service_name = conv.scope.split('/')[0]
- service = services.setdefault(service_name, {
- 'service_name': service_name,
- 'hosts': [],
- })
- host = conv.get_remote('hostname') or conv.get_remote('private-address')
- port = conv.get_remote('port')
- if host and port:
- service['hosts'].append({
- 'hostname': host,
- 'port': port,
- })
- return [s for s in services.values() if s['hosts']]
Add Comment
Please, Sign In to add comment