Class VCenterClient

java.lang.Object
org.metricshub.vcenter.VCenterClient

public final class VCenterClient extends Object
VCenterClient class for interacting with VMware vCenter server.
  • Method Details

    • setDebug

      public static void setDebug(Supplier<Boolean> isDebugEnabledMethod, Consumer<String> debugMethod)
      Sets the debug methods to be used by the VCenterClient class.

      The VCenterClient class may need to write debug information. However, depending on whether it runs in the context of MatsyaEngine or as a CLI, the debug will need to be handled differently.

      In the case of MatsyaEngine, before making any further call to this class, use setDebug(MatsyaEngine::getDebugMode, MatsyaEngine::debug).

      In the case of CLI, use setDebug() with your own methods (which will probably simply print to stdout).

      Parameters:
      isDebugEnabledMethod - The static method that returns a boolean whether the debug mode is enabled or not
      debugMethod - The static method that will print the debug message somewhere
    • requestCertificate

      public static String requestCertificate(String vCenterName, String username, String password, String hostname) throws com.vmware.vim25.InvalidLogin, Exception
      Request an authentication certificate for the specified hostname from the specified VMware vCenter server.

      The specified hostname must be registered in VMware vCenter so we can get an authentication "token" for it.

      To get this token, we first need to authenticate against VMware vCenter (using the good old username and password mechanism). Then, we will be able to connect to the specified hostname VMware ESX just using this "token"

      Parameters:
      vCenterName - The hostname of IP address of the VMware vCenter system
      username - Credentials to connect to VMware vCenter
      password - Associated password
      hostname - The hostname or IP address of the ESX host that we need an authentication token for
      Returns:
      The authentication token in the form of a String
      Throws:
      com.vmware.vim25.InvalidLogin - when the specified username/password is... well, invalid
      Exception - when anything else happens
    • getAllHostSystemManagedEntities

      public static List<String> getAllHostSystemManagedEntities(String vCenterName, String username, String password) throws Exception
      Retrieve all managed entities of type "HostSystem" in the specified VCenter.
      Parameters:
      vCenterName - The hostname of IP address of the VMware vCenter system
      username - Credentials to connect to VMware vCenter
      password - Associated password
      Returns:
      The list of hostnames (or IP addresses) registered in the VCenter
      Throws:
      com.vmware.vim25.InvalidLogin - for bad credentials
      Exception - when anything else goes south