public EnvelopeType Process(string targetPath, string ovfname, string[] vmUuid) { List <EnvelopeType> envList = new List <EnvelopeType>(); foreach (string vmuuid in vmUuid) { envList.Add(_export(XenSession, targetPath, ovfname, vmuuid)); } EnvelopeType ovfEnv = OVF.Merge(envList, ovfname); if (AutoSave) { string ovffilename = Path.Combine(targetPath, string.Format(@"{0}.ovf", ovfname)); OVF.SaveAs(ovfEnv, ovffilename); } OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.ExportThreadComplete, "Export", Messages.COMPLETED_EXPORT)); return(ovfEnv); }
protected override void Run() { base.Run(); if (m_verifySignature) { Description = Messages.VERIFYING_SIGNATURE; try { // The appliance is known to have a signature and the user asked to verify it. m_package.VerifySignature(); // If the appliance has a signature, then it has a manifest. // Always verify the manifest after verifying the signature. m_package.VerifyManifest(); } catch (Exception e) { throw new Exception(String.Format(Messages.VERIFYING_SIGNATURE_ERROR, e.Message)); } } else if (m_verifyManifest) { Description = Messages.VERIFYING_MANIFEST; try { // The appliance had a manifest without a signature and the user asked to verify it. // VerifyManifest() throws an exception when verification fails for any reason. m_package.VerifyManifest(); } catch (Exception e) { throw new Exception(String.Format(Messages.VERIFYING_MANIFEST_ERROR, e.Message)); } } PercentComplete = 20; Description = Messages.IMPORTING_VMS; var session = Connection.Session; var url = session.Url; Uri uri = new Uri(url); //create a copy of the OVF var envelopes = new List <EnvelopeType>(); foreach (var vmMapping in m_vmMappings) { if (Cancelling) { throw new CancelledException(); } string systemid = vmMapping.Key; var mapping = vmMapping.Value; EnvelopeType[] envs = OVF.Split(m_package.OvfEnvelope, "system", new object[] { new[] { systemid } }); //storage foreach (var kvp in mapping.Storage) { OVF.SetTargetSRInRASD(envs[0], systemid, kvp.Key, kvp.Value.uuid); } foreach (var kvp in mapping.StorageToAttach) { OVF.SetTargetVDIInRASD(envs[0], systemid, kvp.Key, kvp.Value.uuid); } //network foreach (var kvp in mapping.Networks) { OVF.SetTargetNetworkInRASD(envs[0], systemid, kvp.Key, kvp.Value.uuid); } if (m_runfixups) { string cdId = OVF.SetRunOnceBootCDROMOSFixup(envs[0], systemid, Path.GetDirectoryName(m_package.PackageSourceFile)); OVF.SetTargetISOSRInRASD(envs[0], systemid, cdId, m_selectedIsoSr.uuid); } envelopes.Add(envs[0]); } EnvelopeType env = OVF.Merge(envelopes, m_package.Name); m_package.ExtractToWorkingDir(); try //importVM { m_transportAction = new Import(uri, session) { ApplianceName = m_package.Name, UpdateHandler = UpdateHandler, Cancel = Cancelling //in case the Cancel button has already been pressed }; m_transportAction.SetTvmNetwork(m_networkUuid, m_isTvmIpStatic, m_tvmIpAddress, m_tvmSubnetMask, m_tvmGateway); m_transportAction.Process(env, m_package.WorkingDir, m_password); } catch (OperationCanceledException) { throw new CancelledException(); } finally { m_package.CleanUpWorkingDir(); } PercentComplete = 100; Description = Messages.COMPLETED; }
protected override void RunCore() { log.Info($"Exporting VMs to package {m_applianceFileName}"); var appFolder = Path.Combine(m_applianceDirectory, m_applianceFileName); var appFile = string.Format("{0}.ovf", m_applianceFileName); if (!Directory.Exists(appFolder)) { Directory.CreateDirectory(appFolder); } var envList = new List <EnvelopeType>(); for (int i = 0; i < m_vmsToExport.Count; i++) { var vm = m_vmsToExport[i]; CheckForCancellation(); Description = string.Format(Messages.EXPORTING_VM_PREPARE, vm.Name()); int curVm = i; void UpdatePercentage(float x) { PercentComplete = (int)((curVm + x) * 80 / m_vmsToExport.Count); } try { var envelope = Export(appFolder, vm, UpdatePercentage); envList.Add(envelope); PercentComplete = (i + 1) * 80 / m_vmsToExport.Count; } catch (OperationCanceledException) { throw new CancelledException(); } } EnvelopeType env = OVF.Merge(envList, m_applianceFileName); PercentComplete = 80; foreach (var eula in m_eulas) { CheckForCancellation(); Description = Messages.ADDING_EULAS; OVF.AddEula(env, eula); } CheckForCancellation(); var ovfPath = Path.Combine(appFolder, appFile); OVF.SaveAs(env, ovfPath); PercentComplete = 85; CheckForCancellation(); if (m_createOVA) { ManifestAndSign(env, appFolder, appFile); PercentComplete = 90; log.Info($"Archiving OVF package {m_applianceFileName} into OVA"); Description = string.Format(Messages.CREATING_OVA_FILE, string.Format("{0}.ova", m_applianceFileName)); OVF.ConvertOVFtoOVA(env, ovfPath, CheckForCancellation, m_compressOVFfiles); } else if (m_compressOVFfiles) { log.Info($"Compressing package {m_applianceFileName}"); Description = Messages.COMPRESSING_FILES; OVF.CompressFiles(env, ovfPath, CompressionFactory.Type.Gz, CheckForCancellation); PercentComplete = 95; ManifestAndSign(env, appFolder, appFile); } else { ManifestAndSign(env, appFolder, appFile); } PercentComplete = 100; Description = Messages.COMPLETED; }
protected override void RunCore() { // The appliance has a signature and the user asked to verify it. if (m_verifySignature) { Description = Messages.VERIFYING_SIGNATURE; try { m_package.VerifySignature(); log.Info($"Verified signature for package {m_package.Name}"); } catch (Exception e) { log.Error($"Signature verification failed for package {m_package.Name}", e); throw new Exception(String.Format(Messages.VERIFYING_SIGNATURE_ERROR, e.Message)); } } // The appliance has // - a signature (in which case it also has a manifest that should be verified AFTER the signature); or // - a manifest without a signature // and the user asked to verify it if (m_verifySignature || m_verifyManifest) { Description = Messages.VERIFYING_MANIFEST; try { m_package.VerifyManifest(); log.Info($"Verified manifest for package {m_package.Name}"); } catch (Exception e) { log.Error($"Manifest verification failed for package {m_package.Name}", e); throw new Exception(String.Format(Messages.VERIFYING_MANIFEST_ERROR, e.Message)); } } PercentComplete = 20; Description = string.Format(Messages.IMPORT_APPLIANCE_PREPARING, m_package.Name); //create a copy of the OVF var envelopes = new List <EnvelopeType>(); foreach (var vmMapping in m_vmMappings) { CheckForCancellation(); string systemid = vmMapping.Key; var mapping = vmMapping.Value; EnvelopeType[] envs = OVF.Split(m_package.OvfEnvelope, "system", new object[] { new[] { systemid } }); //storage foreach (var kvp in mapping.Storage) { OVF.SetTargetSRInRASD(envs[0], systemid, kvp.Key, kvp.Value.uuid); } foreach (var kvp in mapping.StorageToAttach) { OVF.SetTargetVDIInRASD(envs[0], systemid, kvp.Key, kvp.Value.uuid); } //network foreach (var kvp in mapping.Networks) { OVF.SetTargetNetworkInRASD(envs[0], systemid, kvp.Key, kvp.Value.uuid); } if (m_runfixups) { string cdId = OVF.SetRunOnceBootCDROMOSFixup(envs[0], systemid, Path.GetDirectoryName(m_package.PackageSourceFile)); OVF.SetTargetISOSRInRASD(envs[0], systemid, cdId, m_selectedIsoSr.uuid); } envelopes.Add(envs[0]); } EnvelopeType env = OVF.Merge(envelopes, m_package.Name); object importedObject; try //import VMs { m_package.ExtractToWorkingDir(CheckForCancellation); CheckForCancellation(); OVF.ParseEncryption(env, out m_encryptionClass, out m_encryptionVersion); importedObject = Process(env, m_package.WorkingDir, m_package.Name); } catch (OperationCanceledException) { throw new CancelledException(); } finally { m_package.CleanUpWorkingDir(); } PercentComplete = 100; Description = Messages.COMPLETED; if (_startAutomatically && importedObject is XenRef <VM_appliance> applianceRef) { var appliance = Connection.Resolve(applianceRef); if (appliance != null) { new StartApplianceAction(appliance, false).RunAsync(); } } }