Hello,
I would like to write a cobbler trigger to do something every time I add a system. I looked at the documentation at: https://fedorahosted.org/cobbler/wiki/CobblerTriggers but I think I am missing something.
A simple example is given in the form of a shell script and it shows $1 used as the name of a newly added system. However, I see nothing defining the arguments passed, nor the environment. I see that one can use the CobblerApi, but when I follow the link it tells me not to use "BootApi" (is BootApi == CobblerApi?) but to use "CobblerXmlrpc" instead. That seems to be a client/server system. The trigger docs say not to use it.
A says use B. B says don't use B, use C. A says don't use C. ????
So, is there anything defining the trigger API? Does one really need to use Python to do anything meaningful? I'm definitely not a Python wiz. It says that pre-triggers can prevent an add operation. How? Just exit(1)? How do I report errors back to the user?
In case it would help to understand my situation, I would like to be able to leave the networking empty and have a system add operation automatically define eth0 using the hostname to look up the MAC via "getent ethers hostname". I can easily write the code to do the lookup in sh/bash/ksh or perl, but I need to be able to supply the information back to the cobbler system after the lookup. I need to be able to fail on errors.
On Mon, 28 Mar 2011 09:02:20 -0400, Gary Algier gaa@ulticom.com wrote:
Hello,
I would like to write a cobbler trigger to do something every time I add a system. I looked at the documentation at: https://fedorahosted.org/cobbler/wiki/CobblerTriggers but I think I am missing something.
A simple example is given in the form of a shell script and it shows $1 used as the name of a newly added system. However, I see nothing defining the arguments passed, nor the environment. I see that one can use the CobblerApi, but when I follow the link it tells me not to use "BootApi" (is BootApi == CobblerApi?) but to use "CobblerXmlrpc" instead. That seems to be a client/server system. The trigger docs say not to use it.
A says use B. B says don't use B, use C. A says don't use C. ????
So, is there anything defining the trigger API? Does one really need to use Python to do anything meaningful? I'm definitely not a Python wiz. It says that pre-triggers can prevent an add operation. How? Just exit(1)? How do I report errors back to the user?
In case it would help to understand my situation, I would like to be able to leave the networking empty and have a system add operation automatically define eth0 using the hostname to look up the MAC via "getent ethers hostname". I can easily write the code to do the lookup in sh/bash/ksh or perl, but I need to be able to supply the information back to the cobbler system after the lookup. I need to be able to fail on errors.
The best example I can give you is the triggers found in the modules directory in the cobbler source [1]. The install_* ones and sync_* ones. The api passed in is a copy of BootAPI (which is the actual name of CobblerAPI). It is normally not ok to use BootAPI for various reasons, but in this case the trigger is running inside of cobblerd and can safely make use of BootAPI.
[1] - http://git.fedorahosted.org/git/?p=cobbler;a=tree;f=cobbler/modules;h=a6f0c1...
On 03/28/11 16:23, Scott Henson wrote:
On Mon, 28 Mar 2011 09:02:20 -0400, Gary Algiergaa@ulticom.com wrote:
Hello,
I would like to write a cobbler trigger to do something every time I add a system. I looked at the documentation at: https://fedorahosted.org/cobbler/wiki/CobblerTriggers
The best example I can give you is the triggers found in the modules directory in the cobbler source [1]. The install_* ones and sync_* ones. The api passed in is a copy of BootAPI (which is the actual name of CobblerAPI). It is normally not ok to use BootAPI for various reasons, but in this case the trigger is running inside of cobblerd and can safely make use of BootAPI.
[1] - http://git.fedorahosted.org/git/?p=cobbler;a=tree;f=cobbler/modules;h=a6f0c1...
How do I specify a module to be run pre-system-add?
Using an executable I would put it in: /var/lib/cobbler/triggers/add/system/pre with a name of my choosing. Do I create a similar directory structure and place it in: /usr/lib/python2.4/site-packages/cobbler/modules/add/system/pre ?
How does it know when to apply the modules in: /usr/lib/python2.4/site-packages/cobbler/modules/ or are they applied on every operation?
It looks like they are run every time and the register function tells cobbler when it should be used, but it only seems to define pre vs post.
On Mon, 28 Mar 2011 17:26:31 -0400, Gary Algier gaa@ulticom.com wrote:
On 03/28/11 16:23, Scott Henson wrote:
On Mon, 28 Mar 2011 09:02:20 -0400, Gary Algiergaa@ulticom.com wrote:
Hello,
I would like to write a cobbler trigger to do something every time I add a system. I looked at the documentation at: https://fedorahosted.org/cobbler/wiki/CobblerTriggers
The best example I can give you is the triggers found in the modules directory in the cobbler source [1]. The install_* ones and sync_* ones. The api passed in is a copy of BootAPI (which is the actual name of CobblerAPI). It is normally not ok to use BootAPI for various reasons, but in this case the trigger is running inside of cobblerd and can safely make use of BootAPI.
[1] - http://git.fedorahosted.org/git/?p=cobbler;a=tree;f=cobbler/modules;h=a6f0c1...
How do I specify a module to be run pre-system-add?
Using an executable I would put it in: /var/lib/cobbler/triggers/add/system/pre with a name of my choosing. Do I create a similar directory structure and place it in: /usr/lib/python2.4/site-packages/cobbler/modules/add/system/pre
No, you will need to put it in /usr/lib/python2.4/site-package/cobbler/modules and name it install_pre_*. You will then want to create a function in that module named 'register' that takes no arguments and returns "/var/lib/cobbler/triggers/install/pre/*". Then you will want to have a function called 'run', which takes api, args, and logger. This will be the function that does the magic.
How does it know when to apply the modules in: /usr/lib/python2.4/site-packages/cobbler/modules/ or are they applied on every operation?
Cobblerd loads all python files in that directory and runs the register function to identify what kind of module it is.
It looks like they are run every time and the register function tells cobbler when it should be used, but it only seems to define pre vs post.
You can return any valid trigger path and it should run it in the instances when the trigger would be run.
cobbler@lists.fedorahosted.org