Uploaded image for project: 'VCL'
  1. VCL
  2. VCL-320

random selection of computer for reservations

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 2.2
    • web gui (frontend)
    • None

    Description

      Xianqing Yu contributed (via email to vcl-dev list) a modified version of allocComputer that randomly picks a computer from the array of available computers instead of picking the first on the in the list. Here is his function:

      ////////////////////////////////////////////////////////////////////////////////
      ///
      /// \fn allocComputer($blockids, $currentids, $computerids, $start,
      /// $nowfuture)
      ///
      /// \param $blockids - array of computer ids
      /// \param $currentids - array of computer ids
      /// \param $computerids - array of computer ids
      /// \param $start - start time in datetime format
      /// \param $nowfuture - "now" or "future"
      ///
      /// \return empty array if failed to allocate a computer; array with these keys
      /// on success:\n
      /// \b compid - id of computer\n
      /// \b mgmtid - id of management node for computer\n
      /// \b loaded - 0 or 1 - whether or not computer is loaded with desired image
      ///
      /// \brief determines a computer to use from $blockids, $currentids,
      /// and $computerids, looking at the arrays in that order and
      /// tries to allocate a management node for it
      ///
      ////////////////////////////////////////////////////////////////////////////////
      function allocComputer($blockids, $currentids, $computerids, $start,
      $nowfuture) {
      $ret = array();

      if (count($blockids) > 0)

      { $random_number = rand(0,count($blockids) - 1); while($blockids[$random_number] == null) $random_number = rand(0,count($blockids) - 1); $tp = $blockids[0]; $blockids[0] = $blockids[$random_number]; $blockids[$random_number] = $tp; # printArray($blockids); }

      foreach($blockids as $compid)

      { $mgmtnodeid = findManagementNode($compid, $start, $nowfuture); if($mgmtnodeid == 0) continue; $ret['compid'] = $compid; $ret['mgmtid'] = $mgmtnodeid; $ret['loaded'] = 1; return $ret; }

      if (count($currentids) > 0)
      { $random_number1 = rand(0,count($currentids) - 1); while($currentids[$random_number1] == null) $random_number1 = rand(0,count($currentids) - 1); $tp1 = $currentids[0]; $currentids[0] = $currentids[$random_number1]; $currentids[$random_number1] = $tp1; # printArray($currentids); }
      foreach($currentids as $compid) { $mgmtnodeid = findManagementNode($compid, $start, $nowfuture); if($mgmtnodeid == 0) continue; $ret['compid'] = $compid; $ret['mgmtid'] = $mgmtnodeid; $ret['loaded'] = 1; return $ret; }

      if (count($computerids) > 0)

      { $random_number2 = rand(0,count($computerids) - 1); while($computerids[$random_number2] == null) $random_number2 = rand(0,count($computerids) - 1); $tp2 = $computerids[0]; $computerids[0] = $computerids[$random_number2]; $computerids[$random_number2] = $tp2; # printArray($computerids); }

      foreach($computerids as $compid)

      { $mgmtnodeid = findManagementNode($compid, $start, $nowfuture); if($mgmtnodeid == 0) continue; $ret['compid'] = $compid; $ret['mgmtid'] = $mgmtnodeid; $ret['loaded'] = 0; return $ret; }

      return $ret;
      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            jfthomps Josh Thompson
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: