/** * better version * that will, in conjunction with other functions, allow (un)locking hosts * *@return bool|int|null */ function ace_db_get_best_host_2() { $best_host_id = NULL; $host_shortlist = array(); $host_table = ace_db_get_active_host_table(); if (is_array($host_table)) { foreach ($host_table as $host) { //$host_reservation_percentage = 0; $host_lab_quota = ace_db_host_get_quota($host['id']); if ($host_lab_quota !== FALSE && $host_lab_quota['labs'] != 0) { $lab_table = ace_db_host_get_lab_table($host['id']); if (is_array($lab_table)) { $host_lab_count = count($lab_table); $host_reservation_percentage = intval(ceil($host_lab_count / $host_lab_quota) * 100); } else { $host_reservation_percentage = 0; } $host_shortlist[] = array('id' => $host['id'], 'percentage' => $host_reservation_percentage); } } if (is_array($host_shortlist) && count($host_shortlist) > 0) { $lowest_reservation_percentage = 100; foreach ($host_shortlist as $host) { if ($host['percentage'] < $lowest_reservation_percentage) { $lowest_reservation_percentage = $host['percentage']; $best_host_id = intval($host['id']); } } if ($lowest_reservation_percentage = 100) { return FALSE; } } else { return FALSE; } } else { return FALSE; } return $best_host_id !== NULL ? $best_host_id : FALSE; }
/** * returns a table of labs for a given host * * @api * * @param int $host_id host id * * @return array|bool host lab table | FALSE on error */ function ace_host_get_lab_table($host_id) { return ace_db_host_get_lab_table($host_id); }