Skip to content

Instantly share code, notes, and snippets.

@AdamIsrael
Created September 28, 2018 02:26
Show Gist options
  • Save AdamIsrael/3747bb58163ed16c2ac12134ecbafca5 to your computer and use it in GitHub Desktop.
Save AdamIsrael/3747bb58163ed16c2ac12134ecbafca5 to your computer and use it in GitHub Desktop.
Example reactive charm to test register_trigger
from charms.reactive import when, when_not, set_flag
from charmhelpers.core.hookenv import log, config
from charms.reactive.flags import register_trigger
# Register a trigger so that we can respond to config.changed, even if
# it's being cleared by another handler
register_trigger(when='config.changed',
set_flag='trigger.config')
@when_not('test-config-changed.installed')
def install_test_config_changed():
set_flag('test-config-changed.installed')
@when('config.changed')
def log_config_changed():
cfg = config()
log("#### config-changed state handled: {}".format(cfg))
@when('trigger.config')
def trigger_config_changed():
cfg = config()
log("#### trigger_config_changed called: {}".format(cfg))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment