Package org.opennms.protocols.vmware
Class VmwareViJavaAccess
- java.lang.Object
-
- org.opennms.protocols.vmware.VmwareViJavaAccess
-
- All Implemented Interfaces:
AutoCloseable
public class VmwareViJavaAccess extends Object implements AutoCloseable
The Class VmwareViJavaAccessThis class provides all the functionality to query Vmware infrastructure components.
- Author:
- Christian Pape
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_TIMEOUT
-
Constructor Summary
Constructors Constructor Description VmwareViJavaAccess(String hostname)
Constructor for creating a instance for a given server.VmwareViJavaAccess(String hostname, String username, String password)
Constructor for creating a instance for a given server and credentials.VmwareViJavaAccess(VmwareServer vmwareServer)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
connect()
void
connect(int timeout)
Connects to the server.void
disconnect()
Disconnects from the server.com.vmware.vim25.mo.HostSystem
getHostSystemByManagedObjectId(String managedObjectId)
Returns a host system by a given managed object Id.TreeSet<String>
getHostSystemIpAddresses(com.vmware.vim25.mo.HostSystem hostSystem)
Searches for all ip addresses of a host systemint
getMajorApiVersion()
Return the major API version for this management servercom.vmware.vim25.mo.ManagedEntity
getManagedEntityByManagedObjectId(String managedObjectId)
Returns a managed entitiy for a given managed object Id.Map<Integer,com.vmware.vim25.PerfCounterInfo>
getPerfCounterInfoMap()
This method retrieves the performance counters available.String
getPrimaryHostSystemIpAddress(com.vmware.vim25.mo.HostSystem hostSystem)
Searches for the primary ip address of a host system.String
getPropertyOfCimObject(org.sblim.wbem.cim.CIMObject cimObject, String propertyName)
Returns the value of a given cim object and property.int
getTimeout()
com.vmware.vim25.mo.VirtualMachine
getVirtualMachineByManagedObjectId(String managedObjectId)
Returns a virtual machine by a given managed object Id.TreeSet<String>
getVirtualMachineIpAddresses(com.vmware.vim25.mo.VirtualMachine virtualMachine)
Searches for all ip addresses of a virtual machineList<org.sblim.wbem.cim.CIMObject>
queryCimObjects(com.vmware.vim25.mo.HostSystem hostSystem, String cimClass)
Queries a host system for Cim data.List<org.sblim.wbem.cim.CIMObject>
queryCimObjects(com.vmware.vim25.mo.HostSystem hostSystem, String cimClass, String primaryIpAddress)
Queries a host system for Cim data.VmwarePerformanceValues
queryPerformanceValues(com.vmware.vim25.mo.ManagedEntity managedEntity)
This method queries performance values for a given managed entity.protected void
relax()
This method is used to "relax" the policies concerning self-signed certificates.com.vmware.vim25.mo.ManagedEntity[]
searchManagedEntities(String type)
Searches for a managed entity by a given type.static void
setServiceInstancePool(ServiceInstancePool serviceInstancePool)
boolean
setTimeout(int timeout)
Sets the timeout for server connections.
-
-
-
Field Detail
-
DEFAULT_TIMEOUT
public static final int DEFAULT_TIMEOUT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
VmwareViJavaAccess
public VmwareViJavaAccess(String hostname, String username, String password)
Constructor for creating a instance for a given server and credentials.- Parameters:
hostname
- the vCenter's hostnameusername
- the usernamepassword
- the password
-
VmwareViJavaAccess
public VmwareViJavaAccess(String hostname) throws IOException
Constructor for creating a instance for a given server. Checks whether credentials are available in the Vmware config file.- Parameters:
hostname
- the vCenter's hostname- Throws:
IOException
-
VmwareViJavaAccess
public VmwareViJavaAccess(VmwareServer vmwareServer)
-
-
Method Detail
-
getTimeout
public int getTimeout()
-
connect
public void connect(int timeout) throws MalformedURLException, RemoteException
Connects to the server.- Throws:
MalformedURLException
RemoteException
-
connect
public void connect() throws MalformedURLException, RemoteException
- Throws:
MalformedURLException
RemoteException
-
setTimeout
public boolean setTimeout(int timeout)
Sets the timeout for server connections.- Parameters:
timeout
- the timeout to be used for connecting- Returns:
- true, if the operation was successful
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
-
disconnect
public void disconnect()
Disconnects from the server.
-
relax
protected void relax()
This method is used to "relax" the policies concerning self-signed certificates.
-
getPerfCounterInfoMap
public Map<Integer,com.vmware.vim25.PerfCounterInfo> getPerfCounterInfoMap()
This method retrieves the performance counters available.- Returns:
- a map of performance counters
-
getManagedEntityByManagedObjectId
public com.vmware.vim25.mo.ManagedEntity getManagedEntityByManagedObjectId(String managedObjectId)
Returns a managed entitiy for a given managed object Id.- Parameters:
managedObjectId
- the managed object Id- Returns:
- the managed entity
-
getVirtualMachineByManagedObjectId
public com.vmware.vim25.mo.VirtualMachine getVirtualMachineByManagedObjectId(String managedObjectId)
Returns a virtual machine by a given managed object Id.- Parameters:
managedObjectId
- the managed object Id- Returns:
- the virtual machine object
-
getHostSystemByManagedObjectId
public com.vmware.vim25.mo.HostSystem getHostSystemByManagedObjectId(String managedObjectId)
Returns a host system by a given managed object Id.- Parameters:
managedObjectId
- the managed object Id- Returns:
- the host system object
-
queryPerformanceValues
public VmwarePerformanceValues queryPerformanceValues(com.vmware.vim25.mo.ManagedEntity managedEntity) throws RemoteException
This method queries performance values for a given managed entity.- Parameters:
managedEntity
- the managed entity to query- Returns:
- the perfomance values
- Throws:
RemoteException
-
queryCimObjects
public List<org.sblim.wbem.cim.CIMObject> queryCimObjects(com.vmware.vim25.mo.HostSystem hostSystem, String cimClass, String primaryIpAddress) throws ConnectException, RemoteException, org.sblim.wbem.cim.CIMException
Queries a host system for Cim data.- Parameters:
hostSystem
- the host system to querycimClass
- the class of Cim objects to retrieveprimaryIpAddress
- the Ip address to use- Returns:
- the list of Cim objects
- Throws:
RemoteException
org.sblim.wbem.cim.CIMException
ConnectException
-
queryCimObjects
public List<org.sblim.wbem.cim.CIMObject> queryCimObjects(com.vmware.vim25.mo.HostSystem hostSystem, String cimClass) throws ConnectException, RemoteException, org.sblim.wbem.cim.CIMException
Queries a host system for Cim data.- Parameters:
hostSystem
- the host system to querycimClass
- the class of Cim objects to retrieve- Returns:
- the list of Cim objects
- Throws:
RemoteException
org.sblim.wbem.cim.CIMException
ConnectException
-
getPrimaryHostSystemIpAddress
public String getPrimaryHostSystemIpAddress(com.vmware.vim25.mo.HostSystem hostSystem)
Searches for the primary ip address of a host system.The idea is to resolve the HostSystem's name and use the resulting IP if the IP is listed on the available addresses list, otherwise, use the first ip listed on the available list.
- Parameters:
hostSystem
- the host system to query- Returns:
- the primary ip address
-
getHostSystemIpAddresses
public TreeSet<String> getHostSystemIpAddresses(com.vmware.vim25.mo.HostSystem hostSystem)
Searches for all ip addresses of a host system- Parameters:
hostSystem
- the host system to query- Returns:
- the ip addresses of the host system, the first one is the primary
-
getVirtualMachineIpAddresses
public TreeSet<String> getVirtualMachineIpAddresses(com.vmware.vim25.mo.VirtualMachine virtualMachine)
Searches for all ip addresses of a virtual machine- Parameters:
virtualMachine
- the virtual machine to query- Returns:
- the ip addresses of the virtual machine, the first one is the primary
-
searchManagedEntities
public com.vmware.vim25.mo.ManagedEntity[] searchManagedEntities(String type) throws RemoteException
Searches for a managed entity by a given type.- Parameters:
type
- the type string to search for- Returns:
- the list of managed entities found
- Throws:
RemoteException
-
getMajorApiVersion
public int getMajorApiVersion()
Return the major API version for this management server- Returns:
- the major API version
-
getPropertyOfCimObject
public String getPropertyOfCimObject(org.sblim.wbem.cim.CIMObject cimObject, String propertyName)
Returns the value of a given cim object and property.- Parameters:
cimObject
- the Cim objectpropertyName
- the property's name- Returns:
- the value
-
setServiceInstancePool
public static void setServiceInstancePool(ServiceInstancePool serviceInstancePool)
-
-