Пример #1
0
    def execute_resource(self, host, resource, handlers=False):
        """
        This handles the plan/apply intercharge for a given resource in the resource tree.
        It is called recursively via walk_children to run against all resources.
        """
        assert host is not None
        # we only care about processing leaf node objects
        if self.is_collection(resource):
            return

        # if in handler mode we do not process the handler unless it was signaled
        if handlers and not Context.has_seen_any_signal(host, resource.all_handles()):
            Callbacks.on_skipped(resource, is_handler=handlers)
            return

        # tell the callbacks we are about to process a resource
        # they may use this to print information about the resource
        Callbacks.on_resource(resource, handlers)

        # plan always, apply() only if not in check mode, else assume
        # the plan was executed.
        provider = self.do_plan(resource)
        assert provider is not None
        if Context.is_apply():
            self.do_apply(host, provider, handlers)
        else: # is_check
            self.do_simulate(host, provider)

        # if anything has changed, let the callbacks know about it
        self.signal_changes(host=host, provider=provider, resource=resource)
Пример #2
0
    def process_role_internal(self, host, policy, role, local=True, sender=None):
        
        if not local:
            from opsmop.callbacks.event_stream import EventStreamStreamCallbacks
            from opsmop.callbacks.common import CommonCallbacks
            Context.set_callbacks([ EventStreamCallbacks(sender=sender), CommonCallbacks() ])

        
        role.pre()
        # set up the variable scope - this is done later by walk_handlers for lower-level objects in the tree
        policy.attach_child_scope_for(role)
        # tell the callbacks we are in validate mode - this may alter or quiet their output
        Callbacks.on_validate()
        # always validate the role in every mode (VALIDATE, CHECK ,or APPLY)
        self.validate_role(role)
        # skip the role if we need to
        if not role.conditions_true():
            Callbacks.on_skipped(role)
            return
        # process the tree for real for non-validate modes
        if not Context.is_validate():
            self.execute_role_resources(host, role)
            self.execute_role_handlers(host, role)
        # run any user hooks
        role.post()