Connect to VMware
vSphere
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 indicatingTRUEfor read-only access, often faster, orFALSEfor read/write access. If connecting read-only, later calls toVixDiskLib_Open()are always read-only regardless of theopenFlagssetting.
- 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 associatedvmxSpecproperty inconnectParams. When connecting to an ESXi host, provide the ESXiMoRef. When connecting by vCenter Server, pass the vSphereMoRef, which differs.
- Preferred transport method, orNULLto accept the defaults. If you specify any advanced transport mode as the only method, and that method is not available, theVixDiskLib_ConnectEx()call does not fail, but the subsequentVixDiskLib_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; }