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:
parent
b79a9fc6c6
commit
d28b234c9c
@ -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,
|
||||
|
@ -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,26 +433,32 @@ 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;
|
||||
}
|
||||
|
||||
auth = vm_authorization(id, 0, 0, att, &host_perms, 0, auth_op);
|
||||
|
||||
if ( auth == false )
|
||||
if (auth == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( (vm = get_vm(id, att)) == 0 )
|
||||
if ((vm = get_vm(id, att)) == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( vm->get_state() != VirtualMachine::PENDING )
|
||||
if (vm->get_state() != VirtualMachine::PENDING)
|
||||
{
|
||||
failure_response(ACTION,
|
||||
request_error("Wrong state to perform action",""),
|
||||
@ -429,32 +468,36 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
if ( enforce )
|
||||
if (enforce)
|
||||
{
|
||||
int vm_cpu, vm_mem, vm_disk;
|
||||
int cpu, mem, disk;
|
||||
string error;
|
||||
|
||||
vm->get_requirements(vm_cpu, vm_mem, vm_disk);
|
||||
vm->get_requirements(cpu, mem, disk);
|
||||
|
||||
if ( free_cpu < vm_cpu || free_mem < vm_mem )
|
||||
vm->unlock();
|
||||
|
||||
if (check_host(hid, cpu, mem, disk, error) == false)
|
||||
{
|
||||
ostringstream oss;
|
||||
failure_response(ACTION, request_error(error,""), att);
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
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,21 +541,27 @@ 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;
|
||||
}
|
||||
|
||||
auth = vm_authorization(id, 0, 0, att, &host_perms, 0, auth_op);
|
||||
|
||||
if ( auth == false )
|
||||
if (auth == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( (vm = get_vm(id, att)) == 0 )
|
||||
if ((vm = get_vm(id, att)) == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -534,11 +580,35 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList
|
||||
|
||||
current_hid = vm->get_hid();
|
||||
|
||||
vm->unlock();
|
||||
if (enforce)
|
||||
{
|
||||
int cpu, mem, disk;
|
||||
string error;
|
||||
|
||||
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)
|
||||
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;
|
||||
}
|
||||
}
|
||||
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,38 +635,21 @@ 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;
|
||||
}
|
||||
|
||||
if ( live == true )
|
||||
if (live == true)
|
||||
{
|
||||
dm->live_migrate(vm);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user