Host { public boolean vmCreate(Vm vm) { if (getStorage() < vm.getSize()) { Log.printConcatLine("[VmScheduler.vmCreate] Allocation of VM #", vm.getId(), " to Host #", getId(), " failed by storage"); return false; } if (!getRamProvisioner().allocateRamForVm(vm, vm.getCurrentRequestedRam())) { Log.printConcatLine("[VmScheduler.vmCreate] Allocation of VM #", vm.getId(), " to Host #", getId(), " failed by RAM"); return false; } if (!getBwProvisioner().allocateBwForVm(vm, vm.getCurrentRequestedBw())) { Log.printConcatLine("[VmScheduler.vmCreate] Allocation of VM #", vm.getId(), " to Host #", getId(), " failed by BW"); getRamProvisioner().deallocateRamForVm(vm); return false; } if (!getVmScheduler().allocatePesForVm(vm, vm.getCurrentRequestedMips())) { Log.printConcatLine("[VmScheduler.vmCreate] Allocation of VM #", vm.getId(), " to Host #", getId(), " failed by MIPS"); getRamProvisioner().deallocateRamForVm(vm); getBwProvisioner().deallocateBwForVm(vm); return false; } setStorage(getStorage() - vm.getSize()); getVmList().add(vm); vm.setHost(this); return true; } Host(
			int id,
			RamProvisioner ramProvisioner,
			BwProvisioner bwProvisioner,
			long storage,
			List<? extends Pe> peList,
			VmScheduler vmScheduler); double updateVmsProcessing(double currentTime); void addMigratingInVm(Vm vm); void removeMigratingInVm(Vm vm); void reallocateMigratingInVms(); boolean isSuitableForVm(Vm vm); boolean vmCreate(Vm vm); void vmDestroy(Vm vm); void vmDestroyAll(); Vm getVm(int vmId, int userId); int getNumberOfPes(); int getNumberOfFreePes(); int getTotalMips(); boolean allocatePesForVm(Vm vm, List<Double> mipsShare); void deallocatePesForVm(Vm vm); List<Double> getAllocatedMipsForVm(Vm vm); double getTotalAllocatedMipsForVm(Vm vm); double getMaxAvailableMips(); double getAvailableMips(); long getBw(); int getRam(); long getStorage(); int getId(); RamProvisioner getRamProvisioner(); BwProvisioner getBwProvisioner(); VmScheduler getVmScheduler(); @SuppressWarnings("unchecked") List<T> getPeList(); @SuppressWarnings("unchecked") List<T> getVmList(); boolean isFailed(); boolean setFailed(String resName, boolean failed); boolean setFailed(boolean failed); boolean setPeStatus(int peId, int status); List<Vm> getVmsMigratingIn(); Datacenter getDatacenter(); void setDatacenter(Datacenter datacenter);  }
@Test public void testVmCreate() { Vm vm0 = new Vm(0, 0, MIPS / 2, 1, RAM / 2, BW / 2, 0, "", new CloudletSchedulerDynamicWorkload(MIPS / 2, 1)); Vm vm1 = new Vm(1, 0, MIPS, 1, RAM, BW, 0, "", new CloudletSchedulerDynamicWorkload(MIPS, 1)); Vm vm2 = new Vm(2, 0, MIPS * 2, 1, RAM, BW, 0, "", new CloudletSchedulerDynamicWorkload(MIPS * 2, 1)); Vm vm3 = new Vm(3, 0, MIPS / 2, 2, RAM / 2, BW / 2, 0, "", new CloudletSchedulerDynamicWorkload(MIPS / 2, 2)); assertTrue(host.vmCreate(vm0)); assertFalse(host.vmCreate(vm1)); assertFalse(host.vmCreate(vm2)); assertTrue(host.vmCreate(vm3)); }