Ejemplo n.º 1
0
  /**
   * Searches for all ip addresses of a host system
   *
   * @param hostSystem the host system to query
   * @return the ip addresses of the host system, the first one is the primary
   * @throws RemoteException
   */
  public TreeSet<String> getHostSystemIpAddresses(HostSystem hostSystem) throws RemoteException {
    TreeSet<String> ipAddresses = new TreeSet<String>();

    HostNetworkSystem hostNetworkSystem = hostSystem.getHostNetworkSystem();

    if (hostNetworkSystem != null) {
      HostNetworkInfo hostNetworkInfo = hostNetworkSystem.getNetworkInfo();
      if (hostNetworkInfo != null) {
        HostVirtualNic[] hostVirtualNics = hostNetworkInfo.getConsoleVnic();
        if (hostVirtualNics != null) {
          for (HostVirtualNic hostVirtualNic : hostVirtualNics) {
            ipAddresses.add(hostVirtualNic.getSpec().getIp().getIpAddress());
          }
        }
        hostVirtualNics = hostNetworkInfo.getVnic();
        if (hostVirtualNics != null) {
          for (HostVirtualNic hostVirtualNic : hostVirtualNics) {
            ipAddresses.add(hostVirtualNic.getSpec().getIp().getIpAddress());
          }
        }
      }
    }
    return ipAddresses;
  }