Revision e348918e src/rm/RequestManagerVirtualMachine.cc
src/rm/RequestManagerVirtualMachine.cc | ||
---|---|---|
375 | 375 |
/* -------------------------------------------------------------------------- */ |
376 | 376 |
/* -------------------------------------------------------------------------- */ |
377 | 377 |
|
378 |
bool RequestManagerVirtualMachine::check_host(int hid, |
|
379 |
int cpu, |
|
380 |
int mem, |
|
381 |
int disk, |
|
382 |
string& error) |
|
378 |
bool RequestManagerVirtualMachine::check_host( |
|
379 |
int hid, bool enforce, VirtualMachine* vm, string& error) |
|
383 | 380 |
{ |
384 | 381 |
Nebula& nd = Nebula::instance(); |
385 | 382 |
HostPool * hpool = nd.get_hpool(); |
386 | 383 |
|
387 | 384 |
Host * host; |
388 | 385 |
bool test; |
386 |
string capacity_error; |
|
387 |
|
|
388 |
int cpu, mem, disk; |
|
389 |
vector<Attribute *> pci; |
|
390 |
|
|
391 |
vm->get_requirements(cpu, mem, disk, pci); |
|
389 | 392 |
|
390 | 393 |
host = hpool->get(hid, true); |
391 | 394 |
|
... | ... | |
395 | 398 |
return false; |
396 | 399 |
} |
397 | 400 |
|
398 |
test = host->test_capacity(cpu, mem, disk); |
|
401 |
if (!enforce) |
|
402 |
{ |
|
403 |
cpu = 0; |
|
404 |
mem = 0; |
|
405 |
disk = 0; |
|
406 |
} |
|
407 |
|
|
408 |
test = host->test_capacity(cpu, mem, disk, pci, capacity_error); |
|
399 | 409 |
|
400 | 410 |
if (!test) |
401 | 411 |
{ |
402 | 412 |
ostringstream oss; |
403 | 413 |
|
404 |
oss << object_name(PoolObjectSQL::HOST) |
|
405 |
<< " " << hid << " does not have enough capacity."; |
|
414 |
oss << object_name(PoolObjectSQL::VM) << " [" << vm->get_oid() |
|
415 |
<< "] does not fit in " << object_name(PoolObjectSQL::HOST) |
|
416 |
<< " [" << hid << "]. " << capacity_error; |
|
406 | 417 |
|
407 | 418 |
error = oss.str(); |
408 | 419 |
} |
... | ... | |
662 | 673 |
|
663 | 674 |
bool auth = false; |
664 | 675 |
|
676 |
string error; |
|
677 |
|
|
665 | 678 |
// ------------------------------------------------------------------------ |
666 | 679 |
// Get request parameters and information about the target host |
667 | 680 |
// ------------------------------------------------------------------------ |
... | ... | |
814 | 827 |
return; |
815 | 828 |
} |
816 | 829 |
|
817 |
if (enforce)
|
|
830 |
if (check_host(hid, enforce, vm, error) == false)
|
|
818 | 831 |
{ |
819 |
int cpu, mem, disk; |
|
820 |
vector<Attribute *> pci; |
|
821 |
|
|
822 |
string error; |
|
823 |
|
|
824 |
vm->get_requirements(cpu, mem, disk, pci); |
|
825 |
|
|
826 | 832 |
vm->unlock(); |
827 | 833 |
|
828 |
if (check_host(hid, cpu, mem, disk, error) == false) |
|
829 |
{ |
|
830 |
failure_response(ACTION, request_error(error,""), att); |
|
831 |
return; |
|
832 |
} |
|
833 |
|
|
834 |
if ((vm = get_vm(id, att)) == 0) |
|
835 |
{ |
|
836 |
return; |
|
837 |
} |
|
834 |
failure_response(ACTION, request_error(error,""), att); |
|
835 |
return; |
|
838 | 836 |
} |
839 | 837 |
|
840 | 838 |
// ------------------------------------------------------------------------ |
... | ... | |
899 | 897 |
|
900 | 898 |
bool auth = false; |
901 | 899 |
|
900 |
string error; |
|
901 |
|
|
902 | 902 |
// ------------------------------------------------------------------------ |
903 | 903 |
// Get request parameters and information about the target host |
904 | 904 |
// ------------------------------------------------------------------------ |
... | ... | |
1033 | 1033 |
} |
1034 | 1034 |
|
1035 | 1035 |
// Check the host has enough capacity |
1036 |
if (enforce)
|
|
1036 |
if (check_host(hid, enforce, vm, error) == false)
|
|
1037 | 1037 |
{ |
1038 |
int cpu, mem, disk; |
|
1039 |
vector<Attribute *> pci; |
|
1040 |
|
|
1041 |
string error; |
|
1042 |
|
|
1043 |
vm->get_requirements(cpu, mem, disk, pci); |
|
1044 |
|
|
1045 | 1038 |
vm->unlock(); |
1046 | 1039 |
|
1047 |
if (check_host(hid, cpu, mem, disk, error) == false) |
|
1048 |
{ |
|
1049 |
failure_response(ACTION, request_error(error,""), att); |
|
1050 |
return; |
|
1051 |
} |
|
1052 |
} |
|
1053 |
else |
|
1054 |
{ |
|
1055 |
vm->unlock(); |
|
1040 |
failure_response(ACTION, request_error(error,""), att); |
|
1041 |
return; |
|
1056 | 1042 |
} |
1057 | 1043 |
|
1044 |
vm->unlock(); |
|
1045 |
|
|
1058 | 1046 |
// Check we are in the same cluster |
1059 | 1047 |
Host * host = nd.get_hpool()->get(c_hid, true); |
1060 | 1048 |
|
... | ... | |
1835 | 1823 |
int dcpu_host = (int) (dcpu * 100);//now in 100% |
1836 | 1824 |
int dmem_host = dmemory * 1024; //now in Kilobytes |
1837 | 1825 |
|
1826 |
vector<Attribute *> empty_pci; |
|
1827 |
string error; |
|
1828 |
|
|
1838 | 1829 |
host = hpool->get(hid, true); |
1839 | 1830 |
|
1840 | 1831 |
if (host == 0) |
... | ... | |
1848 | 1839 |
return; |
1849 | 1840 |
} |
1850 | 1841 |
|
1851 |
if ( enforce && host->test_capacity(dcpu_host, dmem_host, 0) == false) |
|
1842 |
if ( enforce && host->test_capacity(dcpu_host, dmem_host, 0, empty_pci, error) == false)
|
|
1852 | 1843 |
{ |
1853 | 1844 |
ostringstream oss; |
1854 | 1845 |
|
Also available in: Unified diff