Class VmwareViJavaAccess


  • public class VmwareViJavaAccess
    extends java.lang.Object
    The Class VmwareViJavaAccess

    This 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​(java.lang.String hostname)
      Constructor for creating a instance for a given server.
      VmwareViJavaAccess​(java.lang.String hostname, java.lang.String username, java.lang.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 connect()  
      void connect​(int timeout)
      Connects to the server.
      void disconnect()
      Disconnects from the server.
      com.vmware.vim25.mo.HostSystem getHostSystemByManagedObjectId​(java.lang.String managedObjectId)
      Returns a host system by a given managed object Id.
      java.util.TreeSet<java.lang.String> getHostSystemIpAddresses​(com.vmware.vim25.mo.HostSystem hostSystem)
      Searches for all ip addresses of a host system
      int getMajorApiVersion()
      Return the major API version for this management server
      com.vmware.vim25.mo.ManagedEntity getManagedEntityByManagedObjectId​(java.lang.String managedObjectId)
      Returns a managed entitiy for a given managed object Id.
      java.util.Map<java.lang.Integer,​com.vmware.vim25.PerfCounterInfo> getPerfCounterInfoMap()
      This method retrieves the performance counters available.
      java.lang.String getPrimaryHostSystemIpAddress​(com.vmware.vim25.mo.HostSystem hostSystem)
      Searches for the primary ip address of a host system.
      java.lang.String getPropertyOfCimObject​(org.sblim.wbem.cim.CIMObject cimObject, java.lang.String propertyName)
      Returns the value of a given cim object and property.
      int getTimeout()  
      com.vmware.vim25.mo.VirtualMachine getVirtualMachineByManagedObjectId​(java.lang.String managedObjectId)
      Returns a virtual machine by a given managed object Id.
      java.util.TreeSet<java.lang.String> getVirtualMachineIpAddresses​(com.vmware.vim25.mo.VirtualMachine virtualMachine)
      Searches for all ip addresses of a virtual machine
      java.util.List<org.sblim.wbem.cim.CIMObject> queryCimObjects​(com.vmware.vim25.mo.HostSystem hostSystem, java.lang.String cimClass)
      Queries a host system for Cim data.
      java.util.List<org.sblim.wbem.cim.CIMObject> queryCimObjects​(com.vmware.vim25.mo.HostSystem hostSystem, java.lang.String cimClass, java.lang.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​(java.lang.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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • VmwareViJavaAccess

        public VmwareViJavaAccess​(java.lang.String hostname,
                                  java.lang.String username,
                                  java.lang.String password)
        Constructor for creating a instance for a given server and credentials.
        Parameters:
        hostname - the vCenter's hostname
        username - the username
        password - the password
      • VmwareViJavaAccess

        public VmwareViJavaAccess​(java.lang.String hostname)
                           throws java.io.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:
        java.io.IOException
      • VmwareViJavaAccess

        public VmwareViJavaAccess​(VmwareServer vmwareServer)
    • Method Detail

      • getTimeout

        public int getTimeout()
      • connect

        public void connect​(int timeout)
                     throws java.net.MalformedURLException,
                            java.rmi.RemoteException
        Connects to the server.
        Throws:
        java.net.MalformedURLException
        java.rmi.RemoteException
      • connect

        public void connect()
                     throws java.net.MalformedURLException,
                            java.rmi.RemoteException
        Throws:
        java.net.MalformedURLException
        java.rmi.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
      • 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 java.util.Map<java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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 java.rmi.RemoteException
        This method queries performance values for a given managed entity.
        Parameters:
        managedEntity - the managed entity to query
        Returns:
        the perfomance values
        Throws:
        java.rmi.RemoteException
      • queryCimObjects

        public java.util.List<org.sblim.wbem.cim.CIMObject> queryCimObjects​(com.vmware.vim25.mo.HostSystem hostSystem,
                                                                            java.lang.String cimClass,
                                                                            java.lang.String primaryIpAddress)
                                                                     throws java.net.ConnectException,
                                                                            java.rmi.RemoteException,
                                                                            org.sblim.wbem.cim.CIMException
        Queries a host system for Cim data.
        Parameters:
        hostSystem - the host system to query
        cimClass - the class of Cim objects to retrieve
        primaryIpAddress - the Ip address to use
        Returns:
        the list of Cim objects
        Throws:
        java.rmi.RemoteException
        org.sblim.wbem.cim.CIMException
        java.net.ConnectException
      • queryCimObjects

        public java.util.List<org.sblim.wbem.cim.CIMObject> queryCimObjects​(com.vmware.vim25.mo.HostSystem hostSystem,
                                                                            java.lang.String cimClass)
                                                                     throws java.net.ConnectException,
                                                                            java.rmi.RemoteException,
                                                                            org.sblim.wbem.cim.CIMException
        Queries a host system for Cim data.
        Parameters:
        hostSystem - the host system to query
        cimClass - the class of Cim objects to retrieve
        Returns:
        the list of Cim objects
        Throws:
        java.rmi.RemoteException
        org.sblim.wbem.cim.CIMException
        java.net.ConnectException
      • getPrimaryHostSystemIpAddress

        public java.lang.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 java.util.TreeSet<java.lang.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 java.util.TreeSet<java.lang.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​(java.lang.String type)
                                                                  throws java.rmi.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:
        java.rmi.RemoteException
      • getMajorApiVersion

        public int getMajorApiVersion()
        Return the major API version for this management server
        Returns:
        the major API version
      • getPropertyOfCimObject

        public java.lang.String getPropertyOfCimObject​(org.sblim.wbem.cim.CIMObject cimObject,
                                                       java.lang.String propertyName)
        Returns the value of a given cim object and property.
        Parameters:
        cimObject - the Cim object
        propertyName - the property's name
        Returns:
        the value
      • setServiceInstancePool

        public static void setServiceInstancePool​(ServiceInstancePool serviceInstancePool)