diff --git a/include/Host.h b/include/Host.h index 62ada8c312..9ddb387fd5 100644 --- a/include/Host.h +++ b/include/Host.h @@ -454,6 +454,18 @@ public: return host_share.test(cpu, mem, disk, pci, error); } + /** + * Tests whether a new VM can be hosted by the host or not, checking the + * PCI devices only. + * @param pci devices needed by the VM + * @param error Returns the error reason, if any + * @return true if the share can host the VM + */ + bool test_capacity(vector &pci, string& error) const + { + return host_share.test(pci, error); + } + /** * Returns a copy of the VM IDs set */ diff --git a/include/HostShare.h b/include/HostShare.h index 6ec5d4c194..a704a9e567 100644 --- a/include/HostShare.h +++ b/include/HostShare.h @@ -248,6 +248,26 @@ public: return fits; } + /** + * Check if this share can host a VM, testing only the PCI devices. + * @param pci_devs requested by the VM + * @param error Returns the error reason, if any + * + * @return true if the share can host the VM or it is the only one + * configured + */ + bool test(vector& pci_devs, string& error) const + { + bool fits = pci.test(pci_devs); + + if (!fits) + { + error = "Unavailable PCI device."; + } + + return fits; + } + /** * Function to write a HostShare to an output stream */ diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index 406e948e6e..96d88cea3a 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -398,14 +398,14 @@ bool RequestManagerVirtualMachine::check_host( return false; } - if (!enforce) + if (enforce) { - cpu = 0; - mem = 0; - disk = 0; + test = host->test_capacity(cpu, mem, disk, pci, capacity_error); + } + else + { + test = host->test_capacity(pci, capacity_error); } - - test = host->test_capacity(cpu, mem, disk, pci, capacity_error); if (!test) {