/** * determine best host candidate prior to deploying a lab * * @return int|bool host id | FALSE on error */ function ace_db_get_best_host() { $host_table = ace_db_get_active_host_table(); $vcpu_per_thread = 4; $lab['vcpu'] = 6; $lab['memory'] = 5.5; $lab['storage'] = 42; $winning_host = NULL; #create a shortlist of viable hosts $host_shortlist = array(); foreach ($host_table as $host) { # number of labs this host can support $host_max_labs_by_vcpu = intval($host['threads'] * $vcpu_per_thread / $lab['vcpu']); $host_max_labs_by_memory = intval($host['memory'] / $lab['memory']); $host_max_labs_by_storage = intval($host['storage'] / $lab['storage']); $host_max_labs = min($host_max_labs_by_vcpu, $host_max_labs_by_memory, $host_max_labs_by_storage); # number of labs currently assigned to this host $lab_table = ace_host_get_lab_table($host['id']); //if ($lab_table === FALSE) { if (!is_array($lab_table)) { $use_percentage = 0; $host_shortlist[] = array('id' => $host['id'], 'percentage' => $use_percentage); } else { $host_lab_count = count($lab_table); # usage as percentage if ($host_lab_count < $host_max_labs) { $use_percentage = intval(ceil($host_lab_count / $host_max_labs * 100)); $host_shortlist[] = array('id' => $host['id'], 'percentage' => $use_percentage); } else { $use_percentage = 100; $host_shortlist[] = array('id' => $host['id'], 'percentage' => $use_percentage); } } } # apply algorithm to determine host with lowest use_percentage if (count($host_shortlist) > 0) { $lowest_percentage = 100; foreach ($host_shortlist as $host) { if ($host['percentage'] < $lowest_percentage) { $lowest_percentage = $host['percentage']; $best_host_id = intval($host['id']); } } if ($lowest_percentage == 100) { $best_host_id = FALSE; } } else { $best_host_id = FALSE; } return !empty($best_host_id) ? $best_host_id : FALSE; }
/** * returns a table of active known virtualization hosts * * @api * * @return array|bool active host table | FALSE on error */ function ace_get_active_hosts() { return ace_db_get_active_host_table(); }