VixDiskLib_ConnectEx() connects the library to managed disk on a remote ESXi host or through VMware vCenter Server. For hosted disk on the local system, it works the same as VixDiskLib_Connect(). VixDiskLib_ConnectEx() takes three additional parameters:

  • Boolean indicating TRUE for read-only access, often faster, or FALSE for read/write access. If connecting read-only, later calls to VixDiskLib_Open() are always read-only regardless of the openFlags setting.
  • Managed object reference (MoRef) of the snapshot to access using this connection. This is required for most transport methods (SAN, HotAdd, NBDSSL) and to access a powered-on virtual machine. You must also specify the associated vmxSpec property in connectParams. When connecting to an ESXi host, provide the ESXi MoRef. When connecting by vCenter Server, pass the vSphere MoRef, which differs.
  • Preferred transport method, or NULL to accept the defaults. If you specify any advanced transport mode as the only method, and that method is not available, the VixDiskLib_ConnectEx() call does not fail, but the subsequent VixDiskLib_Open() call will fall back to NBDSSL mode.
    VixDiskLibConnectParams cnxParams = {0};
    if (appGlobals.isRemote) {
         cnxParams.vmName = vmxSpec;
         cnxParams.serverName = hostName;
         cnxParams.credType = VIXDISKLIB_CRED_UID;
         cnxParams.creds.uid.userName = userName;
         cnxParams.creds.uid.password = password;
         cnxParams.port = port;
    }
    VixError vixError = VixDiskLib_ConnectEx(&cnxParams, TRUE, "snapshot-47", NULL, &connection);

When a program calls VixDiskLib_ConnectEx() with NULL parameter to accept default transport mode, SAN is selected as the preferred mode, if SAN storage is available from the ESXi host. Then if the program opens a virtual disk on local storage, subsequent writes will fail. In this case, the program should explicitly pass nbdssl as the preferred transport mode.

The port is where vCenter Server listens for API queries. Specifying null allows the library to select the port, usually 443 (HTTPS). By default VADP uses the same port for virtual machine operations as other SOAP-based Web Services. By default VDDK uses port 902 (VIX automation) for NBDSSL data transport.

Connect to ESXi hosts

In the connection parameters cnxParams, the vmxSpec managed object reference would be different on an ESXi host than on the vCenter Server, as shown below. ESXi hosts offer no prepare-for and end access protection. Otherwise ESXi host connections are similar to vCenter Server connections.

vmxSpec = "moid=23498";
vmxSpec = "moid=898273";

Reuse a vCenter Server Session

As of vSphere 6.5, you can recycle a vCenter Server session to avoid session overflow. Set the credential type to VIXDISKLIB_CRED_SESSIONID and supply the value of vmware_soap_session from a still-live vCenter Server session. For NBD(SSL) and HotAdd transport, the sessionId.key password can be any non-empty string. For SAN transport, you must specify the actual password.

if (appGlobals.isRemote) {
     cnxParams.vmName = vmxSpec;
     cnxParams.serverName = hostName;
     cnxParams.credType = VIXDISKLIB_CRED_SESSIONID;
     cnxParams.creds.sessionId.cookie = cookie;
     cnxParams.creds.sessionId.userName = userName;
     cnxParams.creds.sessionId.key = "reuse"; /* password */
     cnxParams.port = port;
}