class HostResourcesService {

    protected void calculateHostResourcesAllocated(HostResources host) {
        List<VmResources> vmsFromHost = host.getVmsResources();
        long usedCpu = 0;
        long usedMemory = 0;
        for (VmResources vm : vmsFromHost) {
            usedMemory += vm.getMemoryInMegaBytes();
            usedCpu += vm.getCpuSpeed() * vm.getNumberOfCpus();
        }
        host.setUsedCpu(usedCpu);
        host.setUsedMemoryInMegaBytes(usedMemory);
    }

}