(self, provider)
return result
Once a provider has a plan generated, see if we need to run the plan.
Once a provider has a plan generated, see if we need to run the plan.
Once a provider has a plan generated see if we need to run the plan .
def do_apply(self, provider):
        """
        Once a provider has a plan generated, see if we need to run the plan.
        """

        from opsmop.callbacks.callbacks import Callbacks

        # some simple providers - like Echo, do not have a planning step
        # we will always run the apply step for them. For others, we will only
        # run the apply step if we have computed a plan
        if not provider.has_planned_actions():
            if not provider.skip_plan_stage():
                return Result(provider=provider, changed=False, data=None)
                
        # indicate we are about take some actions
        Callbacks().on_apply(provider)
        # take them
        result = provider.apply()
        Callbacks().on_taken_actions(provider, provider.actions_taken)
            
        # all Provider apply() methods need to return Result objects or raise
        # exceptions
        assert issubclass(type(result), Result)

        # the 'register' feature saves results into variable scope
        resource = provider.resource
        
        # determine if there was a failure
        fatal = False
        cond = resource.failed_when
        if cond is not None:
            if issubclass(type(cond), Lookup):
                fatal = cond.evaluate(resource)
                result.reason = cond
            elif callable(cond):
                fatal = cond(result)
            else:
                fatal = cond
        elif result.fatal:
            fatal = True
        result.fatal = fatal
        result.changed = provider.has_changed()
        # TODO: eliminate the actions class
        if result.changed:
            result.actions = [ x.do for x in provider.actions_taken ]
        else:
            result.actions = []

        Callbacks().on_result(provider, result)

        return result
def do_apply ( self , provider ) : from opsmop . callbacks . callbacks import Callbacks # some simple providers - like Echo, do not have a planning step # we will always run the apply step for them. For others, we will only # run the apply step if we have computed a plan if not provider . has_planned_actions ( ) : if not provider . skip_plan_stage ( ) : return Result ( provider = provider , changed = False , data = None ) # indicate we are about take some actions Callbacks ( ) . on_apply ( provider ) # take them result = provider . apply ( ) Callbacks ( ) . on_taken_actions ( provider , provider . actions_taken ) # all Provider apply() methods need to return Result objects or raise # exceptions assert issubclass ( type ( result ) , Result ) # the 'register' feature saves results into variable scope resource = provider . resource # determine if there was a failure fatal = False cond = resource . failed_when if cond is not None : if issubclass ( type ( cond ) , Lookup ) : fatal = cond . evaluate ( resource ) result . reason = cond elif callable ( cond ) : fatal = cond ( result ) else : fatal = cond elif result . fatal : fatal = True result . fatal = fatal result . changed = provider . has_changed ( ) # TODO: eliminate the actions class if result . changed : result . actions = [ x . do for x in provider . actions_taken ] else : result . actions = [ ] Callbacks ( ) . on_result ( provider , result ) return result