Plugin for switch vlan changes
-
Hi all,
I’d written a plugin many years ago on old Fog, and now bringing it back to life I’m writing it for fog1.4.4.
I’m pleased to see Hook method allowing me to tie in to many base fog functions, so have pages, database and config all working great.One element I need to do, is when an image is deployed, before/during the reboot I need to trigger my code. Originally I did that in Post_Stage3.php and called my code in the plugin class from there, but looking in the new improved Fog, Post_Stage3 looks a bit like a placeholder/backward compatibility.
So two questions, first, is there a Hook register I can call to tie into what would be in Post_Stage3 (Obviously this would be ideal, means no change to existing Fog code, as per the Hook/register principles).
Secondly, would I just be able to add my code into Post_Stage3 (A bit hacky, but would work) and execute it as I did previously.Thanks in advance!
Andy -
I can’t help from a programming/hook standpoint. But I can tell you the point you are talking about is where the postinstall scripts are called. The post install scripts are new to FOG 1.3.0+
I am a bit intrigued by your subject line. What are you trying to accomplish with this new plugin?
-
@andyb2000 is your plugin in fog’s repo? If it’s useful, you can donate the code - and then we all (as a community) will try to maintain it (or you can still).
-
Thanks for the replies, yes I’m trying to tie in to the postinstall scripts, preferably through the plugin architecture as that then requires no other code changes.
Code isn’t in the repo as yet as it’s totally not working and nowhere near a release, so will look into that for future as I maintain a few git repo’s myself.
The plugin allows fog to change VLANs on Cisco switches when deployments complete, so to switch the deployed machines to specific VLANs based on the image deployed. It does this using snmpset to the switches. I’ve hooked into the host view (to capture switch and interface for the config), and image view to set the vlan to switch to. This all works.
So my key question is within the plugin Hook ->register functions, can I tie in to the postinstall or Post_Stage3 part.
I’m also looking to tie in (again preferably with the Hook ->register function in my plugin) to when an image is triggered to be deployed to a host, I need to call a function before the host is WOL’d so what would be the register code for that? I’ve tried
->register( 'HOST_TASKING_COMPLETE', array( $this, 'hostTaskingComplete' )
But I suspect that is for the completion of a task, rather than at the creation of the task?
Thanks in advance for any dev’s to help out.Regards,
Andy -
@Tom-Elliott can you look through this thread please? I have no idea about this.
-
I’ll take a look when I have a bit more time. But please Tom, do so as well. You know the web UI way better than I do.
@andyb2000 I am sure we can help you out. Just needs a bit more time for a profound question to answer.
-
@andyb2000 I am very sorry for not having responded properly to your request yet. Just too many other things need attention. But I have this on my list, promise!
-
Hi!
Thank you, I appreciate it’s difficult to look into items like this quickly! Fully understand and appreciate you taking the time to get back to me. -
@andyb2000 Thanks for your patience! So basically there are two mechanisms you can use for what you want to achieve. One is hooks (that you already know) and the other one is events.
So to answer your question. The Post_Stage3.php is still the right place (for end of deploy) but the actual code is being refactored and moved to
lib/reg-task/taskqueue.class.php
(ref). So you were on the right track already. Either hookHOST_TASKING_COMPLETE
or eventHOST_IMAGE_COMPLETE
should work for you. For examples seelib/plugins/windowskey/hooks/changehostkey.hook.php
orlib/plugins/slack/events/imagecomplete_slack.event.php
(notehook
andevent
in the filename).I’m also looking to tie in (again preferably with the Hook ->register function in my plugin) to when an image is triggered to be deployed to a host, I need to call a function before the host is WOL’d so what would be the register code for that?
You want to use
HOST_DEPLOY_POST
orGROUP_DEPLOY_POST
hook (code ref) for that - first one for single host tasking and the later one for group tasking. Mind you those hooks apply for deploy and capture tasking - the name of the hook might be a bit misleading here. -
@andyb2000 If you are looking for more hooks I can recommend this find/awk foo magic command:
find /var/www/fog -type f -exec awk '/processEvent\(/,/\);/' {} \; | less
And for events (note there are only a few as of now):
find /var/www/fog -type f -exec awk '/notify\(/,/\);/' {} \; | less
When you find an interesting hook name you can find out where it is defined by running:
find /var/www/fog -type f -exec grep "HOST_IMAGE_COMPLETE" {} /dev/null \;
I know this is not perfect and we should have all this documented better. But hey, it’s all in the code…
-
Thats excellent, thank you Sebastian for taking the time to reply, I’ll get onto that code now, that’s what I’m after.
And yes, the find/awk trick was also what I was looking for, who needs docs, like you say, it’s in the code