While most of this is covered in the Bcfg2 docs, people still ask questions from time to time about writing client tools. In this post, I will cover the answer to a specific question that was posted to the mailing list recently.
We would like to change how ConfigFiles are copied on the client. This
means rewriting the InstallConfigFile method in the POSIX client plugin.
I wanted to get feed back how best to go about doing this. Would it make
sense to create a new Plug-in or modify the current one?
This post will implement a simple client tool which subclasses the POSIX client tool driver and replaces the InstallConfigFile method with a custom method.
The first step is to create the new client tool:
[root@bcfg2] ~ # cat bcfg2/src/lib/Client/Tools/myPOSIX.py import Bcfg2.Client.Tools import Bcfg2.Options class myPOSIX(Bcfg2.Client.Tools.POSIX.POSIX): name = 'myPOSIX' __execs__ = ['/bin/true'] conflicts = ['POSIX'] __handles__ = [('Path', 'file')] # Redefine InstallConfigFile here def InstallConfigFile(self, entry): return True
All this simple client tool does is redefine the InstallConfigFile method from POSIX.py. Everything else is the same. This is extremely useful if you find the behavior of a client tool useful, but wish to redefine how a particular method is implemented.
It is also worth noting that if you have a case where you need to augment something, you might check with others either on the bcfg2-dev mailing list or in #bcfg2 on Freenode as they may have run into similar issues. We are more than willing to accept useful code upstream.
So, getting back to the client tool, if we go ahead and run this with the following Path specified:
[root@bcfg2] /var/lib/bcfg2 # cat Bundler/foo.xml <Bundle name='foo'> <Path name='/root/foo'/> </Bundle> [root@bcfg2] /var/lib/bcfg2 # cat Cfg/root/foo/foo bar
then we get the following:
[root@bcfg2] ~ # bcfg2 -qI --- +++ @@ -1,1 +1,2 @@ +bar Install Path /root/foo: (y/N): y [root@bcfg2] ~ # cat /root/foo cat: /root/foo: No such file or directory
which is exactly what we expect since we replaced the Install method with what amounts to a noop method. This simple client tool was just used for illustrative purposes. If you were actually implementing this, it would obviously normally be something completely different (and more than likely useful).
That concludes this simple post outlining the basics of modifying existing Bcfg2 client tools.