/**
   * Return the remote machine using its hypervisor APIs through the {@link
   * NodeCollectorPremiumRESTClient} client.
   *
   * @param nodecollector object nodecollector used in the datacenter we want to add the machine.
   * @param hypervisorIp ip address of the hypervisor.
   * @param hypType kind of hypervisor API we want to use.
   * @param user use to log-in
   * @param password password
   * @param port (optional) AIM port we connect to if we use KVM or XEN.
   * @return the remote {@link Machine} entity, null if we don't find anything.
   */
  public Machine getRemoteHypervisor(
      final RemoteService nodecollector,
      final IPAddress hypervisorIp,
      final HypervisorType hypType,
      final String user,
      final String password,
      final Integer port) {
    NodeCollectorRESTClient restCli = initializeRESTClient(nodecollector);
    HostDto host = new HostDto();
    try {
      host = restCli.getRemoteHostInfo(hypervisorIp.toString(), hypType, user, password, port);
    } catch (BadRequestException e) {
      // InternalServerError -> A Bad Request NEVER should be thrown from here.
      logger.error(e.getMessage());
      addUnexpectedErrors(APIError.NC_UNEXPECTED_EXCEPTION);
    } catch (LoginException e) {
      logger.debug(e.getMessage());
      addConflictErrors(APIError.NC_BAD_CREDENTIALS_TO_MACHINE);
    } catch (ConnectionException e) {
      logger.debug(e.getMessage());
      addConflictErrors(APIError.NC_CONNECTION_EXCEPTION);
    } catch (UnprovisionedException e) {
      logger.debug(e.getMessage());
      addConflictErrors(APIError.NC_NOT_FOUND_EXCEPTION);
    } catch (CollectorException e) {
      logger.error(e.getMessage());
      addUnexpectedErrors(APIError.NC_UNEXPECTED_EXCEPTION);
    } catch (ServiceUnavailableException e) {
      logger.error(e.getMessage());
      addServiceUnavailableErrors(APIError.NC_UNAVAILABLE_EXCEPTION);
    } catch (CannotExecuteException e) {
      addConflictErrors(new CommonError(APIError.STATUS_CONFLICT.getCode(), e.getMessage()));
      flushErrors();
    }

    flushErrors();

    Machine machine = hostToMachine(nodecollector.getDatacenter(), host);
    Hypervisor hypervisor =
        machine.createHypervisor(
            hypType, hypervisorIp.toString(), hypervisorIp.toString(), port, user, password);
    machine.setHypervisor(hypervisor);

    return machine;
  }
 protected NodeCollectorRESTClient initializeRESTClient(final RemoteService nodecollector) {
   return new NodeCollectorRESTClient(nodecollector.getUri());
 }