__main__ bundles for executable library policy

30 views
Skip to first unread message

ole.e...@northern.tech

unread,
May 11, 2018, 11:24:51 AM5/11/18
to dev-cfengine
I would like feedback on a new feature. To enable policy which can both be imported as a library (inputs) and executed on it's own, I've introduced the __main__ name for bundles. When the entry policy file has a __main__ bundle it will be defined as main, however if it is in another imported file, it will be removed before evaluation (to avoid conflicting names). The old main bundle will still work as is.

Please tell me if you think this is useful, or if you have opinions on the syntax/semantics of this. The current C implementation might be changed.

Pull Request with example usage is here: https://github.com/cfengine/core/pull/3118

-Herman

Ted Zlatanov

unread,
May 28, 2018, 12:14:24 PM5/28/18
to dev-cf...@googlegroups.com
On Fri, 11 May 2018 08:24:51 -0700 (PDT) "ole.elgesem via dev-cfengine" <dev-cf...@googlegroups.com> wrote:

oevd> I would like feedback on a new feature. To enable policy which can both be
oevd> imported as a library (inputs) and executed on it's own, I've introduced
oevd> the *__main__* name for bundles. When the entry policy file has a *__main__*
oevd> bundle it will be defined as main, however if it is in another imported
oevd> file, it will be removed before evaluation (to avoid conflicting names).
oevd> The old main bundle will still work as is.

oevd> Please tell me if you think this is useful, or if you have opinions on the
oevd> syntax/semantics of this. The current C implementation might be changed.

I found names in CFEngine's evaluator to be tricky because of the way
variable names and resolution work, and preferred using tags. It's less
surprising for the users.

So in this case I wonder if adding a `runnable` tag to a bundle would be
better than requiring the name to be __main__. Or maybe even support
`autorun` in the C code, since it's already fairly standard and users
like it. As an added benefit, the tag approach allows multiple bundles
in one file to be runnable.

Ted

Reply all
Reply to author
Forward
0 new messages