Exemplo n.º 1
0
  /**
   * Returns a list of virtual machines builded from a virtual system list
   *
   * @param vsc VirtualSystemCollectionDto list to transform
   * @return list of virtual machines builded from a virtual system list
   */
  private List<VirtualMachine> transportVSCollectionToVMs(final VirtualSystemCollectionDto vsc) {
    long MEGABYTE = 1024L * 1024L;

    List<VirtualMachine> vms = new ArrayList<VirtualMachine>();

    for (VirtualSystemDto vs : vsc.getVirtualSystems()) {
      VirtualMachine vm =
          new VirtualMachine(
              vs.getName(),
              null,
              null,
              null,
              null,
              UUID.fromString(vs.getUuid()),
              VirtualMachine.NOT_MANAGED);

      vm.setCpu(new Long(vs.getCpu()).intValue());
      vm.setRam(new Long(vs.getRam() / MEGABYTE).intValue());
      vm.setVdrpPort(new Long(vs.getVport()).intValue());
      vm.setState(VirtualMachineState.valueOf(vs.getStatus().value()));
      for (ResourceType rt : vs.getResources()) {
        if (rt.getResourceType().equals(ResourceEnumType.STORAGE_DISK)) {
          long bytesHD = rt.getUnits();
          vm.setHdInBytes(bytesHD);

          if (StringUtils.hasText(rt.getAddress()) && StringUtils.hasText(rt.getConnection())) {
            Datastore ds = new Datastore();
            ds.setDirectory(rt.getAddress());
            ds.setRootPath(rt.getConnection());
            ds.setName(rt.getElementName());
            vm.setDatastore(ds);
          }

          if (rt.getResourceSubType() != null) {

            VirtualImage vi = new VirtualImage(null);
            VirtualDiskEnumType diskFormatType =
                VirtualDiskEnumType.fromValue(rt.getResourceSubType().toString());
            if (diskFormatType.equals(VirtualDiskEnumType.STATEFUL)) {
              vi.setStateful(1);
            }
            vi.setDiskFormatType(DiskFormatType.fromURI(diskFormatType.value()));
            vm.setVirtualImage(vi);
          }
        }
      }

      vms.add(vm);
    }

    return vms;
  }
Exemplo n.º 2
0
 public VirtualMachine(
     final String name,
     final Enterprise enterprise,
     final User user,
     final VirtualImage virtualImage,
     final UUID uuid,
     final Integer typeId) {
   setName(name);
   setEnterprise(enterprise);
   setUser(user);
   setVirtualImage(virtualImage);
   setUuid(uuid.toString());
   setIdType(typeId);
 }