Exemple #1
0
 $arHead['resource_id'] = array();
 $arHead['resource_id']['title'] = 'ID';
 $arHead['resource_hostname'] = array();
 $arHead['resource_hostname']['title'] = 'Name';
 $arHead['resource_ip'] = array();
 $arHead['resource_ip']['title'] = 'Ip-address';
 $arHead['resource_mac'] = array();
 $arHead['resource_mac']['title'] = 'Mac-address';
 $arHead['resource_load'] = array();
 $arHead['resource_load']['title'] = 'Load';
 $arBody = array();
 $resource = new resource();
 // find active, error + available
 $in_res_table = 0;
 $res_load_array = array();
 $resource_list = $resource->get_list();
 foreach ($resource_list as $res) {
     $res_id = $res['resource_id'];
     $g_resource = new resource();
     $g_resource->get_instance_by_id($res_id);
     // start gathering
     $res_all++;
     // resource load
     // is idle or active ?
     if ("{$g_resource->imageid}" == "1" && "{$g_resource->state}" == "active") {
         // idle
         $res_available++;
     } else {
         if ("{$g_resource->state}" == "active") {
             // active
             $res_active++;
 function get_response()
 {
     $response = $this->response;
     $form = $response->get_form($this->actions_name, 'edit');
     $id = $this->apliance_id;
     $submit = $form->get_elements('submit');
     $submit->handler = 'onclick="wait();"';
     $form->add($submit, 'submit');
     $submit = $form->get_elements('cancel');
     $submit->handler = 'onclick="cancel();"';
     $form->add($submit, 'cancel');
     $appliance = new appliance();
     $appliance->get_instance_by_id($id);
     $resource = new resource();
     $list = $resource->get_list();
     $cpus[0] = array(0, $this->lang['option_auto']);
     $cspe[0] = array(0, $this->lang['option_auto']);
     $cmod[0] = array(0, $this->lang['option_auto']);
     $nics[0] = array(0, $this->lang['option_auto']);
     $memt[0] = array(0, $this->lang['option_auto']);
     $swap[0] = array(0, $this->lang['option_auto']);
     foreach ($list as $v) {
         $resource->get_instance_by_id($v['resource_id']);
         $c = $resource->cpunumber;
         $cs = $resource->cpuspeed;
         $cm = $resource->cpumodel;
         $n = $resource->nics;
         $m = $resource->memtotal;
         $s = $resource->swaptotal;
         if (isset($c) && $c != '0') {
             $cpus[$c] = array($c, $c);
         }
         if (isset($cs) && $cs != '0') {
             $cspe[$cs] = array($cs, $cs);
         }
         if (isset($cm) && $cm != '0' && $cm !== '') {
             $cmod[$cm] = array($cm, $cm);
         }
         if (isset($n) && $n != '0') {
             $nics[$n] = array($n, $n);
         }
         if (isset($m) && $m != '0') {
             $memt[$m] = array($m, $m);
         }
         if (isset($s) && $s != '0') {
             $swap[$s] = array($s, $s);
         }
     }
     ksort($cpus, SORT_NUMERIC);
     ksort($cspe, SORT_NUMERIC);
     ksort($cmod, SORT_STRING);
     ksort($nics, SORT_NUMERIC);
     ksort($memt, SORT_NUMERIC);
     ksort($swap, SORT_NUMERIC);
     $d['cpus']['label'] = $this->lang['form_cpus'];
     $d['cpus']['object']['type'] = 'htmlobject_select';
     $d['cpus']['object']['attrib']['index'] = array(0, 1);
     $d['cpus']['object']['attrib']['name'] = 'appliance_cpunumber';
     $d['cpus']['object']['attrib']['options'] = $cpus;
     $d['cpus']['object']['attrib']['selected'] = array($appliance->cpunumber);
     $d['cpuspeed']['label'] = $this->lang['form_cpuspeed'];
     $d['cpuspeed']['object']['type'] = 'htmlobject_select';
     $d['cpuspeed']['object']['attrib']['index'] = array(0, 1);
     $d['cpuspeed']['object']['attrib']['name'] = 'appliance_cpuspeed';
     $d['cpuspeed']['object']['attrib']['options'] = $cspe;
     $d['cpuspeed']['object']['attrib']['selected'] = array($appliance->cpuspeed);
     $d['cpumodel']['label'] = $this->lang['form_cpumodel'];
     $d['cpumodel']['object']['type'] = 'htmlobject_select';
     $d['cpumodel']['object']['attrib']['index'] = array(0, 1);
     $d['cpumodel']['object']['attrib']['name'] = 'appliance_cpumodel';
     $d['cpumodel']['object']['attrib']['options'] = $cmod;
     $d['cpumodel']['object']['attrib']['selected'] = array($appliance->cpumodel);
     $d['nics']['label'] = $this->lang['form_nics'];
     $d['nics']['object']['type'] = 'htmlobject_select';
     $d['nics']['object']['attrib']['index'] = array(0, 1);
     $d['nics']['object']['attrib']['name'] = 'appliance_nics';
     $d['nics']['object']['attrib']['options'] = $nics;
     $d['nics']['object']['attrib']['selected'] = array($appliance->nics);
     $d['memory']['label'] = $this->lang['form_memory'];
     $d['memory']['object']['type'] = 'htmlobject_select';
     $d['memory']['object']['attrib']['index'] = array(0, 1);
     $d['memory']['object']['attrib']['name'] = 'appliance_memtotal';
     $d['memory']['object']['attrib']['options'] = $memt;
     $d['memory']['object']['attrib']['selected'] = array($appliance->memtotal);
     $d['swap']['label'] = $this->lang['form_swap'];
     $d['swap']['object']['type'] = 'htmlobject_select';
     $d['swap']['object']['attrib']['index'] = array(0, 1);
     $d['swap']['object']['attrib']['name'] = 'appliance_swaptotal';
     $d['swap']['object']['attrib']['options'] = $swap;
     $d['swap']['object']['attrib']['selected'] = array($appliance->swaptotal);
     $resource = new resource();
     $resource_hostname = '';
     if (isset($appliance->resources) && $appliance->resources !== '') {
         if ($appliance->resources >= 0) {
             $res = $resource->get_instance_by_id($appliance->resources);
             $resource_hostname = $res->hostname;
         } else {
             $resource_hostname = 'auto-select';
         }
     }
     $a = $response->html->a();
     $a->name = '';
     #$a->label = '<img src="'.$this->controller->get('baseurl').'/img/resource.png">&#160;'.sprintf($this->lang['action_resource'], $resource_hostname);
     $a->label = $resource_hostname;
     $a->css = "manage";
     $a->title = sprintf($this->lang['action_resource'], $resource_hostname);
     $a->href = $response->get_url($this->actions_name, 'step2');
     $d['resource']['label'] = $this->lang['form_resource'];
     $d['resource']['object'] = $a;
     $img = new image();
     $img = $img->get_instance_by_id($appliance->imageid);
     $a = $response->html->a();
     $a->name = '';
     #$a->label = '<img src="'.$this->controller->get('baseurl').'/img/image.png">&#160;'.sprintf($this->lang['action_image'], $img->name) ;
     $a->label = $img->name;
     $a->css = "manage";
     $a->title = sprintf($this->lang['action_image'], $img->name);
     $a->href = $response->get_url($this->actions_name, 'step3');
     $d['image']['label'] = $this->lang['form_image'];
     $d['image']['object'] = $a;
     $kern = new kernel();
     $kern = $kern->get_instance_by_id($appliance->kernelid);
     $a = $response->html->a();
     $a->name = '';
     #$a->label = '<img src="'.$this->controller->get('baseurl').'/img/image.png">&#160;'.sprintf($this->lang['action_image'], $img->name) ;
     $a->label = $kern->name;
     $a->css = "manage";
     $a->title = sprintf($this->lang['action_kernel'], $kern->name);
     $a->href = $response->get_url($this->actions_name, 'step4');
     $d['kernel']['label'] = $this->lang['form_kernel'];
     $d['kernel']['object'] = $a;
     $virtualization = new virtualization();
     if (isset($appliance->resources) && $appliance->resources !== '') {
         $resource->get_instance_by_id($appliance->resources);
     }
     $vl = array();
     $list = $virtualization->get_list();
     foreach ($list as $v) {
         if (strpos($v['label'], ' VM') === false) {
             $vl[] = array($v['label'], $v['value']);
         } else {
             if ($v['value'] === $resource->vtype) {
                 $hide_virtualization = true;
                 break;
             }
         }
     }
     asort($vl);
     if (isset($hide_virtualization)) {
         $virtualization->get_instance_by_id($resource->vtype);
         $div = $this->response->html->div();
         $div->name = '';
         $div->add($virtualization->name);
         $d['virtualization']['label'] = $this->lang['form_virtualization'];
         $d['virtualization']['object'] = $div;
     } else {
         $d['virtualization']['label'] = $this->lang['form_virtualization'];
         $d['virtualization']['object']['type'] = 'htmlobject_select';
         $d['virtualization']['object']['attrib']['index'] = array(1, 0);
         $d['virtualization']['object']['attrib']['name'] = 'appliance_virtualization';
         $d['virtualization']['object']['attrib']['options'] = $vl;
         $d['virtualization']['object']['attrib']['selected'] = array($appliance->virtualization);
     }
     $d['capabilities']['label'] = $this->lang['form_capabilities'];
     $d['capabilities']['object']['type'] = 'htmlobject_input';
     $d['capabilities']['object']['attrib']['type'] = 'text';
     $d['capabilities']['object']['attrib']['name'] = 'appliance_capabilities';
     $d['capabilities']['object']['attrib']['value'] = $appliance->capabilities;
     $d['capabilities']['object']['attrib']['maxlength'] = 1000;
     $d['comment']['label'] = $this->lang['form_comment'];
     $d['comment']['validate']['regex'] = $this->openqrm->regex['comment'];
     $d['comment']['validate']['errormsg'] = sprintf($this->lang['error_comment'], $this->openqrm->regex['comment']);
     $d['comment']['object']['type'] = 'htmlobject_textarea';
     $d['comment']['object']['attrib']['name'] = 'appliance_comment';
     $d['comment']['object']['attrib']['value'] = $appliance->comment;
     $d['comment']['object']['attrib']['maxlength'] = 255;
     $form->add($d);
     $response->form = $form;
     return $response;
 }
 function find_existing_resource($cr_appliance, $cr_virtualization, $clouduser_id)
 {
     $cp_conf = new cloudconfig();
     $show_resource_pools = $cp_conf->get_value(25);
     // resource_pools enabled ?
     // resource pooling enabled ?
     if (strcmp($show_resource_pools, "true")) {
         // disabled
         $cr_appliance->find_resource($cr_virtualization);
         $cr_appliance->get_instance_by_id($cr_appliance->id);
         if ($cr_appliance->resources == -1) {
             return false;
         } else {
             return true;
         }
     } else {
         $found_new_resource = 0;
         $new_resource_id = -1;
         $resource_tmp = new resource();
         $resource_list = array();
         $resource_list = $resource_tmp->get_list();
         $resource = new resource();
         foreach ($resource_list as $index => $resource_db) {
             $resource->get_instance_by_id($resource_db["resource_id"]);
             if ($resource->id > 0 && "{$resource->imageid}" == "1" && "{$resource->state}" == "active") {
                 $new_resource_id = $resource->id;
                 // check resource-type
                 $restype_id = $resource->vtype;
                 if ($restype_id == $cr_virtualization) {
                     // check the rest of the required parameters for the appliance
                     // cpu-number
                     if (strlen($cr_appliance->cpunumber) && strcmp($cr_appliance->cpunumber, "0")) {
                         if (strcmp($cr_appliance->cpunumber, $resource->cpunumber)) {
                             $this->_event->log("find_existing_resource", $_SERVER['REQUEST_TIME'], 5, "cloudappliance.class.php", "Found new resource {$resource->id} type {$cr_virtualization} for appliance {$cr_appliance->name} but it has the wrong CPU-number, skipping.", "", "", 0, 0, 0);
                             continue;
                         }
                     }
                     // memtotal
                     if (strlen($cr_appliance->memtotal) && strcmp($cr_appliance->memtotal, "0")) {
                         if (strcmp($cr_appliance->memtotal, $resource->memtotal)) {
                             $this->_event->log("find_existing_resource", $_SERVER['REQUEST_TIME'], 5, "cloudappliance.class.php", "Found new resource {$resource->id} type {$cr_virtualization} for appliance {$cr_appliance->name} but it has the wrong amount of Memory, skipping.", "", "", 0, 0, 0);
                             continue;
                         }
                     }
                     // nics
                     if (strlen($cr_appliance->nics) && strcmp($cr_appliance->nics, "0")) {
                         if (strcmp($cr_appliance->nics, $resource->nics)) {
                             $this->_event->log("find_existing_resource", $_SERVER['REQUEST_TIME'], 5, "cloudappliance.class.php", "Found new resource {$resource->id} type {$cr_virtualization} for appliance {$cr_appliance->name} but it has the wrong nic count, skipping.", "", "", 0, 0, 0);
                             continue;
                         }
                     }
                     // check to which user group the resource belongs to
                     $private_resource = new cloudrespool();
                     $private_resource->get_instance_by_resource($new_resource_id);
                     // is this resource configured in the resource pools ?
                     if (!strlen($private_resource->id)) {
                         $this->_event->log("find_existing_resource", $_SERVER['REQUEST_TIME'], 5, "cloudappliance.class.php", "Found new resource " . $resource->id . " type " . $cr_virtualization . " for appliance " . $cr_appliance->name . " but it not configured in the a resource pool, skipping.", "", "", 0, 0, 0);
                         continue;
                     }
                     if ($private_resource->cg_id >= 0) {
                         $cloud_user = new clouduser();
                         $cloud_user->get_instance_by_id($clouduser_id);
                         $cloud_user_group = new cloudusergroup();
                         $cloud_user_group->get_instance_by_id($cloud_user->cg_id);
                         // does it really belongs to the users group ?
                         if ($private_resource->cg_id != $cloud_user_group->id) {
                             // resource does not belong to the users group
                             $this->_event->log("find_existing_resource", $_SERVER['REQUEST_TIME'], 5, "cloudappliance.class.php", "Found new resource " . $resource->id . " type " . $cr_virtualization . " for appliance " . $cr_appliance->name . " but it is does not belong to the users resource pool, skipping.", "", "", 0, 0, 0);
                             continue;
                         }
                     } else {
                         $this->_event->log("find_existing_resource", $_SERVER['REQUEST_TIME'], 5, "cloudappliance.class.php", "Found new resource " . $resource->id . " type " . $cr_virtualization . " for appliance " . $cr_appliance->name . " but it is marked as hidden, skipping.", "", "", 0, 0, 0);
                         continue;
                     }
                     // if we have reached this point we have found an existing resource fitting to cr + resource pool
                     $found_new_resource = 1;
                     $this->_event->log("find_existing_resource", $_SERVER['REQUEST_TIME'], 5, "cloudappliance.class.php", "Found new resource {$resource->id} type {$cr_virtualization} for appliance {$cr_appliance->name} .", "", "", 0, 0, 0);
                     break;
                 }
             }
         }
         // in case no resources are available log another ha-error event !
         if ($found_new_resource == 0) {
             $this->_event->log("find_existing_resource", $_SERVER['REQUEST_TIME'], 4, "cloudappliance.class.php", "Could not find a free resource type {$cr_virtualization} for appliance {$cr_appliance->name} !", "", "", 0, 0, 0);
             return false;
         }
         // if we find an resource which fits to the appliance we update it
         $appliance_fields = array();
         $appliance_fields['appliance_resources'] = $new_resource_id;
         $cr_appliance->update($cr_appliance->id, $appliance_fields);
         return true;
     }
 }
Exemple #4
0
 function statistics()
 {
     $resources_all = 0;
     $resources_active = 0;
     $resources_available = 0;
     $dc_load_overall = 0;
     $appliance_load_overall = 0;
     $appliance_active = 0;
     $storage_load_overall = 0;
     $storage_active = 0;
     $cpu_total = 0;
     $mem_used = 0;
     $mem_total = 0;
     // run only each minute
     $db = openqrm_get_db_connection();
     $rs = $db->Execute("select MAX(datacenter_id) from {$this->_db_table}");
     foreach ($rs as $index => $dc) {
         if (isset($dc['MAX(datacenter_id)'])) {
             $this->last_statistics = $dc['MAX(datacenter_id)'];
         } else {
             if (isset($dc['max'])) {
                 $this->last_statistics = $dc['max'];
             }
         }
     }
     // get an array of resources which are assigned to an appliance
     $appliance_resources_array = array();
     $appliance = new appliance();
     $appliance_list = $appliance->get_all_ids();
     foreach ($appliance_list as $app) {
         $app_id = $app['appliance_id'];
         $g_appliance = new appliance();
         $g_appliance->get_instance_by_id($app_id);
         $g_appliance_resource = $g_appliance->resources;
         if (!strcmp($g_appliance->state, "active") || $g_appliance_resource == 0) {
             if ($g_appliance_resource != "-1") {
                 $appliance_resources_array[] .= $g_appliance_resource;
             }
         }
     }
     // get an array of resources which are a storage server
     $storage_resources_array = array();
     $storage = new storage();
     $storage_list = $storage->get_list();
     foreach ($storage_list as $store) {
         $storage_id = $store['value'];
         $g_storage = new storage();
         $g_storage->get_instance_by_id($storage_id);
         $g_storage_resource = $g_storage->resource_id;
         $storage_resources_array[] .= $g_storage_resource;
     }
     $resource = new resource();
     $resource_list = $resource->get_list();
     foreach ($resource_list as $res) {
         $res_id = $res['resource_id'];
         //echo "!! res_id $res_id <br>";
         $g_resource = new resource();
         $g_resource->get_instance_by_id($res_id);
         // start gathering
         $resources_all++;
         $cpu_total = $cpu_total + $g_resource->cpunumber;
         $mem_used = $mem_used + $g_resource->memused;
         $mem_total = $mem_total + $g_resource->memtotal;
         // resource load
         if ("{$g_resource->imageid}" == "1" && "{$g_resource->state}" == "active") {
             // idle
             $resources_available++;
         } else {
             if ("{$g_resource->state}" == "active") {
                 // active
                 $resources_active++;
                 $dc_load_overall = $dc_load_overall + $g_resource->load;
                 // is storage ?
                 if (in_array($g_resource->id, $storage_resources_array)) {
                     $storage_active++;
                     $storage_load_overall = $storage_load_overall + $g_resource->load;
                 }
                 // is appliance ?
                 if (in_array($g_resource->id, $appliance_resources_array)) {
                     $appliance_active++;
                     $appliance_load_overall = $appliance_load_overall + $g_resource->load;
                 }
             }
         }
     }
     if ($resources_active != 0) {
         $dc_load_overall = $dc_load_overall / $resources_active;
         $dc_load_overall = number_format($dc_load_overall, 2, '.', '');
     }
     if ($appliance_active != 0) {
         $appliance_load_overall = $appliance_load_overall / $appliance_active;
         $appliance_load_overall = number_format($appliance_load_overall, 2, '.', '');
     }
     if ($storage_active != 0) {
         $storage_load_overall = $storage_load_overall / $storage_active;
         $storage_load_overall = number_format($storage_load_overall, 2, '.', '');
     }
     $datacenter_fields = array();
     $datacenter_fields['datacenter_load_overall'] = $dc_load_overall;
     $datacenter_fields['datacenter_load_server'] = $appliance_load_overall;
     $datacenter_fields['datacenter_load_storage'] = $storage_load_overall;
     $datacenter_fields['datacenter_cpu_total'] = $cpu_total;
     $datacenter_fields['datacenter_mem_total'] = $mem_total;
     $datacenter_fields['datacenter_mem_used'] = $mem_used;
     $stats_count = $this->get_count();
     if ($stats_count >= $this->resolution) {
         $rs = $db->Execute("select MIN(datacenter_id) from {$this->_db_table}");
         foreach ($rs as $index => $dc) {
             if (isset($dc['MIN(datacenter_id)'])) {
                 $this->oldest_statistics_id = $dc['MIN(datacenter_id)'];
             } else {
                 if (isset($dc['min'])) {
                     $this->oldest_statistics_id = $dc['min'];
                 }
             }
         }
         $rs = $db->Execute("delete from {$this->_db_table} where datacenter_id={$this->oldest_statistics_id}");
         $stats_count = $this->get_count();
     }
     $datacenter_fields['datacenter_id'] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
     $result = $db->AutoExecute($this->_db_table, $datacenter_fields, 'INSERT');
     if (!$result) {
         $this->event->log("add", $_SERVER['REQUEST_TIME'], 2, "datacenter.class.php", "Failed updating datacenter " . $datacenter_fields['datacenter_id'], "", "", 0, 0, 0);
     }
 }
 function dc_status()
 {
     // number of idle systems
     $resources_all = 0;
     // active deployed resources
     $resources_active = 0;
     // resources in error state
     $resources_error = 0;
     // physical resources
     $resources_physical = 0;
     // virtual resources
     $resources_virtual = 0;
     // number of idle systems
     $resources_available = 0;
     // physical resource available
     $resources_available_physical = 0;
     // virtal resource available
     $resources_available_virtual = 0;
     // overall load
     $dc_load_overall = 0;
     // active appliance load
     $appliance_load_overall = 0;
     // peak in appliance load
     $appliance_load_peak = 0;
     // active appliances
     $appliance_active = 0;
     // active appliance with resource in error state
     $appliance_error = 0;
     // storage load
     $storage_load_overall = 0;
     // storage peak
     $storage_load_peak = 0;
     // active storages
     $storage_active = 0;
     // storage with resource in error state
     $storage_error = 0;
     // get an array of resources which are assigned to an appliance
     $appliance_resources_array = array();
     $appliance = new appliance();
     $appliance_list = $appliance->get_all_ids();
     foreach ($appliance_list as $app) {
         $app_id = $app['appliance_id'];
         $g_appliance = new appliance();
         $g_appliance->get_instance_by_id($app_id);
         $g_appliance_resource = $g_appliance->resources;
         if (!strcmp($g_appliance->state, "active") || $g_appliance_resource == 0) {
             if ($g_appliance_resource != "-1") {
                 $appliance_resources_array[] .= $g_appliance_resource;
             }
         }
     }
     // get an array of resources which are a storage server
     $storage_resources_array = array();
     $storage = new storage();
     $storage_list = $storage->get_list();
     foreach ($storage_list as $store) {
         $storage_id = $store['value'];
         $g_storage = new storage();
         $g_storage->get_instance_by_id($storage_id);
         $g_storage_resource = $g_storage->resource_id;
         $storage_resources_array[] .= $g_storage_resource;
     }
     $restype = 0;
     $resource = new resource();
     $resource_list = $resource->get_list();
     foreach ($resource_list as $res) {
         $res_id = $res['resource_id'];
         //echo "!! res_id $res_id <br>";
         $g_resource = new resource();
         $g_resource->get_instance_by_id($res_id);
         // start gathering
         $resources_all++;
         // physical or virtual ?
         if (strlen($g_resource->vtype) && $g_resource->vtype != "NULL") {
             $virtualization = new virtualization();
             $virtualization->get_instance_by_id($g_resource->vtype);
             if (strstr($virtualization->type, "-vm")) {
                 // virtual
                 $resources_virtual++;
                 $restype = 1;
             } else {
                 // physical
                 $resources_physical++;
                 $restype = 0;
             }
         } else {
             // we treat unknown system types as physical
             $resources_physical++;
             $restype = 0;
         }
         // resource load
         // is idle or active ?
         if ("{$g_resource->imageid}" == "1" && "{$g_resource->state}" == "active") {
             // idle
             $resources_available++;
             // virtual or physical ?
             if ($restype == 0) {
                 $resources_available_physical++;
             } else {
                 $resources_available_virtual++;
             }
         } else {
             if ("{$g_resource->state}" == "active") {
                 // active
                 $resources_active++;
                 $dc_load_overall = $dc_load_overall + $g_resource->load;
                 // is storage ?
                 if (in_array($g_resource->id, $storage_resources_array)) {
                     $storage_active++;
                     $storage_load_overall = $storage_load_overall + $g_resource->load;
                     // is peak ?
                     if ($g_resource->load > $storage_load_peak) {
                         $storage_load_peak = $g_resource->load;
                     }
                 }
                 // is appliance ?
                 if (in_array($g_resource->id, $appliance_resources_array)) {
                     $appliance_active++;
                     $appliance_load_overall = $appliance_load_overall + $g_resource->load;
                     // is peak ?
                     if ($g_resource->load > $appliance_load_peak) {
                         $appliance_load_peak = $g_resource->load;
                     }
                 }
             } else {
                 if ("{$g_resource->state}" == "error") {
                     // error
                     $resources_error++;
                     // is storage ?
                     if (in_array($g_resource->id, $storage_resources_array)) {
                         $storage_error++;
                     }
                     // is appliance ?
                     if (in_array($g_resource->id, $appliance_resources_array)) {
                         $appliance_error++;
                     }
                 }
             }
         }
     }
     // end of gathering
     // divide with number of active resources, appliances + storages
     if ($resources_active != 0) {
         $dc_load_overall = $dc_load_overall / $resources_active;
         $dc_load_overall = number_format($dc_load_overall, 2, '.', '');
     }
     if ($appliance_active != 0) {
         $appliance_load_overall = $appliance_load_overall / $appliance_active;
         $appliance_load_overall = number_format($appliance_load_overall, 2, '.', '');
     }
     if ($storage_active != 0) {
         $storage_load_overall = $storage_load_overall / $storage_active;
         $storage_load_overall = number_format($storage_load_overall, 2, '.', '');
     }
     echo "{$dc_load_overall},{$storage_load_overall},{$storage_load_peak},{$appliance_load_overall},{$appliance_load_peak},{$resources_all},{$resources_physical},{$resources_virtual},{$resources_available},{$resources_available_physical},{$resources_available_virtual},{$resources_error},{$appliance_error},{$storage_error}";
     exit(0);
 }
Exemple #6
0
 function find_resource($appliance_virtualization)
 {
     global $event;
     $found_new_resource = 0;
     $virtualization = new virtualization();
     $virtualization->get_instance_by_id($appliance_virtualization);
     $event->log("find_resource", $_SERVER['REQUEST_TIME'], 5, "appliance.class.php", "Trying to find a new resource type {$virtualization->name} for appliance {$this->name} .", "", "", 0, 0, 0);
     // we are searching for physical systems when we want to deploy a virtualization host
     if (strstr($virtualization->name, "Host")) {
         $appliance_virtualization = 1;
     }
     $resource_tmp = new resource();
     $resource_list = array();
     $resource_list = $resource_tmp->get_list();
     $resource = new resource();
     foreach ($resource_list as $index => $resource_db) {
         $resource->get_instance_by_id($resource_db["resource_id"]);
         if ($resource->id > 0 && "{$resource->imageid}" == "1" && "{$resource->state}" == "active") {
             $new_resource_id = $resource->id;
             // check resource-type
             $restype_id = $resource->vtype;
             if ($restype_id == $appliance_virtualization) {
                 // check the rest of the required parameters for the appliance
                 // cpu-number
                 if (strlen($this->cpunumber) && strcmp($this->cpunumber, "0")) {
                     if (strcmp($this->cpunumber, $resource->cpunumber)) {
                         $event->log("find_resource", $_SERVER['REQUEST_TIME'], 5, "appliance.class.php", "Found new resource {$resource->id} type {$virtualization->name} for appliance {$this->name} but it has the wrong CPU-number, skipping.", "", "", 0, 0, 0);
                         continue;
                     }
                 }
                 // cpu-speed
                 if (strlen($this->cpuspeed) && strcmp($this->cpuspeed, "0")) {
                     if (strcmp($this->cpuspeed, $resource->cpuspeed)) {
                         $event->log("find_resource", $_SERVER['REQUEST_TIME'], 5, "appliance.class.php", "Found new resource {$resource->id} type {$virtualization->name} for appliance {$this->name} but it has the wrong CPU-speed, skipping.", "", "", 0, 0, 0);
                         continue;
                     }
                 }
                 // cpu-model
                 if (strlen($this->cpumodel) && strcmp($this->cpumodel, "0")) {
                     if (strcmp($this->cpumodel, $resource->cpumodel)) {
                         $event->log("find_resource", $_SERVER['REQUEST_TIME'], 5, "appliance.class.php", "Found new resource {$resource->id} type {$virtualization->name} for appliance {$this->name} but it has the wrong CPU-model, skipping.", "", "", 0, 0, 0);
                         continue;
                     }
                 }
                 // memtotal
                 if (strlen($this->memtotal) && strcmp($this->memtotal, "0")) {
                     if (strcmp($this->memtotal, $resource->memtotal)) {
                         $event->log("find_resource", $_SERVER['REQUEST_TIME'], 5, "appliance.class.php", "Found new resource {$resource->id} type {$virtualization->name} for appliance {$this->name} but it has the wrong amount of Memory, skipping.", "", "", 0, 0, 0);
                         continue;
                     }
                 }
                 // swaptotal
                 if (strlen($this->swaptotal) && strcmp($this->swaptotal, "0")) {
                     if (strcmp($this->swaptotal, $resource->swaptotal)) {
                         $event->log("find_resource", $_SERVER['REQUEST_TIME'], 5, "appliance.class.php", "Found new resource {$resource->id} type {$virtualization->name} for appliance {$this->name} but it has the wrong amount of Swap, skipping.", "", "", 0, 0, 0);
                         continue;
                     }
                 }
                 // nics
                 if (strlen($this->nics) && strcmp($this->nics, "0")) {
                     if (strcmp($this->nics, $resource->nics)) {
                         $event->log("find_resource", $_SERVER['REQUEST_TIME'], 5, "appliance.class.php", "Found new resource {$resource->id} type {$virtualization->name} for appliance {$this->name} but it has the wrong nic count, skipping.", "", "", 0, 0, 0);
                         continue;
                     }
                 }
                 $found_new_resource = 1;
                 $event->log("find_resource", $_SERVER['REQUEST_TIME'], 5, "appliance.class.php", "Found new resource {$resource->id} type {$virtualization->name} for appliance {$this->name} .", "", "", 0, 0, 0);
                 break;
             }
         }
     }
     // in case no resources are available log another ha-error event !
     if ($found_new_resource == 0) {
         $event->log("find_resource", $_SERVER['REQUEST_TIME'], 4, "appliance.class.php", "Could not find a free resource type {$virtualization->name} for appliance {$this->name} !", "", "", 0, 0, 0);
         return $this;
     }
     // if we find an resource which fits to the appliance we update it
     $appliance_fields = array();
     $appliance_fields['appliance_resources'] = $new_resource_id;
     $this->update($this->id, $appliance_fields);
     return $this;
 }
 function get_response()
 {
     $response = $this->response;
     $form = $response->get_form($this->actions_name, 'step2');
     $submit = $form->get_elements('submit');
     $submit->handler = 'onclick="wait();"';
     $form->add($submit, 'submit');
     $submit = $form->get_elements('cancel');
     $submit->handler = 'onclick="cancel();"';
     $form->add($submit, 'cancel');
     $resource = new resource();
     $list = $resource->get_list();
     $resources = array();
     foreach ($list as $value) {
         $id = $value['resource_id'];
         $resource->get_instance_by_id($id);
         $virtualization_id = $resource->vtype;
         if ($resource->id == 0) {
             $virtualization_id = 1;
         }
         $virtualization = new virtualization();
         $virtualization->get_instance_by_id($virtualization_id);
         $resources[] = array($id, '' . $resource->id . ' / ' . $resource->ip . ' ' . $resource->hostname . ' (' . $virtualization->name . ')');
     }
     asort($resources);
     // handle appliance is new or edited
     $selected = $this->response->html->request()->get('resource_id');
     if ($selected === '' && isset($this->appliance->resources)) {
         $selected = $this->appliance->resources;
     }
     $d['resource']['label'] = $this->lang['form_resource'];
     $d['resource']['required'] = true;
     $d['resource']['object']['type'] = 'htmlobject_select';
     $d['resource']['object']['attrib']['index'] = array(0, 1);
     $d['resource']['object']['attrib']['id'] = 'resource';
     $d['resource']['object']['attrib']['name'] = 'resource';
     $d['resource']['object']['attrib']['options'] = $resources;
     $d['resource']['object']['attrib']['selected'] = array($selected);
     $form->add($d);
     $response->form = $form;
     return $response;
 }