Class GetHost


  • public class GetHost
    extends java.lang.Object
    This class shows how to get a ManagedObjectReference to a host using its name or IP address. While this class is designed for use by the CIM samples, it is generic enough to be useful in other contexts. Other utilities in this class deal with the vim25 connection object fed to it. This class is immutable.
    • Constructor Summary

      Constructors 
      Constructor Description
      GetHost​(Connection connection)
      this class works with a connection object and is immutable against this object
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.net.InetAddress address​(java.lang.String value)  
      com.vmware.vim25.ManagedObjectReference byName​(java.lang.String hostname)
      given a hostname or IP address, returns the managed object ref for that host using the connection fed to the constructor.
      java.lang.String getType()
      returns the connection type
      GetHost hostCheck()
      throws an IsNotHostAgentException if we are NOT talking to an ESX host
      static java.lang.String ipAddress​(java.net.InetAddress address)
      takes a candidate ipaddress or host name and returns a validated IP address or hostname
      boolean isIpAddress​(java.lang.String value)
      takes a candidate hostname or IP address and returns true if the address is useful
      static java.lang.String resolve​(java.net.InetAddress address)
      uses the InetAddress API in Java to process either a hostname or an IP the return result is a string delimited by "/" that holds the DNS name (if found) and the IP address (if found) of the result.
      GetHost vCenterCheck()
      throws an IsNotvCenterCheck if we are NOT talking to a vCenter instance
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

    • Constructor Detail

      • GetHost

        public GetHost​(Connection connection)
        this class works with a connection object and is immutable against this object
        Parameters:
        connection - the connection we are working with
    • Method Detail

      • isIpAddress

        public boolean isIpAddress​(java.lang.String value)
        takes a candidate hostname or IP address and returns true if the address is useful

        NOTE: this is IPv6 compatible

        Parameters:
        value -
        Returns:
        true if is an address that is not multicast and not the local loopback
      • address

        public static java.net.InetAddress address​(java.lang.String value)
        Parameters:
        value - a possible hostname or IP address
        Returns:
        an inet address object build from this hostname or IP address
        See Also:
        InetAddress
      • resolve

        public static java.lang.String resolve​(java.net.InetAddress address)
        uses the InetAddress API in Java to process either a hostname or an IP the return result is a string delimited by "/" that holds the DNS name (if found) and the IP address (if found) of the result. A string with just "/" is returned
        Parameters:
        address - a potential ip or hostname
        Returns:
        a string "hostname/ipaddress" or "/" when nothing found
      • ipAddress

        public static java.lang.String ipAddress​(java.net.InetAddress address)
        takes a candidate ipaddress or host name and returns a validated IP address or hostname
        Parameters:
        address - - candidate value
        Returns:
        the IP as a string or an empty string if no IP found
      • byName

        public com.vmware.vim25.ManagedObjectReference byName​(java.lang.String hostname)
        given a hostname or IP address, returns the managed object ref for that host using the connection fed to the constructor.

        Parameters:
        hostname -
        Returns:
        the matching managed object reference or null
      • vCenterCheck

        public GetHost vCenterCheck()
        throws an IsNotvCenterCheck if we are NOT talking to a vCenter instance
        Returns:
        this instance of the GetHost object for command chaining
        See Also:
        GetHost.IsNotvCenterException
      • hostCheck

        public GetHost hostCheck()
        throws an IsNotHostAgentException if we are NOT talking to an ESX host
        Returns:
        this instance of the GetHost object for command chaining
        See Also:
        GetHost.IsNotHostAgentException
      • getType

        public java.lang.String getType()
        returns the connection type