protected override void Run() { SafeToExit = false; 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)); } } List<string> validationErrors; OVF.Validate(m_package.PackageSourceFile, out validationErrors); 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_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]); } var appName = m_ovfEnvelope.Name; if (string.IsNullOrEmpty(appName)) appName = Path.GetFileNameWithoutExtension(m_package.PackageSourceFile); EnvelopeType env = OVF.Merge(envelopes, appName); try //importVM { m_transportAction = new Import(uri, session) { ApplianceName = appName, 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 as Import).Process(env, Path.GetDirectoryName(m_package.PackageSourceFile), m_password); } catch (OperationCanceledException) { throw new CancelledException(); } PercentComplete = 100; Description = Messages.COMPLETED; }
protected override void Run() { base.Run(); Debug.Assert(m_vmMappings.Count == 1, "There is one VM mapping"); string systemid = m_vmMappings.Keys.ElementAt(0); var mapping = m_vmMappings.Values.ElementAt(0); var session = Connection.Session; var url = session.Url; Uri uri = new Uri(url); PercentComplete = 20; Description = Messages.IMPORTING_DISK_IMAGE; //create a copy of the ovf envelope EnvelopeType[] envs = OVF.Split(m_ovfEnvelope, "system", new object[] {new[] {systemid}}); EnvelopeType curEnv = envs[0]; //storage foreach (var kvp in mapping.Storage) OVF.SetTargetSRInRASD(curEnv, systemid, kvp.Key, kvp.Value.uuid); //network foreach (var kvp in mapping.Networks) OVF.SetTargetNetworkInRASD(curEnv, systemid, kvp.Key, kvp.Value.uuid); if (m_runfixups) { string cdId = OVF.SetRunOnceBootCDROMOSFixup(curEnv, systemid, m_directory); OVF.SetTargetISOSRInRASD(curEnv, systemid, cdId, m_selectedIsoSr.uuid); } try //importVM { m_transportAction = new Import(uri, session) { 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 as Import).Process(curEnv, m_directory, null); PercentComplete = 100; Description = Messages.COMPLETED; } catch (OperationCanceledException) { throw new CancelledException(); } }