예제 #1
0
 function CloudRequestGetList($method_parameters)
 {
     global $event;
     $parameter_array = explode(',', $method_parameters);
     $mode = $parameter_array[0];
     $username = $parameter_array[1];
     $password = $parameter_array[2];
     $clouduser_name = $parameter_array[3];
     // check all user input
     for ($i = 0; $i <= 3; $i++) {
         if (!$this->check_param($parameter_array[$i])) {
             $event->log("cloudsoap->CloudRequestGetList", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Not allowing user-intput with special-characters : {$parameter_array[$i]}", "", "", 0, 0, 0);
             return;
         }
     }
     // check parameter count
     $parameter_count = count($parameter_array);
     if ($parameter_count != 4) {
         $event->log("cloudsoap->CloudRequestGetList", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Wrong parameter count {$parameter_count} ! Exiting.", "", "", 0, 0, 0);
         return;
     }
     // check authentication
     if (!$this->check_user($mode, $username, $password)) {
         $event->log("cloudsoap->CloudRequestGetList", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "User authentication failed (mode {$mode})", "", "", 0, 0, 0);
         return;
     }
     $clouduser = new clouduser();
     // check that in user mode the username is the same as the cloud_username
     switch ($mode) {
         case 'user':
             if ($clouduser->is_name_free($clouduser_name)) {
                 $event->log("cloudsoap->CloudRequestGetList", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Cloud User name {$clouduser_name} does not exists in the Cloud. Not adding the request !", "", "", 0, 0, 0);
                 return;
             }
             if (strcmp($username, $clouduser_name)) {
                 $event->log("cloudsoap->CloudRequestGetList", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Cloud User {$username} is trying to gather the request list of Cloud User {$clouduser_name}  !", "", "", 0, 0, 0);
                 return;
             }
             break;
         case 'admin':
             if (!strlen($clouduser_name)) {
                 $event->log("cloudsoap->CloudRequestGetList", $_SERVER['REQUEST_TIME'], 5, "cloud-soap-server.php", "Providing list of all Cloud-requests", "", "", 0, 0, 0);
                 $cloudrequest_list = array();
                 $cloudrequest = new cloudrequest();
                 $cloudrequest_id_list = $cloudrequest->get_all_ids();
                 foreach ($cloudrequest_id_list as $cr_id_list) {
                     foreach ($cr_id_list as $cr_id) {
                         $cloudrequest_list[] = $cr_id;
                     }
                 }
                 return $cloudrequest_list;
             } else {
                 if ($clouduser->is_name_free($clouduser_name)) {
                     $event->log("cloudsoap->CloudRequestGetList", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Cloud User name {$clouduser_name} does not exists in the Cloud. Not adding the request !", "", "", 0, 0, 0);
                     return;
                 }
             }
             break;
     }
     $cloudrequest_list = array();
     $clouduser->get_instance_by_name($clouduser_name);
     $cu_id = $clouduser->id;
     $event->log("cloudsoap->CloudRequestGetList", $_SERVER['REQUEST_TIME'], 5, "cloud-soap-server.php", "Providing list of Cloud-requests for Cloud User {$clouduser_name} ({$cu_id})", "", "", 0, 0, 0);
     $cloudrequest = new cloudrequest();
     $cloudrequest_id_list = $cloudrequest->get_all_active_ids_per_user($cu_id);
     foreach ($cloudrequest_id_list as $cr_id_list) {
         foreach ($cr_id_list as $cr_id) {
             $cloudrequest_list[] = $cr_id;
         }
     }
     return $cloudrequest_list;
 }
예제 #2
0
 $arHead['cr_id'] = array();
 $arHead['cr_id']['title'] = 'ID';
 $arHead['cr_user'] = array();
 $arHead['cr_user']['title'] = 'User';
 $arHead['cr_state'] = array();
 $arHead['cr_state']['title'] = 'State';
 $arHead['cr_app'] = array();
 $arHead['cr_app']['title'] = 'Appliance';
 $arHead['cr_res'] = array();
 $arHead['cr_res']['title'] = 'Res.';
 $arHead['cr_load'] = array();
 $arHead['cr_load']['title'] = 'Load';
 $arBody = array();
 $cloud_load_array = array();
 $cr = new cloudrequest();
 $cr_list = $cr->get_all_ids();
 foreach ($cr_list as $cr_id_arr) {
     $cr_id = $cr_id_arr['cr_id'];
     $cr_all++;
     $g_cr = new cloudrequest();
     $g_cr->get_instance_by_id($cr_id);
     if ($g_cr->status == 3) {
         // fill active
         $cr_active++;
         // find most active cloud appliance
         $c_app = new appliance();
         $c_app->get_instance_by_id($g_cr->appliance_id);
         $c_resource = new resource();
         $c_resource->get_instance_by_id($c_app->resources);
         if ("{$c_resource->state}" == "active") {
             $cloud_load_array[$cr_id] = $c_resource->load;
예제 #3
0
 function check_consistency($noop)
 {
     $errors = array();
     $noop_str = '';
     // cloud appliance check
     $cloud_appliance_arr = $this->cloudappliance->get_all_ids();
     foreach ($cloud_appliance_arr as $capp) {
         $ca_id = $capp['ca_id'];
         $this->cloudappliance->get_instance_by_id($ca_id);
         $cr = new cloudrequest();
         $cr->get_instance_by_id($this->cloudappliance->cr_id);
         // cr not existing any more, just remove the cloud appliance
         if (!strlen($cr->status)) {
             if ($noop) {
                 $this->cloudappliance->remove($ca_id);
             } else {
                 // error
                 $errors[] = 'cr ' . $ca_id . ' missing, found left-over!<br>';
             }
         }
         if ($cr->status == "6") {
             if ($noop) {
                 $clean_appliance = new appliance();
                 $clean_appliance->get_instance_by_id($cr->appliance_id);
                 $error = $this->__remove_cloud_resource($clean_appliance->resources, true, $cr->id);
                 if ($error !== '') {
                     $errors[] = $error;
                 }
                 $error = $this->__remove_cloud_image($clean_appliance->imageid, true);
                 if ($error !== '') {
                     $errors[] = $error;
                 }
                 $error = $this->__remove_cloud_appliance($clean_appliance->id, true);
                 if ($error !== '') {
                     $errors[] = $error;
                 }
                 $error = $this->__free_cloud_ips($cr->id, true);
                 if ($error !== '') {
                     $errors[] = $error;
                 }
                 $this->cloudappliance->remove($ca_id);
             } else {
                 // error
                 $errors[] = "cr " . $cr->id . " - found left-over!<br>";
             }
         }
     }
     unset($cr);
     // cloud image check
     $cloud_image_arr = $this->cloudimage->get_all_ids();
     foreach ($cloud_image_arr as $cim) {
         $ci_id = $cim['ci_id'];
         $this->cloudimage->get_instance_by_id($ci_id);
         $cr = new cloudrequest();
         $cr->get_instance_by_id($this->cloudimage->cr_id);
         // cr not existing any more, just remove the cloud image
         if (!strlen($cr->status)) {
             if ($noop) {
                 $this->cloudimage->remove($ci_id);
             } else {
                 // error
                 $errors[] = "cr missing, found left-over!<br>";
             }
         }
         // cr status done
         if ($cr->status == "6") {
             if ($noop) {
                 $error = $this->__remove_cloud_resource($this->cloudimage->resource_id, $noop, $cr->id);
                 if ($error !== '') {
                     $errors[] = $error;
                 }
                 $error = $this->__remove_cloud_image($this->cloudimage->image_id, $noop);
                 if ($error !== '') {
                     $errors[] = $error;
                 }
                 $error = $this->__remove_cloud_appliance($this->cloudimage->appliance_id, $noop);
                 if ($error !== '') {
                     $errors[] = $error;
                 }
                 $error = $this->__free_cloud_ips($cr->id, $noop);
                 if ($error !== '') {
                     $errors[] = $error;
                 }
                 $this->cloudimage->remove($ci_id);
             } else {
                 // error
                 $errors[] = "cr " . $cr->id . " - found left-over!<br>";
             }
         }
     }
     // create vm lc
     $cvmlc_arr = $this->cloudcreatevmlc->get_all_ids();
     foreach ($cvmlc_arr as $cvmlc_ids) {
         $cvmlc_id = $cvmlc_ids['vc_id'];
         $this->cloudcreatevmlc->get_instance_by_id($cvmlc_id);
         $now = $_SERVER['REQUEST_TIME'];
         $vm_c_timeout = $this->cloudcreatevmlc->request_time + $this->cloudcreatevmlc->vm_create_timeout + $this->cloudcreatevmlc->vm_create_timeout;
         if ($now > $vm_c_timeout) {
             if ($noop) {
                 $this->cloudcreatevmlc->remove($cvmlc_id);
             } else {
                 // error
                 $errors[] = "found left-over CVMLC " . $cvmlc_id . " <br>";
             }
         }
     }
     // check all done requests if they still contain an appliance id
     $crl = new cloudrequest();
     $cr_list = $crl->get_all_ids();
     foreach ($cr_list as $list) {
         $cr_id = $list['cr_id'];
         $cr = new cloudrequest();
         $cr->get_instance_by_id($cr_id);
         if ($cr->status != 6) {
             continue;
         }
         if (strlen($cr->appliance_id)) {
             if ($cr->appliance_id != 0) {
                 if ($noop) {
                     $cr->setappliance("remove", $cr->appliance_id);
                 } else {
                     // error
                     $errors[] = "removing appliance id " . $cr->appliance_id . " from request " . $cr->id . " <br>";
                 }
             }
         }
     }
     // check all ips
     $this->__free_cloud_ips(0, $noop);
     if ($noop) {
         $this->event->remove_by_description('Could not create instance of');
     }
     // handle errors
     if (count($errors) < 1) {
         return '';
     } else {
         return implode('', $errors);
     }
 }