Connect the extension to
vCenter Server
Last Updated December 16, 2024

You must provide information about the
vCenter Server
instance to which you connect an extension. Set the details of the connection to
vCenter Server
in the client-side stub of the extension.
If you deploy your extension using the Open Virtualization Format (OVF), you can integrate it with the vCenter Extension vService. The vCenter Extension vService automates the process of registering extension with
vCenter Server
, so you do not need to provide any connection parameters. See How do I integrate an extension with the vCenter Extension vService.
To connect an extension to
vCenter Server
, provide the following information to the client-side stub of the connection.
  • A username and password for a
    vCenter Server
    administrator account, if you do not use the vCenter Extension vService
  • The extension key for the extension
  • A reference to the
    SessionManager
    instance in the
    vCenter Server
You can define the connection to
vCenter Server
in the
MyVimConnection
class.
The
MyManager
class can perform the following functions.
  • Implement the
    MyVimConnection
    class to establish the connection to
    vCenter Server
    when the My Solution starts.
  • Uses the Spring framework to obtain the connection information from the
    mysolution.properties
    file that you configure when you set up My Solution.
  • Passes the connection property values to
    MyVimConnection
    .
  1. Create an instance of the
    ManagedObjectReference
    data object to define the connection to the extension.
    The
    MyVimConnection
    class creates a
    ManagedObjectReference
    object of type
    ServiceInstance
    , named
    _siRef
    .
    public MyVimConnection(String host, int port) {
       [...]
       _siRef = new ManagedObjectReference();
       _siRef.setType("ServiceInstance");
       _siRef.setValue("ServiceInstance"); 
      }
  2. Define methods to get and set the
    vCenter Server
    host, ports, username, password, connection timeout, and session cookie.
    The
    MyVimConnection
    constructor defines methods to obtain the host, ports, username, password, connection timeout, and session cookie from the information that you set in the
    mysolution
    .properties
    file.
  3. Connect to
    vCenter Server
    by obtaining the
    SessionManager
    managed object for the
    vCenter Server
    .
    MyVimConnection.java
    defines a method named
    connect()
    . The
    connect()
    method defines a standard connection to
    vCenter Server
    that uses WSDL. The following segment shows the calls to the
    SessionManager.login()
    and
    SessionManager.loginExtensionByCertificate()
    methods that establish the connection to
    vCenter Server
    . The
    _stub
    variable is an instance of
    VimPortType
    ,
    _sc
    is a
    ServiceContent
    object, and
    _siRef
    is the
    ManagedObjectReference
    object of type
    ServiceInstance
    .
    private synchronized void connect() {
        [...]
        try {
            [...]
            VimService locator = new VimService(wsdlURL, new QName("urn:vim25Service",
                                                                   "VimService"));
    
            _stub = locator.getVimPort();
            [...]
    
            _sc = _stub.retrieveServiceContent(_siRef);
    
            ManagedObjectReference sessionManager = _sc.getSessionManager();
    
            if (_extensionKey == null) {
              _stub.login(sessionManager, _username, _password, null);
            }
            else {
              _stub.loginExtensionByCertificate(sessionManager, _extensionKey, null);
            }
        [...]
         _connectionStatus = ConnectionStatus.Connected;
        } catch (Exception e) {
            _logger.error(e, e);
        }
      }
  4. Register the extension by calling the
    ExtensionManager.registerExtension()
    method.
    MyVimConnection
    defines a
    registerExtension()
    method that implements
    ExtensionManager.registerExtension()
    .
    MyManager
    calls
    MyVimConnection.registerExtension()
    after it has set the properties for the extension.
    public void registerExtension(Extension ex) {
        try {
             Extension findExtension = _stub.findExtension(_sc.getExtensionManager(),
                                                           ex.getKey());
             if (findExtension == null) {
                 _stub.registerExtension(_sc.getExtensionManager(), ex);
             } else {
                 _stub.updateExtension(_sc.getExtensionManager(), ex);
             }
             _stub.setExtensionCertificate(_sc.getExtensionManager(),
                                           ex.getKey(), null);
             } catch (Exception e) { 
                 _logger.error(e, e); 
             }
      }
You registered an extension with
vCenter Server
.
Provide an extension key with which to register the extension with
vCenter Server
.