Package com.vmware.cim.helpers
Class GetHost
- java.lang.Object
-
- com.vmware.cim.helpers.GetHost
-
public class GetHost extends java.lang.ObjectThis 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classGetHost.IsNotHostAgentExceptionthrown when this class must assert that a Host is in use.classGetHost.IsNotvCenterExceptionthrown when this class must assert that a vCenter connection is in use.
-
Field Summary
Fields Modifier and Type Field Description Connectionconnection
-
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.InetAddressaddress(java.lang.String value)com.vmware.vim25.ManagedObjectReferencebyName(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.StringgetType()returns the connection typeGetHosthostCheck()throws an IsNotHostAgentException if we are NOT talking to an ESX hoststatic java.lang.StringipAddress(java.net.InetAddress address)takes a candidate ipaddress or host name and returns a validated IP address or hostnamebooleanisIpAddress(java.lang.String value)takes a candidate hostname or IP address and returns true if the address is usefulstatic java.lang.Stringresolve(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.GetHostvCenterCheck()throws an IsNotvCenterCheck if we are NOT talking to a vCenter instance
-
-
-
Field Detail
-
connection
public final Connection connection
-
-
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 usefulNOTE: 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
-
-