def _decorator(func): action_id = _action_id(func) short_action_id = _short_action_id(func) @wraps(func) def _wrapped(*args, **kwargs): active_states = get_states() missing_states = [state for state in desired_states if state not in active_states] if missing_states: hookenv.log('%s called before state%s: %s' % ( short_action_id, 's' if len(missing_states) > 1 else '', ', '.join(missing_states)), hookenv.WARNING) return func(*args, **kwargs) _wrapped._action_id = action_id _wrapped._short_action_id = short_action_id return _wrapped
def _decorator(func): action_id = _action_id(func) short_action_id = _short_action_id(func) @wraps(func) def _wrapped(*args, **kwargs): active_flags = get_flags() missing_flags = [flag for flag in desired_flags if flag not in active_flags] if missing_flags: hookenv.log('%s called before flag%s: %s' % ( short_action_id, 's' if len(missing_flags) > 1 else '', ', '.join(missing_flags)), hookenv.WARNING) return func(*args, **kwargs) _wrapped._action_id = action_id _wrapped._short_action_id = short_action_id return _wrapped
def preflight(action): """ Decorator to run a handler before the main hook phase. preflight hooks are used to initialize state for use by the main hooks (including hooks that exist in other layers). They can also be used to validate the environment, blocking the unit and aborting the hook if something this layer is responsible for is broken (eg. a service configuration option set to an invalid value). We need abort before the main reactive loop, or we risk failing to run handlers that rely on @when_file_changed, reactive.helpers.data_changed or other state tied to charmhelpers.core.unitdata transactions. """ _id = _short_action_id(action) hookenv.atstart(hookenv.log, "preflight handler: {}".format(_id)) hookenv.atstart(action) return action
def preflight(action): ''' Decorator to run a handler before the main hook phase. preflight hooks are used to initialize state for use by the main hooks (including hooks that exist in other layers). They can also be used to validate the environment, blocking the unit and aborting the hook if something this layer is responsible for is broken (eg. a service configuration option set to an invalid value). We need abort before the main reactive loop, or we risk failing to run handlers that rely on @when_file_changed, reactive.helpers.data_changed or other state tied to charmhelpers.core.unitdata transactions. ''' _id = _short_action_id(action) hookenv.atstart(hookenv.log, 'preflight handler: {}'.format(_id)) hookenv.atstart(action) return action
def _decorator(func): action_id = _action_id(func) short_action_id = _short_action_id(func) @wraps(func) def _wrapped(*args, **kwargs): active_states = get_states() missing_states = [state for state in desired_states if state not in active_states] if missing_states: hookenv.log( "%s called before state%s: %s" % (short_action_id, "s" if len(missing_states) > 1 else "", ", ".join(missing_states)), hookenv.WARNING, ) return func(*args, **kwargs) _wrapped._action_id = action_id _wrapped._short_action_id = short_action_id return _wrapped