• Recent
    • Unsolved
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login
    1. Home
    2. andyb2000
    • Profile
    • Following 0
    • Followers 0
    • Topics 3
    • Posts 7
    • Best 0
    • Controversial 0
    • Groups 0

    andyb2000

    @andyb2000

    Dev, coder, tinkerer, core network engineer, and other bits and pieces!

    0
    Reputation
    165
    Profile views
    7
    Posts
    0
    Followers
    0
    Following
    Joined Last Online
    Website www.thebmwz3.co.uk Location North-East, UK

    andyb2000 Unfollow Follow

    Latest posts made by andyb2000

    • Plugin hook deploy problem

      Hi all,
      FOG Running Version 1.4.4 SVN Revision: 6077

      Working on a plugin, I’m using the hooks method to call code on GROUP_DEPLOY_HOST:

      ->register(
                      'GROUP_DEPLOY_POST',
                      array(
                          $this,
                          'groupDeployPost'
                      )
                  )
      

      So then my function “groupDeployPost” contains code like this:

       public function groupDeployPost($arguments)
         {
              global $node;
              global $sub;
              global $id;
              global $type;
      
              if (!in_array($this->node, (array)self::$pluginsinstalled)) {
                  return;
              }
      		self::getClass('MyPluginClass')->myclass_setvlan(113,"666",0);
      	}
      

      (Note I’ve obviously cut a lot of it down, just to give an example.)
      Now in MyPluginClass I have the function myclass_setvlan and I can call that from pretty much anywhere else (I do on the host display screens, other php pages, etc) so I know that calling the class and the function work great.
      However, in this hook it doesn’t work, in fact there are a lot of defined variables, functions, etc that DO NOT work just in this GROUP_DEPLOY_POST hook, which makes me think this is different somehow. (e.g. it works on HOST_TASKING_COMPLETE or HOST_FIELDS etc)

      I get the failure:

      [Wed Jan 31 12:21:04.094317 2018] [php7:error] [pid 23333] [client x.x.x.x:12990] PHP Fatal error:  Uncaught Error: Call to a member function getClass() on null in /var/www/fog/lib/plugins/myplugin/class/myplugin.class.php:49\nStack trace:\n#0 /var/www/fog/lib/plugins/myplugin/hooks/addmypluginhost.hook.php(461): MyPluginClass->myclass_setvlan('113', '666', 0)\n#1 /var/www/fog/lib/fog/hookmanager.class.php(83): AddMyPluginHost->groupDeployPost(Array)\n#2 /var/www/fog/lib/fog/fogpage.class.php(1372): HookManager->processEvent('GROUP_DEPLOY_PO...')\n#3 /var/www/fog/lib/fog/fogpagemanager.class.php(257): FOGPage->deployPost()\n#4 /var/www/fog/management/index.php(58): FOGPageManager->render()\n#5 {main}\n  thrown in /var/www/fog/lib/plugins/myplugin/class/myplugin.class.php on line 49, referer: http://x.x.x.x/fog/management/index.php?node=group&sub=deploy&type=8&id=18
      

      This makes me think there is something missing from the core code hook that’s not passing variables/classes through? Is there a quick and dirty way of forcing this to work, perhaps by referencing my class/php file directly as an include at this point? Just to get me working!

      Thanks in advance.

      posted in General
      andyb2000A
      andyb2000
    • RE: Image name/Path not stripping all illegal chars

      Ah, thanks for the clarification @Tom-Elliott that makes sense, I just had some users complaining as they weren’t particularly linux-savvy trying to capture, not realising the significance of the forward slash.
      Thank you, I’ll advise them.

      posted in FOG Problems
      andyb2000A
      andyb2000
    • Image name/Path not stripping all illegal chars

      This appears a fairly simple one, when creating a new image, image name (iName) takes any characters, which then does a regular expression replace to fill in the iFile input box with the Image Path to be created.
      It doesn’t escape/remove all illegal characters, one such character is the forward-slash which then causes filesystem issues during the FTP rename component.

      Tested using Image Name of “MyTest-25/01/18” which then gets the image path filled out to /images/mytest-25/01/18
      When image is captured the process fails at the FTP segment, raw ftp logs show the rename failing:

      Thu Jan 25 15:27:40 2018 [pid 28283] [fog] FTP command: Client "172.16.4.1", "RNFR /images/dev/18a905f6e4ae"
      Thu Jan 25 15:27:40 2018 [pid 28283] [fog] FTP response: Client "172.16.4.1", "350 Ready for RNTO."
      Thu Jan 25 15:27:40 2018 [pid 28283] [fog] FTP command: Client "172.16.4.1", "RNTO /images/mytest-25/01/18"
      Thu Jan 25 15:27:40 2018 [pid 28283] [fog] FTP response: Client "172.16.4.1", "550 Rename failed."
      

      (Obviously due to the forward slash being a directory command in Linux).

      Code in question:
      fog/management/js/fog/fog.image.js

          $('#iName').on('change keyup',function(e) {
              var start = this.selectionStart,
                  end = this.selectionEnd;
              if (typeof iFileVal === 'undefined') return;
              if (iFileVal.length == 0) $('#iFile').val(this.value.replace(/[^\w+\/\.-]/g,''));
              this.setSelectionRange(start,end);
              e.preventDefault();
      

      I’m out of time today, but will try and spot the error in the regex as it does appear to have it in the replace values (/)

      Regards,
      Andy

      posted in FOG Problems
      andyb2000A
      andyb2000
    • RE: Plugin for switch vlan changes

      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 🙂

      posted in General
      andyb2000A
      andyb2000
    • RE: Plugin for switch vlan changes

      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.

      posted in General
      andyb2000A
      andyb2000
    • RE: Plugin for switch vlan changes

      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

      posted in General
      andyb2000A
      andyb2000
    • 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

      posted in General
      andyb2000A
      andyb2000