• Recent
  • Unsolved
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
  • Recent
  • Unsolved
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

Multcasting - Hosts Do Not Contain the Same Image Assignments

Scheduled Pinned Locked Moved Solved
Bug Reports
6
25
7.3k
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T
    Tom Elliott
    last edited by Jan 29, 2016, 5:29 PM

    My revised code: explained if you need to understand a bit more.

        public function doMembersHaveUniformImages() {
            $imageID = $this->getSubObjectIDs('Host',array('id'=>$this->get('hosts')),'imageID','','', '','','array_count_values');
            return (count($imageID) == 1 && $imageID[0] == $this->getHostCount());
        }
    

    First, we get all the counts of the values returned. This return will store in an array, not an associative array. Meaning values in this will be:

    imageID[0]
    imageID[1]
    imageID[2]

    etc…

    the return will count the total number of items in the array,

    if it’s 0, or greater than 1, we know they aren’t uniform.

    If it is one, the count should match that of the number of hosts in the group.

    If that doesn’t match, we know they aren’t uniform.

    If both tests pass, we know they are uniform.

    Does this help?

    Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

    Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

    Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

    1 Reply Last reply Reply Quote 0
    • J
      jgurka @Tom Elliott
      last edited by jgurka Jan 29, 2016, 11:56 AM Jan 29, 2016, 5:55 PM

      @Tom-Elliott

      This is how I understand it:

      $images = array_count_values…

      • Outputs an array of the counts for each item listed.
        • E.g., Host = 2, imageID = 1

      $images[0]

      • References the output array and will take the maximum of existing integer indices as the value.
        • If Host = 2 and imageID = 1, PHP would be taking a value of 2.
      • [0] specifies the key value. Since PHP starts counting at 0 for integers, the value 0 is actually equal to “maximum of existing integer + 1.”
      • So, if $images pulled value of 2 and we add [0], it’s actually doing “2+1=3.”
      T 1 Reply Last reply Jan 29, 2016, 5:56 PM Reply Quote 0
      • T
        Tom Elliott @jgurka
        last edited by Jan 29, 2016, 5:56 PM

        @jgurka What you’re saying is wrong. I coded it, I know what it’s doing. I’m trying to help.

        Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

        Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

        Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

        T 1 Reply Last reply Jan 29, 2016, 6:00 PM Reply Quote 2
        • T
          Tom Elliott @Tom Elliott
          last edited by Jan 29, 2016, 6:00 PM

          Further,

          Array count values, doesn’t matter how it gets the informatin, it’s only counting the values.

          for example:

          this[0] = 1
          this[1] = 1
          this[2] = 2

          Array count values on it will return:

          this[1] => 2
          this[2] => 1

          So i do have an error: but the error is not the way you’re seeing it.

          Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

          Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

          Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

          J 1 Reply Last reply Jan 29, 2016, 6:12 PM Reply Quote 0
          • T
            Tom Elliott
            last edited by Jan 29, 2016, 6:05 PM

            Hopefully this one works:

                public function doMembersHaveUniformImages() {
                    $imageID = $this->getSubObjectIDs('Host',array('id'=>$this->get('hosts')),'imageID','','', '','','array_count_values');
                    $imageID = count($imageID) == 1 ? array_shift($imageID) : 0;
                    return $imageID == $this->getHostCount();
                }
            

            Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

            Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

            Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

            1 Reply Last reply Reply Quote 0
            • J
              jgurka @Tom Elliott
              last edited by Jan 29, 2016, 6:12 PM

              @Tom-Elliott

              ‘Host’ is defined in the output array for $images?

              PHP.net reference on array_count_values

              • array_count_values() returns an array using the values of array as keys and their frequency in array as values.

              This shows an example output at bottom of page for array_count_values

              Btw, I’m not trying to attack you at all. 🙂

              T 1 Reply Last reply Jan 29, 2016, 6:22 PM Reply Quote 0
              • T
                Tom Elliott @jgurka
                last edited by Jan 29, 2016, 6:22 PM

                @jgurka You’re reading it incorrectly though.

                Understand, I’m not trying to attack either.

                I’m not passing anything with a value of Host.

                THe “getSubObjectIDs” is only getting the id’s of an object. So, without the array_count_values, it returns only the id’s of the manager and field it is requesting. (in this case the imageID field).

                So it will receiving the values in non associative form:

                eg.

                $imageID[0] = 15 (15 here is the image id returned.)
                $imageID[1] = 16 (16 here is the image id returned.)

                It then passes (if array_count_values) is passed, through that and returns:

                imageID[15] = 1 (here the array key is swapped from a normal associative array to whatever the value was, and the number is the total count of the 15 values, so from above it is only 1 count.)

                Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

                Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

                Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

                J 2 Replies Last reply Jan 29, 2016, 8:02 PM Reply Quote 0
                • J
                  jgurka @Tom Elliott
                  last edited by jgurka Jan 29, 2016, 2:05 PM Jan 29, 2016, 8:02 PM

                  @Tom-Elliott

                  I’m doing my best to follow your explanation. Please note I’ve been referring to the older version that I edited and not your latest (I’ll spin up a VM in a little to see if it’s working).

                  Let me see if I’m following correctly. I’m referencing the older version of the code:

                      public function doMembersHaveUniformImages() {
                          $images = array_count_values($this->getSubObjectIDs('Host',array('id'=>$this->get('hosts')),'imageID'));
                          return (count($images) == 1 && $images[0] == $this->getHostCount());
                  

                  $images defines the new array & equals sets that variable to the output of what follows.

                  array_count_values will count all of the values that are output from what follows.

                  $this is used to reference the calling object (in this case getSubObjectIDs) and -> points it to the object.

                  ‘Host’ is referring to the class Host that is set by host.class.php

                  array(‘id’=>$this->get(‘hosts’) tells it to create an array, referencing ‘id’ that’s defined in group.class.php (database field ‘groupID’). $this references the call object of get(‘hosts’), which is defined within tasklog.class.php as returning the hosts listed in the ‘taskID.’

                  array_count_values($this->getSubObjectIDs(‘Host’,array(‘id’=>$this->get(‘hosts’)),‘imageID’) as a whole is telling it to get the subobject IDs from ‘Host’ following the condition that they have the same GroupIDs assigned and also the subobject ID(s) of imageID based on qualifying as same groupID. It is then counting the number of each subobject IDs that resulted for ‘hosts’ and ‘imageID.’

                  Note: I’m under the impression this would be outputting in a format like ([hosts] => 2 [imageID] =>1).

                  return specifies what follows as evaluating to either true or false.

                  count($images) is using the count function on array that was outputted from above.

                  Note: it appears that using count on an array like it is here will count the entire array as a whole, which is always going to result in an output of 1.

                  count($images) == 1 is a validation that the number of images being used is equal to one.

                  && ties on an additional validation qualifier check

                  $images[0] is referencing the array output and setting the key to 0.

                  Note: from what I’ve been able to find, non-associative arrays automatically use the next integer value in the key sequence, starting at 0, for key if you do not provide one. Non-associative arrays also increment by 1 starting with the value 0, thus key 0 is adding a value 1 on. I’m understanding it as taking the value “2”, since it’s the largest of the two values in the output array and then incrementing it by one.

                  $images[0] == $this->getHostCount() is validating that the number of hosts found by $images array is equal to that found by the getHostCount() function specified in group.class.php

                  return (count($images) == 1 && $images[0] == $this->getHostCount()); as a whole this is validating that both the number of images is equal to one and that the number of hosts match and will return true if both are true or false if either fail.

                  Let me know your thoughts on my logic – I’m just interested in PHP after looking at this and want to better understand exactly what is occurring.

                  Thanks,
                  JG

                  1 Reply Last reply Reply Quote 0
                  • J
                    jgurka @Tom Elliott
                    last edited by Jan 29, 2016, 8:45 PM

                    @Tom-Elliott

                    Just had a chance to try out your latest revision – working like a charm. 👍

                    After writing all that up and re-reading your post, I get what you’re saying now. Really, all you’re doing is retrieving two sets of items:

                    1. ID of the manager
                    2. IDs of all images in the specified group

                    Since ‘Host’ isn’t included in the following array call (where array_count_values is now located), it is only counting the values that it pulled from imageID that are members of the group. It then counts up how many of each imageID there is (should only be one) and sets the variable equal to that.

                    I also see what you’re saying about $array[0] not being an actual array but the output number now that I can see that you’re really only interested in counting imageIDs – not multiple items like I thought.

                    Thanks for the explanation & fix!

                    T 1 Reply Last reply Jan 29, 2016, 10:04 PM Reply Quote 2
                    • H
                      Hanz @Thiago
                      last edited by Jan 29, 2016, 9:32 PM

                      This post is deleted!
                      1 Reply Last reply Reply Quote 0
                      • T
                        Tom Elliott @jgurka
                        last edited by Jan 29, 2016, 10:04 PM

                        @jgurka I’m willing to help you understand how the classes and what not operate within fog, and would also help with php in general. I’d more prefer to discuss that over chats as I’m sure we don’t want 4028, people passing out at their keyboards with glossed over eyes from forum posts describing the little details and intricacies.

                        Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

                        Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

                        Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

                        1 Reply Last reply Reply Quote 0
                        • 1
                        • 2
                        • 2 / 2
                        2 / 2
                        • First post
                          24/25
                          Last post

                        198

                        Online

                        12.0k

                        Users

                        17.3k

                        Topics

                        155.2k

                        Posts
                        Copyright © 2012-2024 FOG Project