class AutonomiccsSystemVmDeploymentService implements InitializingBean {

    protected boolean canHostSupportVm(ServiceOfferingVO vmServiceOffering, HostResources hostResources) {
        if (vmServiceOffering.getCpu() > hostResources.getCpus()) {
            return false;
        }
        double hostTotalCpu = hostResources.getCpuOverprovisioning() * hostResources.getCpus() * hostResources.getSpeed();
        double hostUsedCpu = hostResources.getUsedCpu();
        if ((vmServiceOffering.getSpeed() * vmServiceOffering.getCpu()) > hostTotalCpu - hostUsedCpu) {
            return false;
        }

        double hostTotalMemoryInMegaBytes = (hostResources.getMemoryOverprovisioning() * hostResources.getTotalMemoryInBytes()) / ONE_MEGABYTE_IN_BYTES;
        long usedMemoryInMegabytes = hostResources.getUsedMemoryInMegaBytes();
        if (vmServiceOffering.getRamSize() > hostTotalMemoryInMegaBytes - usedMemoryInMegabytes) {
            return false;
        }
        return true;
    }

}