/** * Converts the type of {@link HostDto} from the nodecollector response to the {@link Machine} * type for the API model. * * @param datacenter datacenter where the machine will be assigned. * @param host hostDto object. * @return a {@link Machine} entity. */ protected Machine hostToMachine(final Datacenter datacenter, final HostDto host) { final Integer MEGABYTE = 1048576; int ram = (int) (host.getRam() / MEGABYTE); int cpus = (int) host.getCpu(); Machine machine = new Machine( datacenter, host.getName(), host.getDescription(), ram, 0, cpus, 0, 0, transfromToState(host.getStatus()), ""); // Long totalStorage = 0L; String switches = ""; for (ResourceType resource : host.getResources()) { // TODO remove code if (resource.getResourceType().equals(ResourceEnumType.STORAGE_DISK)) { Datastore datastore = new Datastore(machine, resource.getElementName(), resource.getAddress(), ""); datastore.setEnabled(Boolean.FALSE); datastore.setSize(resource.getUnits()); datastore.setUsedSize(resource.getUnits() - resource.getAvailableUnits()); if (resource.getConnection() == null) { datastore.setDatastoreUUID(UUID.randomUUID().toString()); } else { datastore.setDatastoreUUID(resource.getConnection()); } // totalStorage += datastore.getSize(); } else { if (resource.getResourceType().equals(ResourceEnumType.NETWORK_INTERFACE)) { switches = switches.concat(resource.getElementName()) + "/"; machine.getListOfMacs().add(resource.getAddress()); } } } switches = switches.substring(0, switches.lastIndexOf('/')); machine.setVirtualSwitch(switches); return machine; }