Forum: Cfengine Help
Subject: Re: classes scope with methods
Author: yrouxel
Link to topic: https://cfengine.com/forum/read.php?3,20797,20809#msg-20809
Hi Seva,
Thanks for your reply.
I didn't managed to find that information in the reference manual. But,
effectively, classes defined by a class body ("classes => ...") in the sub
bundle, are visible to the caller bundle.
In the previous topic I had another issue (Classes scope and lifetime,
2011/02/08; ):
sub-bundles, which are plain bundles of their own, don't seem to be reentrant :
If the sub-bundle B is called several times through methods calls, variables
keep their value setted in previous calls, and private classes setted are
retained. This is rather awkward, as some of these variables/classes can be
used only for the internal logic of the bundle B and their state should be
reinitailized once the method call ends.
For variables, there is a solution with policy:
bundle agent B(arg1) {
vars:
"vB1" string => "blabla",
policy => "overridable";
...
}
But for classes, the only way I found was to resort to a kind of unique naming
of class for each call, possibly depending on the value of some arguments of
the bundle B:
bundle agent B(arg1) {
vars:
"class_uid" => canonify("$(arg1)");
classes:
"cB1_$(class_uid)" expression => "any";
}
This way, each each time bundle B is called, internal classes have new names.
This does not seem very elegant to me. Is there is a better way ?
Regards
Yann Rouxel
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine