예제 #1
0
 function check_limits($resource_quantity, $ram_req, $disk_req, $cpu_req, $network_req)
 {
     $cu_id = $this->cu_id;
     $users_appliance_count = 0;
     $users_global_memory_consumption = 0;
     $users_global_disk_consumption = 0;
     $users_global_network_consumption = 0;
     $users_global_cpu_consumption = 0;
     $this->_event->log("check_limits", $_SERVER['REQUEST_TIME'], 5, "clouduserlimits.class.php", "Checking Cloud Limits for User {$cu_id}", "", "", 0, 0, 0);
     // quantity
     if ($this->resource_limit != 0) {
         // check howmany waiting request the user has
         $cr_waiting = new cloudrequest();
         $waiting_crs = $cr_waiting->get_count_waiting_per_user($cu_id);
         // check howmany active appliances the user has
         $cloud_user_apps_arr = array();
         $cloud_user_app = new cloudappliance();
         $cloud_user_apps_arr = $cloud_user_app->get_all_ids();
         foreach ($cloud_user_apps_arr as $capp) {
             $tmp_cloud_app = new cloudappliance();
             $tmp_cloud_app_id = $capp['ca_id'];
             $tmp_cloud_app->get_instance_by_id($tmp_cloud_app_id);
             // check if the cr is ours
             $rc_tmp_cr = new cloudrequest();
             $rc_tmp_cr->get_instance_by_id($tmp_cloud_app->cr_id);
             if ($rc_tmp_cr->cu_id != $cu_id) {
                 continue;
             }
             $users_appliance_count++;
             $users_global_memory_consumption = $users_global_memory_consumption + $rc_tmp_cr->ram_req;
             $users_global_disk_consumption = $users_global_disk_consumption + $rc_tmp_cr->disk_req;
             $users_global_network_consumption = $users_global_network_consumption + $rc_tmp_cr->network_req;
             $users_global_cpu_consumption = $users_global_cpu_consumption + $rc_tmp_cr->cpu_req;
         }
         // check resource_quantity limit
         if ($users_appliance_count + $waiting_crs >= $this->resource_limit) {
             $this->_event->log("check_limits", $_SERVER['REQUEST_TIME'], 5, "clouduserlimits.class.php", "-> User {$cu_id} already {$users_appliance_count} appliance(s) active plus {$waiting_crs} waiting requests.", "", "", 0, 0, 0);
             return false;
         } else {
             $this->_event->log("check_limits", $_SERVER['REQUEST_TIME'], 5, "clouduserlimits.class.php", "-> User {$cu_id} has {$users_appliance_count} appliance(s) running (Users limit is {$this->resource_limit})", "", "", 0, 0, 0);
         }
     } else {
         $this->_event->log("check_limits", $_SERVER['REQUEST_TIME'], 5, "clouduserlimits.class.php", "-> Limit resource_limit for User {$cu_id} not set, skipping check.", "", "", 0, 0, 0);
     }
     // memory
     if ($this->memory_limit != 0) {
         // check the overall memory consumption
         if ($users_global_memory_consumption >= $this->memory_limit) {
             $this->_event->log("check_limits", $_SERVER['REQUEST_TIME'], 2, "clouduserlimits.class.php", "-> Not adding request from User {$cu_id} who already consumes {$users_global_memory_consumption} MB of memory.", "", "", 0, 0, 0);
             return false;
         } else {
             $this->_event->log("check_limits", $_SERVER['REQUEST_TIME'], 5, "clouduserlimits.class.php", "-> User {$cu_id} consumes {$users_global_memory_consumption} MB of memory (Users limit is {$this->memory_limit})", "", "", 0, 0, 0);
         }
     } else {
         $this->_event->log("check_limits", $_SERVER['REQUEST_TIME'], 5, "clouduserlimits.class.php", "-> Limit memory_limit for User {$cu_id} not set, skipping check.", "", "", 0, 0, 0);
     }
     // disk
     if ($this->disk_limit != 0) {
         if ($users_global_disk_consumption >= $this->disk_limit) {
             $this->_event->log("check_limits", $_SERVER['REQUEST_TIME'], 2, "clouduserlimits.class.php", "-> Not adding request from User {$cu_id} who already consumes {$users_global_disk_consumption} MB of disk space.", "", "", 0, 0, 0);
             return false;
         } else {
             $this->_event->log("check_limits", $_SERVER['REQUEST_TIME'], 5, "clouduserlimits.class.php", "-> User {$cu_id} consumes {$users_global_disk_consumption} MB of disk space (Users limit is {$this->disk_limit})", "", "", 0, 0, 0);
         }
     } else {
         $this->_event->log("check_limits", $_SERVER['REQUEST_TIME'], 5, "clouduserlimits.class.php", "-> Limit disk_limit for User {$cu_id} not set, skipping check.", "", "", 0, 0, 0);
     }
     // cpu
     if ($this->cpu_limit != 0) {
         if ($users_global_cpu_consumption >= $this->cpu_limit) {
             $this->_event->log("check_limits", $_SERVER['REQUEST_TIME'], 2, "clouduserlimits.class.php", "-> Not adding request from User {$cu_id} who already consumes {$users_global_cpu_consumption} CPUs.", "", "", 0, 0, 0);
             return false;
         } else {
             $this->_event->log("check_limits", $_SERVER['REQUEST_TIME'], 5, "clouduserlimits.class.php", "-> User {$cu_id} consumes {$users_global_cpu_consumption} CPUs (Users limit is {$this->cpu_limit})", "", "", 0, 0, 0);
         }
     } else {
         $this->_event->log("check_limits", $_SERVER['REQUEST_TIME'], 5, "clouduserlimits.class.php", "-> Limit cpu_limit for User {$cu_id} not set, skipping check.", "", "", 0, 0, 0);
     }
     // network
     if ($this->network_limit != 0) {
         if ($users_global_network_consumption >= $this->disk_limit) {
             $this->_event->log("check_limits", $_SERVER['REQUEST_TIME'], 2, "clouduserlimits.class.php", "-> Not adding request from User {$cu_id} who already consumes {$users_global_network_consumption} network interfaces.", "", "", 0, 0, 0);
             return false;
         } else {
             $this->_event->log("check_limits", $_SERVER['REQUEST_TIME'], 5, "clouduserlimits.class.php", "-> User {$cu_id} consumes {$users_global_network_consumption} network interfaces (Users limit is {$this->network_limit})", "", "", 0, 0, 0);
         }
     } else {
         $this->_event->log("check_limits", $_SERVER['REQUEST_TIME'], 5, "clouduserlimits.class.php", "-> Limit network_limit for User {$cu_id} not set, skipping check.", "", "", 0, 0, 0);
     }
     return true;
 }