private void ExportVApp() { string vApp = cb.get_option("vapp"); localPath = cb.get_option("localpath"); ManagedObjectReference vAppMoRef = cb._svcUtil.getEntityByName("VirtualApp", vApp); if (vAppMoRef != null) { OvfCreateDescriptorParams ovfCreateDescriptorParams = new OvfCreateDescriptorParams(); Console.WriteLine("Getting the HTTP NFCLEASE for the vApp: " + vApp); ManagedObjectReference httpNfcLease = cb._connection._service.ExportVApp(vAppMoRef); HttpNfcLeaseInfo httpNfcLeaseInfo = null; Object[] result = cb._svcUtil.WaitForValues(httpNfcLease, new String[] { "state" }, new String[] { "state" }, new Object[][] { new Object[] { "ready", "error" } }); if (result[0].Equals("ready")) { httpNfcLeaseInfo = cb._svcUtil.GetDynamicProperty(httpNfcLease, "info") as HttpNfcLeaseInfo; httpNfcLeaseInfo.leaseTimeout = 300000000; PrintHttpNfcLeaseInfo(httpNfcLeaseInfo); long diskCapacity = (httpNfcLeaseInfo.totalDiskCapacityInKB) * 1024; Console.WriteLine("************ " + diskCapacity); HttpNfcLeaseDeviceUrl[] deviceUrlArr = httpNfcLeaseInfo.deviceUrl; if (deviceUrlArr != null) { Console.WriteLine("Downloading Files:"); List <OvfFile> ovfFiles = new List <OvfFile>(); foreach (HttpNfcLeaseDeviceUrl urlArray in deviceUrlArr) { string deviceId = urlArray.key; string deviceUrlStr = urlArray.url; string absoluteFile = deviceUrlStr.Substring(deviceUrlStr.LastIndexOf("/") + 1); Console.WriteLine(" Absolute File Name: " + absoluteFile); Console.WriteLine(" VMDK URL: " + deviceUrlStr); long writtenSize = WriteVMDKFile(absoluteFile, deviceUrlStr); OvfFile ovfFile = new OvfFile(); ovfFile.path = absoluteFile; ovfFile.deviceId = deviceId; ovfFile.size = writtenSize; ovfFiles.Add(ovfFile); } ovfCreateDescriptorParams.ovfFiles = ovfFiles.ToArray(); OvfCreateDescriptorResult ovfCreateDescriptorResult = cb._connection._service.CreateDescriptor( cb._connection._sic.ovfManager, vAppMoRef, ovfCreateDescriptorParams); String outOvf = localPath + "/" + vApp + ".ovf"; File.WriteAllText(outOvf, ovfCreateDescriptorResult.ovfDescriptor); Console.WriteLine("OVF Desriptor Written to file " + vApp + ".ovf"); Console.WriteLine("DONE"); if (ovfCreateDescriptorResult.error != null) { Console.WriteLine("Following Errors occured:"); foreach (LocalizedMethodFault lf in ovfCreateDescriptorResult.error) { Console.WriteLine(lf.localizedMessage); } } if (ovfCreateDescriptorResult.warning != null) { Console.WriteLine("Following Warnings occured:"); foreach (LocalizedMethodFault lf in ovfCreateDescriptorResult.warning) { Console.WriteLine(lf.localizedMessage); } } } else { Console.WriteLine("No url found"); } Console.WriteLine("Completed Downloading the files"); cb._connection._service.HttpNfcLeaseProgress(httpNfcLease, 100); cb._connection._service.HttpNfcLeaseComplete(httpNfcLease); } else { throw new Exception("Error happened while acquiring HttpNfcLease"); } } else { throw new Exception("vApp not found"); } }
private void ExportVApp() { string vApp = cb.get_option("vapp"); localPath = cb.get_option("localpath"); ManagedObjectReference vAppMoRef = cb._svcUtil.getEntityByName("VirtualApp", vApp); if (vAppMoRef != null) { OvfCreateDescriptorParams ovfCreateDescriptorParams = new OvfCreateDescriptorParams(); Console.WriteLine("Getting the HTTP NFCLEASE for the vApp: " + vApp); ManagedObjectReference httpNfcLease = cb._connection._service.ExportVApp(vAppMoRef); HttpNfcLeaseInfo httpNfcLeaseInfo = null; Object[] result = cb._svcUtil.WaitForValues(httpNfcLease, new String[] { "state" }, new String[] { "state" }, new Object[][] { new Object[] { "ready", "error" } }); if (result[0].Equals("ready")) { httpNfcLeaseInfo = cb._svcUtil.GetDynamicProperty(httpNfcLease, "info") as HttpNfcLeaseInfo; httpNfcLeaseInfo.leaseTimeout = 300000000; PrintHttpNfcLeaseInfo(httpNfcLeaseInfo); long diskCapacity = (httpNfcLeaseInfo.totalDiskCapacityInKB) * 1024; Console.WriteLine("************ " + diskCapacity); HttpNfcLeaseDeviceUrl[] deviceUrlArr = httpNfcLeaseInfo.deviceUrl; if (deviceUrlArr != null) { Console.WriteLine("Downloading Files:"); List<OvfFile> ovfFiles = new List<OvfFile>(); foreach (HttpNfcLeaseDeviceUrl urlArray in deviceUrlArr) { string deviceId = urlArray.key; string deviceUrlStr = urlArray.url; string absoluteFile = deviceUrlStr.Substring(deviceUrlStr.LastIndexOf("/") + 1); Console.WriteLine(" Absolute File Name: " + absoluteFile); Console.WriteLine(" VMDK URL: " + deviceUrlStr); long writtenSize = WriteVMDKFile(absoluteFile, deviceUrlStr); OvfFile ovfFile = new OvfFile(); ovfFile.path = absoluteFile; ovfFile.deviceId = deviceId; ovfFile.size = writtenSize; ovfFiles.Add(ovfFile); } ovfCreateDescriptorParams.ovfFiles = ovfFiles.ToArray(); OvfCreateDescriptorResult ovfCreateDescriptorResult = cb._connection._service.CreateDescriptor( cb._connection._sic.ovfManager, vAppMoRef, ovfCreateDescriptorParams); String outOvf = localPath + "/" + vApp + ".ovf"; File.WriteAllText(outOvf, ovfCreateDescriptorResult.ovfDescriptor); Console.WriteLine("OVF Desriptor Written to file " + vApp + ".ovf"); Console.WriteLine("DONE"); if (ovfCreateDescriptorResult.error != null) { Console.WriteLine("Following Errors occured:"); foreach (LocalizedMethodFault lf in ovfCreateDescriptorResult.error) { Console.WriteLine(lf.localizedMessage); } } if (ovfCreateDescriptorResult.warning != null) { Console.WriteLine("Following Warnings occured:"); foreach (LocalizedMethodFault lf in ovfCreateDescriptorResult.warning) { Console.WriteLine(lf.localizedMessage); } } } else { Console.WriteLine("No url found"); } Console.WriteLine("Completed Downloading the files"); cb._connection._service.HttpNfcLeaseProgress(httpNfcLease, 100); cb._connection._service.HttpNfcLeaseComplete(httpNfcLease); } else { throw new Exception("Error happened while acquiring HttpNfcLease"); } } else { throw new Exception("vApp not found"); } }