xenadmin/XenAdmin/Wizards/ImportWizard/ImportWizard.cs
Danilo Del Busso 4b0b83245f
CP-34231: Remove language with negative connotations (#2860)
* CA-34231: Replace negative language with `block list` in code and references

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `stop` in code and references

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `freezing` in code

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `run/ran` in code comments

Some paramater mentions have been renamed, as they will be renamed in future commits.
Excluded mentions in XenAPI/Host.cs and XenAPI/VM.cs since code is autogenerated.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	CFUValidator/CommandLineOptions/CFUCommandLineOptionManager.cs
#	XenAdmin/Controls/Wlb/WlbOptModeScheduler.cs
#	XenAdmin/Dialogs/Wlb/WorkloadReports.cs

* CA-34231: Replace negative language with `run` in Command.cs Run method

Used Resharper renaming utility
Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/TabPages/GeneralTabPage.cs

* CA-34231: Replace negative language with `run` in Command.cs CanRun method

Used Resharper rename utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `run` in Command.cs CanRunCore method

Used ReSharper rename utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Commands/DRConfigureCommand.cs
#	XenAdmin/Commands/DRDryrunCommand.cs
#	XenAdmin/Commands/DRFailbackCommand.cs
#	XenAdmin/Commands/DRFailoverCommand.cs
#	XenAdmin/Commands/DisasterRecoveryCommand.cs
#	XenAdmin/Commands/VMGroupCommand.cs

* CA-34231: Replace negative language with `run` in Command.cs RunCore method

Used ReSharper rename utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `run` in Command.cs GetCantExecuteReasonCore method

Used ReSharper rename utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `run` in Command.cs GetCantRunReasons method

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace remaining negative language with `run` in Command.cs

Also applied to related symbols. Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `run` in methods named CanRun

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `run` in methods in CrossPoolMigrateCommand.cs

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Commands/CrossPoolMigrateCommand.cs

* CA-34231: Replace negative language with `run` in remaining Run methods

Also updated negative language in `DeleteVMCommand`
Also updated in comment in `CrossPoolMigrateCommand`
Also renamed missed instances of `CanRun`

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `run` in `CanRunCore` and `RunCore`

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace remaining negative language with `run` in Commands folder

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace remaining negative language with `run` in XenAdmin/Controls folder

Used ReSharper renaming utility. Had to rename `WlbReportView.xs:RunReport()` to `WlbReportView.xs:StartRunReport()` to resolve conflict with change from `WlbReportView:ExecuteReport()` to `WlbReportView:RunReport()`

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Controls/Wlb/WlbOptModeScheduler.cs
#	XenAdmin/Dialogs/Wlb/WorkloadReports.cs
#	XenAdminTests/UnitTests/WlbTests/WlbScheduledTaskTests.cs

* CA-34231: Replace all remaining negative language with `run` in code

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Commands/Controls/WlbRecommendations.cs
#	XenAdminTests/UnitTests/WlbTests/WlbScheduledTaskTests.cs
#	XenModel/WLB/WlbScheduledTask.cs

* CA-34231: Replace negative language with `supporter` or `bond member` in code strings

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `supporter` or `bond member` in Messages string

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/MainWindow.cs
#	XenAdmin/Wizards/PatchingWizard/PatchingWizard_SelectServers.cs
#	XenModel/Messages.Designer.cs
#	XenModel/Messages.resx

* CA-34231: Replace remaining negative language with `supporter` in .resx files

Used ReSharper renaming utility. FriendlyErrorNames.resx has been excluded.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `supporter` or `bond member` in XenAdmin code

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Dialogs/NewPoolDialog.cs

* CA-34231: Replace negative language with `supporter` or `bond member` in XenModel code

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `coordinator` in CFUValidator code

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	CFUValidator/CFUValidator.cs

* CA-34231: Replace negative language with `coordinator` in solution's comments and hardcoded strings

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `coordinator` in `Helpers:GetCoordinator` method

Used ReSharper renaming utility.
also renamed similarly named method in `ObjectChange.cs`

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Alerts/Types/HotfixEligibilityAlert.cs
#	XenAdmin/Controls/CustomDataGraph/ArchiveMaintainer.cs

* CA-34231: Replace negative language with `coordinator` in `EvacuateHostDialog.resx`

Used ReSharper renaming utility. Excluded jp and zh resources

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Dialogs/EvacuateHostDialog.resx

* CA-34231: Replace negative language with `coordinator` in `EvacuateHostDialog.resx`

Used ReSharper renaming utility. Excluded jp and zh resource files.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Dialogs/NewPoolDialog.resx

* CA-34231: Rename missing language references for change to `coordinator`

Misc files were not saved before last commits.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `coordinator` in `Messages.resx`'s code

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Commands/HACommand.cs
#	XenAdmin/TabPages/AdPage.cs
#	XenModel/Actions/Network/CreateBondAction.cs
#	XenModel/Actions/Network/NetworkAction.cs
#	XenModel/Messages.Designer.cs
#	XenModel/Messages.resx

* CA-34231: Replace negative language with `coordinator` in `ExternalPluginAction.cs`

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `coordinator` in `XenAdmin/Commands`

Used ReSharper renaming utility. Also replace negative language in missed comment in `ExternalPluginAction.cs`

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Commands/AddHostToPoolCommand.cs
#	XenAdmin/Commands/HACommand.cs

* CA-34231: Replace negative language with `coordinator` in `Helpers.cs`

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `coordinator` in `NetworkingHelper.cs`

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `coordinator` in `PoolJoinRules.cs`

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Dialogs/NewPoolDialog.cs

* CA-34231: Replace negative language with `coordinator` in `XenAdmin/Commands`, `Controls`, and `Core`

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Commands/AddHostToPoolCommand.cs

* CA-34231: Replace negative language with `coordinator` in `XenAdmin/Diagnostics`

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `coordinator` in `XenAdmin/Dialogs`

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Dialogs/NewPoolDialog.cs

* CA-34231: Replace remaining negative language with `coordinator` in `XenAdmin`

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/MainWindow.cs
#	XenAdmin/TabPages/GeneralTabPage.cs
#	XenAdmin/Wizards/PatchingWizard/PatchingWizard_SelectServers.cs
#	XenAdmin/Wizards/RollingUpgradeWizard/RollingUpgradeExtrasPage.cs
#	XenAdmin/Wizards/RollingUpgradeWizard/RollingUpgradeWizard.cs
#	XenAdmin/Wizards/RollingUpgradeWizard/RollingUpgradeWizardPrecheckPage.cs
#	XenAdmin/XenSearch/Columns.cs

* CA-34231: Replace remaining negative language with `coordinator` in `XenModel\Actions`

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenModel/Actions/Network/CreateBondAction.cs

* CA-34231: Replace remaining negative language with `coordinator` in `XenModel`

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace remaining negative strings with `main` in `Messages.resx`

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenModel/Messages.Designer.cs
#	XenModel/Messages.resx

* CA-34231: Replace remaining negative string names with `main` in `Messages.resx`

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Dialogs/OptionsPages/SaveAndRestoreOptionsPage.cs
#	XenModel/Messages.resx

* CA-34231: Rename dialogs to replace negative connotations with `main`

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `main` in `SaveAndResoreOptionsPage.cs`

Also updated its resx file. Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Dialogs/OptionsPages/SaveAndRestoreOptionsPage.cs

* CA-34231: Fix invalid reference in `SaveAndRestoreOptionsPage.Designer.cs` after renaming

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `main` in `EnterMainPasswordDialog.cs`

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `main` in `ChangeMainPasswordDialog.cs`

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Fix invalid reference not changed after renaming `EnterMainPasswordDialog.cs`

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace remaining negative language with `main` in `XenAdmin/Dialogs`

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Update class names in HelpManager.resx

Following renaming of main password dialog. Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `main` in `Metadata.cs`

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Remove remaning negative language with `coordinator` from `Messages.resx`

Used ReSharper renaming

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Remove remaning negative language with `other pool member` from `Messages.resx`

Used ReSharper

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace remaining negative language in solution

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Remove commented out code in VNCGraphicsClient.cs

Code has only been improved partially as it's not strictly relevant to the PR

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Amend negative word replacement in XSVNCScreen.cs

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Simplify debug call formatting in NewPoolDialog.cs

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Add code mistakenly removed in MainWindow.cs

Removed as part of `f155f9c8`

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Revert renaming of constant related to Windows' API

Considered external to CH Center

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Amend hotkey for Coordinator field in `NewPoolDialog`

Previous ALT+<key> hotkey was conflicting with CreatePool

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Remove unecessary whitespace in EvacuateHostDialog.cs

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Update if block to exclude unecessary else in DRFailoverWizard.cs

Not relevant to the PR, but the change is small enought to no need extra testing

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Amend typo in PoolJoinRules.cs

supporer -> supporter

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Replace missing negative language with `coordinator` in `XenAPI-Extensions/Pool.cs`

Variables and methods XenAPI-Extensions were mistakenly skipped

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Replace negative language in `XenApi-Extensions` with `coordinator/interface`

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Replace negative language in `XenApi-Extensions` with `supporter/member`

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Replace remaining negative language in `XenServerHealthCheckBugTool.cs`

This is only used to format the string

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Change line-endings to CRLF in `Page_CloudConfigParamters.cs`

Done in order to fix merge conflict into master

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Amend misc negative language renaming typos

`XenServerHealthCheckBugTool` and `XenServerHealthCheckService`

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>
2021-08-31 11:31:16 +01:00

717 lines
29 KiB
C#

/* Copyright (c) Citrix Systems, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using XenAdmin.Actions;
using XenAdmin.Actions.OvfActions;
using XenAdmin.Controls;
using XenAdmin.Core;
using XenAdmin.Mappings;
using XenAdmin.Network;
using XenAdmin.Wizards.GenericPages;
using XenAPI;
using System.Linq;
using XenAdmin.Actions.VMActions;
using XenAdmin.Commands;
using XenOvf;
using XenOvf.Definitions;
using XenOvf.Utilities;
using Tuple = System.Collections.Generic.KeyValuePair<string, string>;
namespace XenAdmin.Wizards.ImportWizard
{
internal partial class ImportWizard : XenWizardBase
{
#region Private fields
private readonly ImportSelectStoragePage m_pageStorage;
private readonly ImportSelectNetworkPage m_pageNetwork;
private readonly ImportSelectHostPage m_pageHost;
private readonly ImportSecurityPage m_pageSecurity;
private readonly ImportEulaPage m_pageEula;
private readonly ImportOptionsPage m_pageOptions;
private readonly ImportFinishPage m_pageFinish;
private readonly RBACWarningPage m_pageRbac;
private readonly ImageVMConfigPage m_pageVMconfig;
private readonly ImportSourcePage m_pageImportSource;
private readonly StoragePickerPage m_pageXvaStorage;
private readonly NetworkPickerPage m_pageXvaNetwork;
private readonly GlobalSelectHost m_pageXvaHost;
private readonly LunPerVdiImportPage lunPerVdiMappingPage;
private readonly ImportBootOptionPage m_pageBootOptions;
private IXenObject m_selectedObject;
private Dictionary<string, VmMapping> m_vmMappings = new Dictionary<string, VmMapping>();
/// <summary>
/// Make this nullable and initialize with null so the pages are added correctly to the wizard progress the first time
/// </summary>
private ImportType? m_typeOfImport;
private bool m_ignoreAffinitySet;
private EnvelopeType m_envelopeFromVhd;
private IXenConnection TargetConnection { get; set; }
#endregion
public ImportWizard(IXenConnection con, IXenObject xenObject, string filename, bool ovfModeOnly)
: base(con)
{
InitializeComponent();
m_pageStorage = new ImportSelectStoragePage();
m_pageNetwork = new ImportSelectNetworkPage();
m_pageHost = new ImportSelectHostPage();
m_pageSecurity = new ImportSecurityPage();
m_pageEula = new ImportEulaPage();
m_pageOptions = new ImportOptionsPage();
m_pageFinish = new ImportFinishPage();
m_pageRbac = new RBACWarningPage();
m_pageVMconfig = new ImageVMConfigPage();
m_pageImportSource = new ImportSourcePage();
m_pageXvaStorage = new StoragePickerPage();
m_pageXvaNetwork = new NetworkPickerPage();
m_pageXvaHost = new GlobalSelectHost();
lunPerVdiMappingPage = new LunPerVdiImportPage { Connection = con };
m_pageBootOptions = new ImportBootOptionPage();
m_selectedObject = xenObject;
m_pageFinish.SummaryRetriever = GetSummary;
m_pageXvaStorage.ImportVmCompleted += m_pageXvaStorage_ImportVmCompleted;
if (!string.IsNullOrEmpty(filename))
m_pageImportSource.SetFileName(filename);
m_pageImportSource.OvfModeOnly = ovfModeOnly;
AddPages(m_pageImportSource, m_pageHost, m_pageStorage, m_pageNetwork, m_pageFinish);
m_pageHost.ConnectionSelectionChanged += pageHost_ConnectionSelectionChanged;
m_pageXvaHost.ConnectionSelectionChanged += pageHost_ConnectionSelectionChanged;
ShowXenAppXenDesktopWarning(con);
}
#region Override (XenWizardBase) Methods
protected override void FinishWizard()
{
switch (m_typeOfImport)
{
case ImportType.Xva:
if (m_pageXvaStorage.ImportXvaAction != null)
m_pageXvaStorage.ImportXvaAction.EndWizard(m_pageFinish.StartVmsAutomatically, m_pageXvaNetwork.VIFs);
break;
case ImportType.Ovf:
new ImportApplianceAction(TargetConnection,
m_pageImportSource.SelectedOvfPackage,
m_vmMappings,
m_pageSecurity.VerifyManifest,
m_pageSecurity.VerifySignature,
m_pageSecurity.Password,
m_pageOptions.RunFixups,
m_pageOptions.SelectedIsoSR,
m_pageFinish.StartVmsAutomatically).RunAsync();
break;
case ImportType.Vhd:
new ImportImageAction(TargetConnection,
m_envelopeFromVhd,
Path.GetDirectoryName(m_pageImportSource.FilePath),
m_vmMappings,
m_pageOptions.RunFixups,
m_pageOptions.SelectedIsoSR,
m_pageFinish.StartVmsAutomatically,
VMOperationCommand.WarningDialogHAInvalidConfig,
VMOperationCommand.StartDiagnosisForm).RunAsync();
break;
}
base.FinishWizard();
}
protected override void OnCancel(ref bool cancel)
{
base.OnCancel(ref cancel);
if (cancel)
return;
if (m_pageXvaStorage.ImportXvaAction != null)
{
m_pageXvaStorage.ImportXvaAction.EndWizard(false, null);
m_pageXvaStorage.ImportXvaAction.Cancel();
}
}
protected override void UpdateWizardContent(XenTabPage page)
{
Type type = page.GetType();
if (type == typeof(ImportSourcePage))
{
#region ImportSourcePage
var oldTypeOfImport = m_typeOfImport;//store previous type
m_typeOfImport = m_pageImportSource.TypeOfImport;
var appliancePages = new XenTabPage[] {m_pageEula, m_pageHost, m_pageStorage, m_pageNetwork, m_pageSecurity, m_pageOptions};
var imagePages = new XenTabPage[] { m_pageVMconfig, m_pageHost, m_pageStorage, m_pageNetwork, m_pageOptions };
var xvaPages = new XenTabPage[] { m_pageXvaHost, m_pageXvaStorage, m_pageXvaNetwork };
switch (m_typeOfImport)
{
case ImportType.Ovf:
if (oldTypeOfImport != ImportType.Ovf)
{
Text = Messages.WIZARD_TEXT_IMPORT_OVF;
pictureBoxWizard.Image = Images.StaticImages._000_ImportVirtualAppliance_h32bit_32;
RemovePages(imagePages);
RemovePage(m_pageBootOptions);
RemovePages(xvaPages);
AddAfterPage(m_pageImportSource, appliancePages);
}
m_pageEula.SelectedOvfEnvelope = m_pageImportSource.SelectedOvfPackage.OvfEnvelope;
m_pageSecurity.SelectedOvfPackage = m_pageImportSource.SelectedOvfPackage;
CheckDisabledPages(m_pageEula, m_pageSecurity); //decide whether to disable these progress steps
ResetVmMappings(m_pageImportSource.SelectedOvfPackage.OvfEnvelope);
m_pageHost.SelectedOvfEnvelope = m_pageImportSource.SelectedOvfPackage.OvfEnvelope;
m_pageHost.SetDefaultTarget(m_pageHost.ChosenItem ?? m_selectedObject);
m_pageHost.VmMappings = m_vmMappings;
m_pageStorage.SelectedOvfEnvelope = m_pageImportSource.SelectedOvfPackage.OvfEnvelope;
lunPerVdiMappingPage.SelectedOvfEnvelope = m_pageImportSource.SelectedOvfPackage.OvfEnvelope;
m_pageNetwork.SelectedOvfEnvelope = m_pageImportSource.SelectedOvfPackage.OvfEnvelope;
NotifyNextPagesOfChange(m_pageEula, m_pageHost, m_pageStorage, m_pageNetwork, m_pageSecurity, m_pageOptions);
break;
case ImportType.Vhd:
if (oldTypeOfImport != ImportType.Vhd)
{
Text = Messages.WIZARD_TEXT_IMPORT_VHD;
pictureBoxWizard.Image = Images.StaticImages._000_ImportVM_h32bit_32;
RemovePages(appliancePages);
RemovePages(xvaPages);
AddAfterPage(m_pageImportSource, imagePages);
}
m_pageVMconfig.IsWim = m_pageImportSource.IsWIM;
m_pageHost.SetDefaultTarget(m_pageHost.ChosenItem ?? m_selectedObject);
m_pageHost.SelectedOvfEnvelope = null;
m_pageHost.VmMappings = m_vmMappings;
NotifyNextPagesOfChange(m_pageVMconfig, m_pageHost, m_pageStorage, m_pageNetwork, m_pageOptions);
break;
case ImportType.Xva:
if (oldTypeOfImport != ImportType.Xva)
{
Text = Messages.WIZARD_TEXT_IMPORT_XVA;
pictureBoxWizard.Image = Images.StaticImages._000_ImportVM_h32bit_32;
RemovePages(imagePages);
RemovePage(m_pageBootOptions);
RemovePages(appliancePages);
AddAfterPage(m_pageImportSource, xvaPages);
}
m_pageXvaHost.SetDefaultTarget(m_selectedObject);
m_pageXvaStorage.FilePath = m_pageImportSource.FilePath;
break;
}
#endregion
}
else if (type == typeof(ImageVMConfigPage))
{
//then use it to create an ovf for the import
m_envelopeFromVhd = OVF.CreateOvfEnvelope(m_pageVMconfig.VmName,
m_pageVMconfig.CpuCount, m_pageVMconfig.Memory,
m_pageBootOptions.BootParams, m_pageBootOptions.PlatformSettings,
m_pageImportSource.DiskCapacity, m_pageImportSource.IsWIM, m_pageVMconfig.AdditionalSpace,
m_pageImportSource.FilePath, m_pageImportSource.ImageLength, BrandManager.ProductBrand);
m_pageStorage.SelectedOvfEnvelope = m_envelopeFromVhd;
lunPerVdiMappingPage.SelectedOvfEnvelope = m_envelopeFromVhd;
m_pageNetwork.SelectedOvfEnvelope = m_envelopeFromVhd;
ResetVmMappings(m_envelopeFromVhd);
NotifyNextPagesOfChange(m_pageHost, m_pageStorage, m_pageNetwork);
}
else if (type == typeof(ImportSelectHostPage))
{
TargetConnection = m_pageHost.ChosenItem == null ? null : m_pageHost.ChosenItem.Connection;
RemovePage(m_pageRbac);
ConfigureRbacPage(TargetConnection);
m_vmMappings = m_pageHost.VmMappings;
m_pageStorage.VmMappings = m_vmMappings;
m_pageStorage.Connection = TargetConnection;
m_pageNetwork.Connection = TargetConnection;
m_pageOptions.Connection = TargetConnection;
RemovePage(m_pageBootOptions);
if (m_typeOfImport == ImportType.Vhd && BootModesControl.ShowBootModeOptions(TargetConnection))
{
AddAfterPage(m_pageNetwork, m_pageBootOptions);
m_pageBootOptions.Connection = TargetConnection;
}
m_pageBootOptions.Connection = TargetConnection;
NotifyNextPagesOfChange(m_pageStorage, m_pageNetwork, m_pageOptions);
}
else if (type == typeof(ImportSelectStoragePage))
{
RemovePage(lunPerVdiMappingPage);
lunPerVdiMappingPage.ClearPickerData();
m_vmMappings = m_pageStorage.VmMappings;
m_pageNetwork.VmMappings = m_vmMappings;
lunPerVdiMappingPage.VmMappings = m_vmMappings;
if (lunPerVdiMappingPage.IsAnyPickerDataMappable
&& lunPerVdiMappingPage.MapLunsToVdisRequired
&& m_typeOfImport == ImportType.Ovf)
AddAfterPage(m_pageStorage, lunPerVdiMappingPage);
}
else if (type == typeof(LunPerVdiImportPage))
{
m_vmMappings = lunPerVdiMappingPage.VmMappings;
m_pageNetwork.VmMappings = m_vmMappings;
}
else if (type == typeof(ImportSelectNetworkPage))
{
m_vmMappings = m_pageNetwork.VmMappings;
m_pageOptions.VmMappings = m_vmMappings;
}
else if (type == typeof(GlobalSelectHost))
{
var con = m_pageXvaHost.SelectedHost == null ? m_pageXvaHost.SelectedConnection : m_pageXvaHost.SelectedHost.Connection;
RemovePage(m_pageRbac);
ConfigureRbacPage(con);
m_pageXvaStorage.SetConnection(con);
m_pageXvaStorage.SetTargetHost(m_ignoreAffinitySet ? null : m_pageXvaHost.SelectedHost);
m_pageXvaNetwork.SetConnection(con);
m_pageXvaNetwork.SetAffinity(m_pageXvaHost.SelectedHost);
NotifyNextPagesOfChange(m_pageXvaStorage, m_pageXvaNetwork);
}
else if (type == typeof(StoragePickerPage))
{
m_pageFinish.ShowStartVmsGroupBox = m_pageXvaStorage.ImportedVm != null && !m_pageXvaStorage.ImportedVm.is_a_template;
m_pageXvaNetwork.SetVm(m_pageXvaStorage.ImportedVm);
NotifyNextPagesOfChange(m_pageXvaNetwork);
}
if (type != typeof(ImportFinishPage))
NotifyNextPagesOfChange(m_pageFinish);
}
protected override string WizardPaneHelpID()
{
var curPageType = CurrentStepTabPage.GetType();
if (curPageType == typeof(RBACWarningPage))
{
switch (m_typeOfImport)
{
case ImportType.Ovf:
return FormatHelpId("RbacImportOvf");
case ImportType.Vhd:
return FormatHelpId("RbacImportImage");
case ImportType.Xva:
return FormatHelpId("RbacImportXva");
}
}
if (curPageType == typeof(ImportSelectHostPage))
{
switch (m_typeOfImport)
{
case ImportType.Ovf:
return FormatHelpId("SelectHostOvf");
case ImportType.Vhd:
return FormatHelpId("SelectHostImage");
}
}
if (curPageType == typeof(ImportSelectStoragePage))
{
switch (m_typeOfImport)
{
case ImportType.Ovf:
return FormatHelpId("SelectStorageOvf");
case ImportType.Vhd:
return FormatHelpId("SelectStorageImage");
}
}
if (curPageType == typeof(ImportSelectNetworkPage))
{
switch (m_typeOfImport)
{
case ImportType.Ovf:
return FormatHelpId("SelectNetworkOvf");
case ImportType.Vhd:
return FormatHelpId("SelectNetworkImage");
}
}
if (curPageType == typeof(ImportOptionsPage))
{
switch (m_typeOfImport)
{
case ImportType.Ovf:
return FormatHelpId("ImportOptionsOvf");
case ImportType.Vhd:
return FormatHelpId("ImportOptionsImage");
}
}
if (curPageType == typeof(ImportFinishPage))
{
switch (m_typeOfImport)
{
case ImportType.Ovf:
return FormatHelpId("ImportFinishOvf");
case ImportType.Vhd:
return FormatHelpId("ImportFinishImage");
case ImportType.Xva:
return FormatHelpId("ImportFinishXva");
}
}
return base.WizardPaneHelpID();
}
#endregion
#region Private methods
private void ConfigureRbacPage(IXenConnection selectedConnection)
{
if (selectedConnection == null || selectedConnection.Session == null || selectedConnection.Session.IsLocalSuperuser ||
Helpers.GetCoordinator(selectedConnection).external_auth_type == Auth.AUTH_TYPE_NONE)
return;
m_pageRbac.ClearPermissionChecks();
m_ignoreAffinitySet = false;
switch (m_typeOfImport)
{
case ImportType.Ovf:
case ImportType.Vhd:
{
var check = m_typeOfImport == ImportType.Ovf
? new RBACWarningPage.WizardPermissionCheck(Messages.RBAC_WARNING_IMPORT_WIZARD_APPLIANCE) {Blocking = true}
: new RBACWarningPage.WizardPermissionCheck(Messages.RBAC_WARNING_IMPORT_WIZARD_IMAGE) {Blocking = true};
check.AddApiCheckRange(ApplianceAction.StaticRBACDependencies);
m_pageRbac.AddPermissionChecks(selectedConnection, check);
AddAfterPage(m_pageHost, m_pageRbac);
}
break;
case ImportType.Xva:
{
//Check to see if they can import VMs at all
var importCheck = new RBACWarningPage.WizardPermissionCheck(Messages.RBAC_WARNING_IMPORT_WIZARD_XVA) {Blocking = true};
importCheck.ApiCallsToCheck.AddRange(ImportVmAction.ConstantRBACRequirements);
importCheck.ApiCallsToCheck.Add("sr.scan");//CA-337323
//Check to see if they can set the VM's affinity
var affinityCheck = new RBACWarningPage.WizardPermissionCheck(Messages.RBAC_WARNING_IMPORT_WIZARD_AFFINITY);
affinityCheck.ApiCallsToCheck.Add("vm.set_affinity");
affinityCheck.WarningAction = delegate
{
//We cannot allow them to set the affinity, so we are only going
//to offer them the choice of connection, not specific host
m_ignoreAffinitySet = true;
};
m_pageRbac.AddPermissionChecks(selectedConnection, importCheck, affinityCheck);
AddAfterPage(m_pageXvaHost, m_pageRbac);
}
break;
}
//set page Connection after the page has been added to the wizard
//(because the Connection is reset when the page is added
m_pageRbac.Connection = selectedConnection;
}
private void CheckDisabledPages(params XenTabPage[] pages)
{
foreach (var p in pages)
p.CheckPageDisabled();
}
protected override IEnumerable<Tuple> GetSummary()
{
switch (m_typeOfImport)
{
case ImportType.Xva:
return GetSummaryXva();
case ImportType.Ovf:
return GetSummaryOvf();
case ImportType.Vhd:
return GetSummaryVhd();
default:
return new List<Tuple>();
}
}
private IEnumerable<Tuple> GetSummaryXva()
{
var temp = new List<Tuple>();
temp.Add(new Tuple(Messages.FINISH_PAGE_VMNAME, m_pageXvaStorage.ImportedVm.Name()));
temp.Add(new Tuple(Messages.FINISH_PAGE_TARGET, m_pageXvaHost.SelectedHost == null ? m_pageXvaHost.SelectedConnection.Name : m_pageXvaHost.SelectedHost.Name()));
temp.Add(new Tuple(Messages.FINISH_PAGE_STORAGE, m_pageXvaStorage.SR.Name()));
var con = m_pageXvaHost.SelectedHost == null ? m_pageXvaHost.SelectedConnection : m_pageXvaHost.SelectedHost.Connection;
bool first = true;
foreach (var vif in m_pageXvaNetwork.VIFs)
{
var netref = new XenRef<XenAPI.Network>(vif.network);
var network = con.Resolve(netref);
// CA-218956 - Expose HIMN when showing hidden objects
if (network == null || (network.IsGuestInstallerNetwork() && !XenAdmin.Properties.Settings.Default.ShowHiddenVMs))
continue;
temp.Add(new Tuple(first ? Messages.FINISH_PAGE_NETWORK : "", network.Name()));
first = false;
}
return temp;
}
private IEnumerable<Tuple> GetSummaryOvf()
{
var temp = new List<Tuple>();
var appName = m_pageImportSource.SelectedOvfPackage.Name;
temp.Add(new Tuple(Messages.FINISH_PAGE_REVIEW_APPLIANCE, appName));
temp.Add(new Tuple(Messages.FINISH_PAGE_VERIFY_MANIFEST, m_pageSecurity.VerifyManifest.ToYesNoStringI18n()));
temp.Add(new Tuple(Messages.FINISH_PAGE_VERIFY_SIGNATURE, m_pageSecurity.VerifySignature.ToYesNoStringI18n()));
temp.Add(new Tuple(Messages.FINISH_PAGE_RUN_FIXUPS, m_pageOptions.RunFixups.ToYesNoStringI18n()));
if (m_pageOptions.RunFixups)
temp.Add(new Tuple(Messages.FINISH_PAGE_ISOSR, m_pageOptions.SelectedIsoSR.Name()));
temp.AddRange(GetVmMappingsSummary());
return temp;
}
private IEnumerable<Tuple> GetSummaryVhd()
{
var temp = new List<Tuple>();
temp.Add(new Tuple(Messages.FINISH_PAGE_IMAGEPATH, m_pageImportSource.FilePath));
temp.Add(new Tuple(Messages.FINISH_PAGE_VMNAME, m_pageVMconfig.VmName));
temp.Add(new Tuple(Messages.FINISH_PAGE_CPUCOUNT, m_pageVMconfig.CpuCount.ToString()));
temp.Add(new Tuple(Messages.FINISH_PAGE_MEMORY, string.Format(Messages.VAL_MB, m_pageVMconfig.Memory)));
if (Helpers.NaplesOrGreater(TargetConnection))
temp.Add(new Tuple(Messages.BOOT_MODE, m_pageBootOptions.SelectedBootMode.StringOf()));
if (m_pageImportSource.IsWIM)
temp.Add(new Tuple(Messages.FINISH_PAGE_ADDSPACE, Util.DiskSizeString(m_pageVMconfig.AdditionalSpace)));
temp.Add(new Tuple(Messages.FINISH_PAGE_RUN_FIXUPS, m_pageOptions.RunFixups.ToYesNoStringI18n()));
if (m_pageOptions.RunFixups)
temp.Add(new Tuple(Messages.FINISH_PAGE_ISOSR, m_pageOptions.SelectedIsoSR.Name()));
temp.AddRange(GetVmMappingsSummary());
return temp;
}
private IEnumerable<Tuple> GetVmMappingsSummary()
{
var temp = new List<Tuple>();
foreach (var mapping in m_vmMappings.Values)
{
var targetLbl = m_vmMappings.Count == 1 ? Messages.FINISH_PAGE_TARGET : string.Format(Messages.FINISH_PAGE_TARGET_FOR_VM, mapping.VmNameLabel);
var storageLbl = m_vmMappings.Count == 1 ? Messages.FINISH_PAGE_STORAGE : string.Format(Messages.FINISH_PAGE_STORAGE_FOR_VM, mapping.VmNameLabel);
var networkLbl = m_vmMappings.Count == 1 ? Messages.FINISH_PAGE_NETWORK : string.Format(Messages.FINISH_PAGE_NETWORK_FOR_VM, mapping.VmNameLabel);
temp.Add(new Tuple(targetLbl, mapping.TargetName));
bool first = true;
foreach (var sr in mapping.Storage)
{
temp.Add(new Tuple(first ? storageLbl : "", sr.Value.Name()));
first = false;
}
first = true;
foreach (var net in mapping.Networks)
{
temp.Add(new Tuple(first ? networkLbl : "", net.Value.Name()));
first = false;
}
}
return temp;
}
private void ResetVmMappings(EnvelopeType ovfEnvelope)
{
string[] sysIds = OVF.FindSystemIds(ovfEnvelope);
m_vmMappings.Clear();
foreach (string sysId in sysIds)
{
var vmMap = new VmMapping
{
VmNameLabel = (m_typeOfImport == ImportType.Ovf)
? FindVMName(ovfEnvelope, sysId)
: m_pageVMconfig.VmName //it should only iterate once
};
m_vmMappings.Add(sysId, vmMap);
}
}
private bool IsGUID(string expression)
{
if (expression != null)
{
Regex guidRegEx = new Regex(@"^(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$");
return guidRegEx.IsMatch(expression);
}
return false;
}
// Find a name to use of a VM within an envelope that could have come from any hypervisor.
// TODO: Consider refactoring this method because it is very similar to OVF.FindSystemName().
private string FindVMName(EnvelopeType ovfEnv, string systemid)
{
VirtualSystem_Type vSystem = OVF.FindVirtualSystemById(ovfEnv, systemid);
// Use the given name if present and valid.
// The given name is Envelope.VirtualSystem.Name specified in the OVF Specification 1.1 clause 7.2.
// XenServer sets the name property.
// vSphere 4.1 and Virtual Box 4.0.6 do not.
if ((Tools.ValidateProperty("Name", vSystem)) && !String.IsNullOrEmpty(vSystem.Name[0].Value))
return vSystem.Name[0].Value;
// The VM wasn't given a name.
// Build a list of choices from various properties.
var choices = new List<string>();
// VirtualSystem.id is next preference because vSphere and Virtual Box typically set this property to the VM name.
if (!string.IsNullOrEmpty(vSystem.id))
choices.Add(vSystem.id);
// VirtualHardwareSection_Type.VirtualSystemIdentifier is next preference because Virtual Box will also set this property to the VM name.
VirtualHardwareSection_Type[] vhsList = OVF.FindVirtualHardwareSection(ovfEnv, systemid);
foreach (VirtualHardwareSection_Type vhs in vhsList)
{
if (vhs == null || vhs.System == null)
continue;
if (Tools.ValidateProperty("VirtualSystemIdentifier", vhs.System))
choices.Add(vhs.System.VirtualSystemIdentifier.Value);
}
// Operating system description is next preference.
OperatingSystemSection_Type[] ossList = OVF.FindSections<OperatingSystemSection_Type>(vSystem.Items);
foreach (OperatingSystemSection_Type oss in ossList)
{
if (Tools.ValidateProperty("Description", oss))
choices.Add(oss.Description.Value);
}
// Envelope name is the last preference for XenServer that can could be a path in some cases.
// vSphere and Virtual Box usually don't set this property.
choices.Add(Path.GetFileNameWithoutExtension(ovfEnv.Name));
// Last preference is file name.
choices.Add(Path.GetFileNameWithoutExtension(m_pageImportSource.SelectedOvfPackage.PackageSourceFile));
// First choice is one that is not a GUID.
foreach (var choice in choices)
{
if (!String.IsNullOrEmpty(choice) && !IsGUID(choice))
return choice;
}
// Second choice is the first GUID.
foreach (var choice in choices)
{
if (!String.IsNullOrEmpty(choice))
return choice;
}
// Last resort is a new GUID.
return Guid.NewGuid().ToString();
}
#endregion
private void m_pageXvaStorage_ImportVmCompleted()
{
Program.Invoke(this, () =>
{
if (CurrentStepTabPage.GetType() == typeof(StoragePickerPage))
{
m_pageFinish.ShowStartVmsGroupBox = m_pageXvaStorage.ImportedVm != null && !m_pageXvaStorage.ImportedVm.is_a_template;
m_pageXvaNetwork.SetVm(m_pageXvaStorage.ImportedVm);
NotifyNextPagesOfChange(m_pageXvaNetwork);
NextStep();
}
});
}
private void ShowXenAppXenDesktopWarning(IXenConnection connection)
{
if (connection != null && connection.Cache.Hosts.Any(h => h.DesktopFeaturesEnabled() || h.DesktopPlusFeaturesEnabled() || h.DesktopCloudFeaturesEnabled()))
{
var format = Helpers.GetPool(connection) != null
? Messages.NEWVMWIZARD_XENAPP_XENDESKTOP_INFO_MESSAGE_POOL
: Messages.NEWVMWIZARD_XENAPP_XENDESKTOP_INFO_MESSAGE_SERVER;
ShowInformationMessage(string.Format(format, BrandManager.CompanyNameShort));
}
else
HideInformationMessage();
}
private void pageHost_ConnectionSelectionChanged(IXenConnection connection)
{
ShowXenAppXenDesktopWarning(connection);
}
#region Nested items
/// <summary>
/// Type of the object we want to import
/// </summary>
public enum ImportType
{
/// <summary>
/// Exported VM or template; filetype *.xva, *.xva.gz
/// </summary>
Xva,
/// <summary>
/// Appliance; filetypes *.ovf, *.ova, *.ova.gz
/// </summary>
Ovf,
/// <summary>
/// Virtual disk image; filetypes *.vhd, *.vmdk (CA-61385: remove ".vdi", ".wim" support for Boston)
/// </summary>
Vhd
}
#endregion
}
}