1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-02 09:47:00 +03:00

feature #1338: Make use of Host::test_capacity in core checks.

This commit is contained in:
Ruben S. Montero 2012-12-15 03:11:30 +01:00
parent b79a9fc6c6
commit d28b234c9c
2 changed files with 128 additions and 71 deletions

View File

@ -63,11 +63,15 @@ protected:
string& tm,
string& ds_location,
int& ds_id,
int& free_cpu,
int& free_mem,
RequestAttributes& att,
PoolObjectAuth& host_perms);
bool check_host(int hid,
int cpu,
int mem,
int disk,
string& error);
int add_history(VirtualMachine * vm,
int hid,
const string& hostname,

View File

@ -102,8 +102,6 @@ int RequestManagerVirtualMachine::get_host_information(int hid,
string& tm,
string& ds_location,
int& ds_id,
int& free_cpu,
int& free_mem,
RequestAttributes& att,
PoolObjectAuth& host_perms)
{
@ -131,9 +129,6 @@ int RequestManagerVirtualMachine::get_host_information(int hid,
vmm = host->get_vmm_mad();
vnm = host->get_vnm_mad();
free_cpu = host->get_share_max_cpu() - host->get_share_cpu_usage();
free_mem = host->get_share_max_mem() - host->get_share_mem_usage();
host->get_permissions(host_perms);
cluster_id = host->get_cluster_id();
@ -205,6 +200,46 @@ int RequestManagerVirtualMachine::get_host_information(int hid,
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
bool RequestManagerVirtualMachine::check_host(int hid,
int cpu,
int mem,
int disk,
string& error)
{
Nebula& nd = Nebula::instance();
HostPool * hpool = nd.get_hpool();
Host * host;
bool test;
host = hpool->get(hid, true);
if (host == 0)
{
error = "Host no longer exists";
return false;
}
test = host->test_capacity(cpu, mem, disk);
if (!test)
{
ostringstream oss;
oss << object_name(PoolObjectSQL::HOST)
<< " " << hid << " does not have enough capacity.";
error = oss.str();
}
host->unlock();
return test;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
VirtualMachine * RequestManagerVirtualMachine::get_vm(int id,
RequestAttributes& att)
{
@ -391,8 +426,6 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList,
string tm_mad;
string ds_location;
int ds_id;
int free_cpu;
int free_mem;
int id = xmlrpc_c::value_int(paramList.getInt(1));
int hid = xmlrpc_c::value_int(paramList.getInt(2));
@ -400,9 +433,15 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList,
bool auth = false;
if (get_host_information(
hid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location, ds_id,
free_cpu, free_mem, att, host_perms) != 0)
if (get_host_information(hid,
hostname,
vmm_mad,
vnm_mad,
tm_mad,
ds_location,
ds_id,
att,
host_perms) != 0)
{
return;
}
@ -431,30 +470,34 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList,
if (enforce)
{
int vm_cpu, vm_mem, vm_disk;
int cpu, mem, disk;
string error;
vm->get_requirements(vm_cpu, vm_mem, vm_disk);
if ( free_cpu < vm_cpu || free_mem < vm_mem )
{
ostringstream oss;
oss << object_name(PoolObjectSQL::HOST)
<< " [" << hid << "] does not have enough capacity. CPU: Free "
<< free_cpu << " Requested " << vm_cpu << ", MEMORY: Free "
<< free_mem << " Requested " << vm_mem;
failure_response(ACTION,
request_error(oss.str(),""),
att);
vm->get_requirements(cpu, mem, disk);
vm->unlock();
if (check_host(hid, cpu, mem, disk, error) == false)
{
failure_response(ACTION, request_error(error,""), att);
return;
}
if ((vm = get_vm(id, att)) == 0)
{
return;
}
}
if ( add_history(
vm,hid,hostname,vmm_mad,vnm_mad,tm_mad,ds_location,ds_id,att) != 0)
if (add_history(vm,
hid,
hostname,
vmm_mad,
vnm_mad,
tm_mad,
ds_location,
ds_id,
att) != 0)
{
vm->unlock();
return;
@ -485,14 +528,11 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList
string tm_mad;
string ds_location;
int ds_id;
int free_cpu;
int free_mem;
PoolObjectAuth aux_perms;
int current_ds_id;
string aux_st;
int current_hid;
int aux_int;
int id = xmlrpc_c::value_int(paramList.getInt(1));
int hid = xmlrpc_c::value_int(paramList.getInt(2));
@ -501,9 +541,15 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList
bool auth = false;
if (get_host_information(
hid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location, ds_id,
free_cpu, free_mem, att, host_perms) != 0)
if (get_host_information(hid,
hostname,
vmm_mad,
vnm_mad,
tm_mad,
ds_location,
ds_id,
att,
host_perms) != 0)
{
return;
}
@ -534,11 +580,35 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList
current_hid = vm->get_hid();
if (enforce)
{
int cpu, mem, disk;
string error;
vm->get_requirements(cpu, mem, disk);
vm->unlock();
if (get_host_information(
current_hid, aux_st, aux_st, aux_st, aux_st, aux_st, current_ds_id,
aux_int, aux_int, att, aux_perms) != 0)
if (check_host(hid, cpu, mem, disk, error) == false)
{
failure_response(ACTION, request_error(error,""), att);
return;
}
}
else
{
vm->unlock();
}
if (get_host_information(current_hid,
aux_st,
aux_st,
aux_st,
aux_st,
aux_st,
current_ds_id,
att,
aux_perms) != 0)
{
return;
}
@ -565,32 +635,15 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList
return;
}
if ( enforce )
{
int vm_cpu, vm_mem, vm_disk;
vm->get_requirements(vm_cpu, vm_mem, vm_disk);
if ( free_cpu < vm_cpu || free_mem < vm_mem )
{
ostringstream oss;
oss << object_name(PoolObjectSQL::HOST)
<< " [" << hid << "] does not have enough capacity. CPU: Free "
<< free_cpu << " Requested " << vm_cpu << ", MEMORY: Free "
<< free_mem << " Requested " << vm_mem;
failure_response(ACTION,
request_error(oss.str(),""),
att);
vm->unlock();
return;
}
}
if ( add_history(vm, hid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location,
ds_id, att) != 0)
if (add_history(vm,
hid,
hostname,
vmm_mad,
vnm_mad,
tm_mad,
ds_location,
ds_id,
att) != 0)
{
vm->unlock();
return;