def __init__(self, *args): super().__init__(*args) # Abstract out framework and friends so that this object is not # too tightly coupled with the underlying framework's implementation. # From this point forward, our Charm object will only interact with the # adapter and not directly with the framework. self.fw_adapter = framework.FrameworkAdapter(self.framework) self.prometheus_client = interface_http.Client(self, 'prometheus-api') self.mysql = interface_mysql.MySQLInterface(self, 'mysql') self.state.set_default( prometheus_server_details=None, mysql_server_details=None, ) # Bind event handlers to events event_handler_bindings = { self.mysql.on.new_relation: self.on_mysql_new_relation, self.on.config_changed: self.on_config_changed, self.on.start: self.on_start, self.on.update_status: self.on_update_status, self.on.upgrade_charm: self.on_start, self.prometheus_client.on.server_available: self.on_prom_available, } for event, delegator in event_handler_bindings.items(): self.fw_adapter.observe(event, delegator)
def __init__(self, charm, relation_name): super().__init__(charm, relation_name) self._relation_name = relation_name # Abstract out framework and friends so that this object is not # too tightly coupled with the underlying framework's implementation. # From this point forward, our Client object will only interact with # the adapter and not directly with the framework. self.adapter = framework.FrameworkAdapter(self.framework) self.adapter.observe(charm.on[relation_name].relation_changed, self.on_relation_changed)