Forum: CFEngine Help
Subject: Re: Clarification on parameter passing with bundles / classes
Author: frans
Link to topic: https://cfengine.com/forum/read.php?3,24247,24259#msg-24259

Thanks Todd and lauwersw for the replies.  The point about classes being global 
when enacted if_repaired was the root of my woes.  

To illustrate, take this bundle as an example:


bundle agent test {

vars:

        "myslist"  slist => { "red", "green", "blue" };

files:

        "/tmp/foo/$(myslist)"
                copy_from => local_cp("/root/$(myslist)"),
                classes => if_repaired("$(myslist)");

methods:

        "any" usebundle => reportfile("$(myslist)"),
        ifvarclass => "$(myslist)";
}

bundle agent reportfile(target) {

 reports:
        
        red::
        "This is red leader.";
        
        
        green::
        "This is green leader";
}



During execution the first call to the reportfile method results in both red 
and green being true.

cf3>       BUNDLE reportfile( {'red'} )

cf3> Report: This is red leader.
cf3> R: This is red leader.
cf3> 
cf3>     .........................................................
cf3>     Promise handle: 
cf3>     Promise made by: This is green leader
cf3>     .........................................................
cf3> 
cf3> Report: This is green leader
cf3> R: This is green leader

Then, when reportfile gets called with "green" as the parameter, no reports are 
made.

cf3>  -> This promise has already been verified
cf3>  -> This promise has already been verified

In order to get the one-off handling of certain parameters that I was looking 
for it's necessary to pass the parameter to a private class that is going to be 
local in scope and will only exist for a particular iteration of the method.  


bundle agent reportfile(target) {

 classes:
        "$(target)_class" expression => "$(target)";

 reports:

        red::
        "This is red leader.",
        ifvarclass => "red_class";

        green::
        "This is green leader",
        ifvarclass => "green_class";

}



cf3>       * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
cf3>       BUNDLE reportfile( {'red'} )
cf3>       * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
cf3> 

cf3> 
cf3> Initiate variable convergence...
cf3> 
cf3>      +  Private classes augmented:
cf3>      +       red_class

cf3> 
cf3> Report: This is red leader.
cf3> R: This is red leader.
cf3> 
cf3> . . . . . . . . . . . . . . . . . . . . . . . . . . . .
cf3> Skipping whole next promise (This is green leader), as var-context 
green_class is not relevant
cf3> . . . . . . . . . . . . . . . . . . . . . . . . . . . .
cf3> 

cf3>       * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
cf3>       BUNDLE reportfile( {'green'} )
cf3>       * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

cf3> 
cf3>      +  Private classes augmented:
cf3>      +       green_class
cf3> 

cf3> Report: This is green leader
cf3> R: This is green leader
cf3>

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to