Пример #1
0
  /**
   * Returns the physical information of a remote node.
   *
   * @return a {@link HostDto} instance
   * @throws NoHypervisorException
   * @throws CollectorException
   * @throws LoginException
   * @throws ConnectionException
   */
  @GET
  @Path(HOST)
  public HostDto getHostInfo(
      @PathParam("ip") @NotNull @Ip final String ip,
      @QueryParam("hyp") @NotNull final String hypervisorType,
      @QueryParam("user") @NotNull final String user,
      @QueryParam("passwd") @NotNull final String password,
      @QueryParam(AIMPORT) @DefaultValue("8889") @Port final Integer aimport)
      throws NodecollectorException {

    Long time = System.currentTimeMillis();
    HypervisorType hypType;
    try {
      hypType = HypervisorType.fromValue(hypervisorType);
    } catch (IllegalArgumentException e) {
      throw new BadRequestException(MessageValues.UNKNOWN_HYPERVISOR);
    }
    HostDto dto = hostService.getHostInfo(ip, hypType, user, password, aimport);

    time = System.currentTimeMillis() - time;
    LOGGER.debug(
        "Retrieving host '" + dto.getName() + " (" + ip + ")' took " + time + " miliseconds.");
    return dto;
  }
Пример #2
0
  /**
   * 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;
  }