Restoring vApps

During the restore process, the backup software typically restores a virtual machine in vSphere using the virtual machine configuration and disk files. In situations where the vApp has been lost from the vCloud Director inventory, the backup software needs to first restore the virtual machine in vSphere, and then import the virtual machine into vCloud Director.
Although the vApp may contain multiple virtual machines in the view of vCloud Director, the virtual machines are known individually to vSphere. To complete the restore operation, the backup software needs to re-create the restored vApp so that all the member virtual machines are created as child virtual machines of the vApp.
To re-create the vApp using the vCloud SDK for .NET, the backup software must use two method calls:
ImportVmAsVapp
and
ImportVmIntoVapp
. Use the
ImportVmAsVapp
method to create a vApp from any one of the child virtual machines. Then call the
ImportVmIntoVapp
method once for each remaining child virtual machine. The following example shows how to use both methods to create a vApp using the vCloud SDK.
// Importing Virtual Machines into vApps /// <summary> /// Reference to hold the vCloud Client reference /// </summary> private static VcloudAdminExtension extension = null; vcloudClient.login(user, password); extension = vcloudClient.getVcloudAdminExtension(); // Get references for known VIM Servers Dictionary<string, ReferenceType> vimServerRefsByName = extension.GetVMWVimServerRefsByName(); // Select VIM Server Reference VMWVimServer vimServer = VMWVimServer.GetVMWVimServerByReference(vcloudClient, vimServerRefsByName[vimServerName]); ... // Import first VM from VIM server as vApp: ImportVmIntoVAppParamsType importVmIntoVAppParamsType = new ImportVmIntoVAppParamsType(); importVmIntoVAppParamsType.vmMoRefField = moref; // vSphere ID from backup data. importVmIntoVAppParamsType.vdcField = vdcRef; // vDC where the new vApp will be created. Vapp vapp = vimServer.ImportVmAsVApp(importVmAsVAppParamsType); // Task is embedded in vapp. ... foreach (VM vm in vms) { // Import remaining VMs from VIM Server into existing vApp: … importVmIntoVAppParamsType.vmMoRefField = moref; // vSphere ID from backup data. importVmIntoVAppParamsType.vAppField = vapp; // vApp to hold restored VMs. Task task = vimServer.ImportVmIntoVApp(importVmIntoVAppParamsType); … };
The following example shows the corresponding REST API calls used to rebuild a vApp in vCloud Director.
POST https://vCloud/api/admin/extension/vimServer/id/importVmAsVApp POST https://vCloud/api/admin/extension/vimServer/id/importVmIntoExistingVApp