Skip to content

Instantly share code, notes, and snippets.

@johnsca
Created June 27, 2017 13:35
Show Gist options
  • Save johnsca/af3e1b70084ca34b85ea493f1caaca77 to your computer and use it in GitHub Desktop.
Save johnsca/af3e1b70084ca34b85ea493f1caaca77 to your computer and use it in GitHub Desktop.
from charms.reactive.context import relation_endpoint
@when('charm.installed', 'relation_endpoint.db.ready')
def handler():
render_config(hostnames=relation_endpoint.user_db.hostnames)
relation_endpoint.admin_db.hostnames
class CassandraClient(RelationEndpoint):
@property
def _ready_units(self):
ready_units = []
for relation in self.relations:
for unit in relation.units:
if unit.received_data.foo == 'foo':
ready_units.append(unit)
return ready_units
@property
def _unready_units(self):
return filter(lambda u: u.received_data.foo != 'foo',
(u for r in self.relations for u in r.units))
@property
def hostnames(self):
return [u.received_data.hostname for u in self._ready_units]
@when('relation_endpoint.{relation_endpoint_name}.changed')
def changed(self):
if self._ready_units:
set_flag('relation_endpoint.{relation_endpoint_name}.ready')
@johnsca
Copy link
Author

johnsca commented Jun 27, 2017

Something we lost here is the docstrings for the flags. We'll need some convention for that again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment