18.08.2013 Views

Virtual Disk API Programming Guide - Documentation - VMware

Virtual Disk API Programming Guide - Documentation - VMware

Virtual Disk API Programming Guide - Documentation - VMware

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Virtual</strong> <strong>Disk</strong> <strong>Programming</strong> <strong>Guide</strong><br />

VixError vixError = Vix<strong>Disk</strong>Lib_ConnectEx(&cnxParams, TRUE,<br />

"snapshot-47", NULL, &connection);<br />

Even when a program calls Vix<strong>Disk</strong>Lib_ConnectEx() with NULL parameter to accept the default transport<br />

mode, SAN is selected as the preferred mode, if SAN storage is available from the ESX/ESXi host. Then if the<br />

program opens a virtual disk on local storage, subsequent writes will fail. In this case, the program should<br />

explicitly pass nbd or nbdssl as the preferred transport mode.<br />

In the connection parameters cnxParams, the vmxSpec managed object reference would be different on an<br />

ESX/ESXi host than on the vCenter Server:<br />

vmxSpec = "moid=23498";<br />

vmxSpec = "moid=898273";<br />

The port should be the one on which vCenter Server listens for <strong>API</strong> queries. Specifying a null port allows the<br />

library to select the default communications port. It is likely to be 443 (HTTPS) or maybe 902 (VIX automation).<br />

This is the port for data copying, not the port for SOAP requests.<br />

Get Selected Transport Method<br />

The Vix<strong>Disk</strong>Lib_GetTransportMode() function returns the transport method selected for diskHandle.<br />

printf("Selected transport method: %s\n", Vix<strong>Disk</strong>Lib_GetTransportMode(diskHandle));<br />

Prepare For Access and End Access<br />

The Vix<strong>Disk</strong>Lib_PrepareForAccess() function notifies a vCenter‐managed host that a virtual machine’s<br />

disks are being opened, probably for backup, so the host should postpone virtual machine operations that<br />

might interfere with virtual disk access. Call this function before creating a snapshot on a virtual machine.<br />

Internally, this function disables the vSphere <strong>API</strong> method RelocateVM_Task.<br />

vixError = Vix<strong>Disk</strong>Lib_PrepareForAccess(&cnxParams, "vmName");<br />

The connection parameters must indicate one virtual machine only. When opening a managed disk, provide<br />

valid credentials for the vCenter Server that manages the ESXi host with the disk. The second parameter is<br />

currently just for tracking purposes, and could be the virtual machine name or the name of your application.<br />

If you run Vix<strong>Disk</strong>Lib_PrepareForAccess() directly on an ESXi host, the system throws an error saying<br />

“VDDK: HostAgent is not a <strong>Virtual</strong>Center, cannot disable sVmotion.”<br />

Every Vix<strong>Disk</strong>Lib_PrepareForAccess() call should have a matching Vix<strong>Disk</strong>Lib_EndAccess() call.<br />

The Vix<strong>Disk</strong>Lib_EndAccess() function notifies the host that a virtual machine’s disks have been closed, so<br />

operations that rely on the virtual disks to be closed, such as vMotion, can now be allowed. Call this function<br />

after closing all the virtual disks, and after deleting the virtual machine snapshot. Normally this function is<br />

called after previously calling Vix<strong>Disk</strong>Lib_PrepareForAccess, but you can call it to clean up after a crash.<br />

Internally, this function re‐enables the vSphere <strong>API</strong> method RelocateVM_Task.<br />

vixError = Vix<strong>Disk</strong>Lib_EndAccess(&cnxParams, "vmName");<br />

Here is a code snippet showing use of PrepareForAccess in a backup program that waits up to 10 minutes<br />

for Storage vMotion to finish. Regular vMotion would finish much faster than that.<br />

if (appGlobals.vmxSpec != NULL) {<br />

int i;<br />

retry:<br />

vixError = Vix<strong>Disk</strong>Lib_PrepareForAccess(&cnxParams, "VMname");<br />

for (i = 0; i < 10; i++) {<br />

if (vixError != VIX_OK) { // no specific error code for vMotion-in-progress<br />

sleep(60);<br />

goto retry;<br />

}<br />

}<br />

}<br />

38 <strong>VMware</strong>, Inc.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!