Merge pull request #2842 from danilo-delbusso/master

CA-350411: Add conditional page control refresh in Import Wizard
This commit is contained in:
Konstantina Chremmou 2021-12-02 21:01:00 +00:00 committed by GitHub
commit 2af5758424
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 579 additions and 464 deletions

View File

@ -49,14 +49,14 @@ namespace XenAdmin.Commands
: base(mainWindow, pool)
{ }
public override string MenuText { get { return Messages.HOST_MENU_IMPORT_VM_TEXT; } }
public override string ContextMenuText{get{return Messages.HOST_MENU_IMPORT_VM_TEXT;}}
public override string MenuText => Messages.HOST_MENU_IMPORT_VM_TEXT;
public override string ContextMenuText => Messages.HOST_MENU_IMPORT_VM_TEXT;
protected override void RunCore(SelectedItemCollection selection)
{
var con = selection.GetConnectionOfFirstItem();
MainWindowCommandInterface.ShowPerConnectionWizard(con, new ImportWizard(con, selection.FirstAsXenObject, null, false));
MainWindowCommandInterface.ShowPerConnectionWizard(con, new ImportWizard(con, selection.FirstAsXenObject, null));
}
}
}

View File

@ -2706,7 +2706,7 @@ namespace XenAdmin
{
HelpersGUI.BringFormToFront(this);
Host hostAncestor = SelectionManager.Selection.Count == 1 ? SelectionManager.Selection[0].HostAncestor : null;
new ImportWizard(SelectionManager.Selection.GetConnectionOfFirstItem(), hostAncestor, param, false).Show();
new ImportWizard(SelectionManager.Selection.GetConnectionOfFirstItem(), hostAncestor, param).Show();
}
#region XenSearch

View File

@ -55,17 +55,17 @@ namespace XenAdmin.Wizards.ImportWizard
/// <summary>
/// Gets the page's title (headline)
/// </summary>
public override string PageTitle { get { return Messages.IMAGE_DEFINITION_PAGE_TITLE; } }
public override string PageTitle => Messages.IMAGE_DEFINITION_PAGE_TITLE;
/// <summary>
/// Gets the page's label in the (left hand side) wizard progress panel
/// </summary>
public override string Text { get { return Messages.IMAGE_DEFINITION_PAGE_TEXT; } }
public override string Text => Messages.IMAGE_DEFINITION_PAGE_TEXT;
/// <summary>
/// Gets the value by which the help files section for this page is identified
/// </summary>
public override string HelpID { get { return "VMConfig"; } }
public override string HelpID => "VMConfig";
protected override bool ImplementsIsDirty()
{
@ -97,16 +97,16 @@ namespace XenAdmin.Wizards.ImportWizard
#region Accessors
public bool IsWim { private get; set; }
public bool IsWim { internal get; set; }
public string VmName { get { return m_textBoxVMName.Text; } }
public string VmName => m_textBoxVMName.Text;
public ulong CpuCount { get { return (ulong)m_upDownCpuCount.Value; } }
public ulong CpuCount => (ulong)m_upDownCpuCount.Value;
public ulong Memory { get { return (ulong)m_upDownMemory.Value; } }
public ulong Memory => (ulong)m_upDownMemory.Value;
public ulong AdditionalSpace => m_groupBoxAddSpace.Visible && m_groupBoxAddSpace.Enabled ? (ulong)m_upDownAddSpace.Value * GB : 0;
public ulong AdditionalSpace { get { return m_groupBoxAddSpace.Enabled ? (ulong)m_upDownAddSpace.Value * GB : 0; } }
#endregion
#region Private Methods

File diff suppressed because it is too large Load Diff

View File

@ -49,9 +49,6 @@ namespace XenAdmin.Wizards.ImportWizard
#region Private fields
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private IXenConnection m_selectedConnection;
private Host m_selectedAffinity;
private VM m_vm;
private bool m_buttonNextEnabled;
#endregion
@ -108,6 +105,15 @@ namespace XenAdmin.Wizards.ImportWizard
#region Accessors
/// <summary>
/// Should be set before the Affinity is set.
/// </summary>
internal IXenConnection SelectedConnection { get; set; }
internal Host SelectedAffinity { get; set; }
internal VM VM { get; set; }
public List<VIF> VIFs
{
get
@ -136,24 +142,6 @@ namespace XenAdmin.Wizards.ImportWizard
#endregion
public void SetAffinity(Host host)
{
m_selectedAffinity = host;
}
public void SetVm(VM vm)
{
m_vm = vm;
}
/// <summary>
/// Should be called before the Affinity is set.
/// </summary>
public void SetConnection(IXenConnection con)
{
m_selectedConnection = con;
}
#region Private methods
private void UpdateControlsEnabledState(bool enabled)
@ -167,7 +155,7 @@ namespace XenAdmin.Wizards.ImportWizard
{
NetworkNetworkColumn.Items.Clear();
var networks = m_selectedConnection.Cache.Networks.Where(ShowNetwork);
var networks = SelectedConnection.Cache.Networks.Where(ShowNetwork);
foreach (XenAPI.Network network in networks)
{
@ -186,18 +174,18 @@ namespace XenAdmin.Wizards.ImportWizard
m_networkGridView.SuspendLayout();
m_networkGridView.Rows.Clear();
if (m_vm.is_a_template && m_vm.VIFs.Count < 1)
if (VM.is_a_template && VM.VIFs.Count < 1)
{
// We need to automatically generate VIFs for Networks marked AutoPlug=true
var networks = m_selectedConnection.Cache.Networks;
var networks = SelectedConnection.Cache.Networks;
foreach (XenAPI.Network network in networks)
{
if (m_networkGridView.Rows.Count < m_vm.MaxVIFsAllowed() && ShowNetwork(network) && network.GetAutoPlug())
if (m_networkGridView.Rows.Count < VM.MaxVIFsAllowed() && ShowNetwork(network) && network.GetAutoPlug())
{
AddVIFRow(new VIF
{
Connection = m_selectedConnection,
Connection = SelectedConnection,
device = m_networkGridView.Rows.Count.ToString(),
network = new XenRef<XenAPI.Network>(network.opaque_ref),
MAC = Messages.MAC_AUTOGENERATE
@ -205,16 +193,16 @@ namespace XenAdmin.Wizards.ImportWizard
}
}
}
else if (m_vm.is_a_template)
else if (VM.is_a_template)
{
// We need to create off the _vmTemplate
var vifs = m_selectedConnection.ResolveAll(m_vm.VIFs);
var vifs = SelectedConnection.ResolveAll(VM.VIFs);
foreach (VIF vif in vifs)
{
AddVIFRow(new VIF
{
Connection = m_selectedConnection,
Connection = SelectedConnection,
device = vif.device,
network = vif.network,
MAC = Messages.MAC_AUTOGENERATE
@ -224,7 +212,7 @@ namespace XenAdmin.Wizards.ImportWizard
else
{
//We need to recreate off vm
var vifs = m_selectedConnection.ResolveAll(m_vm.VIFs);
var vifs = SelectedConnection.ResolveAll(VM.VIFs);
foreach (VIF vif in vifs)
AddVIFRow(vif);
}
@ -240,7 +228,7 @@ namespace XenAdmin.Wizards.ImportWizard
private XenAPI.Network GetDefaultNetwork()
{
foreach (XenAPI.Network network in m_selectedConnection.Cache.Networks)
foreach (XenAPI.Network network in SelectedConnection.Cache.Networks)
if (ShowNetwork(network))
return network;
@ -261,13 +249,13 @@ namespace XenAdmin.Wizards.ImportWizard
if (network.IsMember())
return false;
if (m_selectedAffinity != null && !m_selectedAffinity.CanSeeNetwork(network))
if (SelectedAffinity != null && !SelectedAffinity.CanSeeNetwork(network))
return false;
if (m_selectedAffinity == null && !network.AllHostsCanSeeNetwork())
if (SelectedAffinity == null && !network.AllHostsCanSeeNetwork())
return false;
if (network.IsSriov() && !m_vm.HasSriovRecommendation())
if (network.IsSriov() && !VM.HasSriovRecommendation())
return false;
return true;
@ -276,7 +264,7 @@ namespace XenAdmin.Wizards.ImportWizard
private void AddVIFRow(VIF vif)
{
var row = new VifRow(vif);
XenAPI.Network network = m_selectedConnection.Resolve(vif.network);
XenAPI.Network network = SelectedConnection.Resolve(vif.network);
bool isGuestInstallerNetwork = network != null && network.IsGuestInstallerNetwork();
ToStringWrapper<XenAPI.Network> comboBoxEntry = FindComboBoxEntryForNetwork(network);
@ -344,7 +332,7 @@ namespace XenAdmin.Wizards.ImportWizard
private void m_buttonAddNetwork_Click(object sender, EventArgs e)
{
if (m_networkGridView.Rows.Count >= m_vm.MaxVIFsAllowed())
if (m_networkGridView.Rows.Count >= VM.MaxVIFsAllowed())
{
using (var dlg = new ErrorDialog(FriendlyErrorNames.VIFS_MAX_ALLOWED)
{WindowTitle = FriendlyErrorNames.VIFS_MAX_ALLOWED_TITLE})
@ -354,7 +342,7 @@ namespace XenAdmin.Wizards.ImportWizard
return;
}
VIF vif = new VIF {Connection = m_selectedConnection};
VIF vif = new VIF {Connection = SelectedConnection};
int i = 0;
while (true)

View File

@ -45,8 +45,6 @@ namespace XenAdmin.Wizards.ImportWizard
public partial class StoragePickerPage : XenTabPage
{
#region Private fields
private Host m_targetHost;
private IXenConnection m_targetConnection;
private volatile Task m_importTask;
private bool m_alreadyFoundVM;
private ActionProgressDialog m_actionDialog;
@ -98,8 +96,8 @@ namespace XenAdmin.Wizards.ImportWizard
SetButtonNextEnabled(false);
m_buttonPreviousEnabled = false;
OnPageUpdated();
ImportXvaAction = new ImportVmAction(m_targetHost == null ? m_targetConnection : m_targetHost.Connection,
m_targetHost, FilePath, SR,
ImportXvaAction = new ImportVmAction(TargetHost == null ? TargetConnection : TargetHost.Connection,
TargetHost, FilePath, SR,
VMOperationCommand.WarningDialogHAInvalidConfig, VMOperationCommand.StartDiagnosisForm);
ImportXvaAction.Completed += m_importXvaAction_Completed;
@ -119,7 +117,7 @@ namespace XenAdmin.Wizards.ImportWizard
public override void PopulatePage()
{
SetButtonNextEnabled(false);
m_srPicker.PopulateAsync(SrPicker.SRPickerType.VM, m_targetConnection, m_targetHost, null, null);
m_srPicker.PopulateAsync(SrPicker.SRPickerType.VM, TargetConnection, TargetHost, null, null);
IsDirty = true;
}
@ -137,6 +135,10 @@ namespace XenAdmin.Wizards.ImportWizard
#region Accessors
internal IXenConnection TargetConnection { get; set; }
internal Host TargetHost { get; set; }
public ImportVmAction ImportXvaAction { get; private set; }
public string FilePath { private get; set; }
@ -147,19 +149,6 @@ namespace XenAdmin.Wizards.ImportWizard
#endregion
/// <summary>
/// Should be called before the Affinity is set.
/// </summary>
public void SetConnection(IXenConnection con)
{
m_targetConnection = con;
}
public void SetTargetHost(Host host)
{
m_targetHost = host;
}
#region Private methods
private void SetButtonNextEnabled(bool enabled)
@ -196,12 +185,12 @@ namespace XenAdmin.Wizards.ImportWizard
while (ImportXvaAction.RelatedTask == null)
Thread.Sleep(100);
while ((m_importTask = m_targetConnection.Resolve(ImportXvaAction.RelatedTask)) == null)
while ((m_importTask = TargetConnection.Resolve(ImportXvaAction.RelatedTask)) == null)
Thread.Sleep(100);
// We register a XenObjectsUpdated event handler where we check that the import task has the object creation phase marked as "complete";
// Once the object creation is complete, we look for the vm; When we found the vm we unregister this event handler;
m_targetConnection.XenObjectsUpdated += targetConnection_XenObjectsUpdated;
TargetConnection.XenObjectsUpdated += targetConnection_XenObjectsUpdated;
Program.Invoke(this, CheckTask);
}
@ -233,11 +222,11 @@ namespace XenAdmin.Wizards.ImportWizard
{
// Should never get here (as we unregister XenObjectsUpdated event handler after we find the vm) but just in case,
// unregister XenObjectsUpdated event handler
m_targetConnection.XenObjectsUpdated -= targetConnection_XenObjectsUpdated;
TargetConnection.XenObjectsUpdated -= targetConnection_XenObjectsUpdated;
return;
}
foreach (VM vm in m_targetConnection.Cache.VMs)
foreach (VM vm in TargetConnection.Cache.VMs)
{
if (!vm.other_config.ContainsKey(ImportVmAction.IMPORT_TASK))
continue;
@ -250,7 +239,7 @@ namespace XenAdmin.Wizards.ImportWizard
ImportedVm = vm;
// We found the VM, unregister XenObjectsUpdated event handler
m_targetConnection.XenObjectsUpdated -= targetConnection_XenObjectsUpdated;
TargetConnection.XenObjectsUpdated -= targetConnection_XenObjectsUpdated;
// And close the dialog, flick to next page.
m_actionDialog.Close();
@ -279,7 +268,7 @@ namespace XenAdmin.Wizards.ImportWizard
if (!(ImportXvaAction.Succeeded) || ImportXvaAction.Cancelled)
{
// task failed or has been cancelled, unregister XenObjectsUpdated event handler
m_targetConnection.XenObjectsUpdated -= targetConnection_XenObjectsUpdated;
TargetConnection.XenObjectsUpdated -= targetConnection_XenObjectsUpdated;
// Give the user a chance to correct any errors
m_actionDialog = null;

View File

@ -44,6 +44,11 @@ namespace XenAdmin.Mappings
}
public string VmNameLabel { get; set; }
public ulong Capacity { get; set; }
public ulong CpuCount { get; set; }
public ulong Memory { get; set; }
public string BootParams { get; set; }
public string PlatformSettings { get; set; }
/// <summary>
/// OpaqueRef of the target pool or host
@ -66,5 +71,26 @@ namespace XenAdmin.Mappings
/// Keyed on the id in the ovf file
/// </summary>
public Dictionary<string, XenAPI.Network> Networks { get; set; }
}
public override bool Equals(object obj)
{
return obj is VmMapping other &&
VmNameLabel == other.VmNameLabel &&
Capacity == other.Capacity &&
CpuCount == other.CpuCount &&
Memory == other.Memory &&
BootParams == other.BootParams &&
PlatformSettings == other.PlatformSettings &&
XenRef == other.XenRef &&
TargetName == other.TargetName &&
Storage == other.Storage &&
StorageToAttach == other.StorageToAttach &&
Networks == other.Networks;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}

View File

@ -1388,7 +1388,7 @@ namespace XenOvf
#region CREATEs
public static EnvelopeType CreateOvfEnvelope(string vmName, ulong cpuCount, ulong memory,
string bootParams, string platformSettings, ulong diskCapacity, bool isWim, ulong additionalSpace,
string bootParams, string platformSettings, ulong capacity,
string diskPath, ulong imageLength, string productBrand)
{
EnvelopeType env = CreateEnvelope(vmName);
@ -1415,10 +1415,6 @@ namespace XenOvf
AddNetwork(env, systemID, netId, string.Format(Messages.NETWORK_NAME, 0), Messages.OVF_NET_DESCRIPTION, null);
string diskId = Guid.NewGuid().ToString();
ulong capacity = diskCapacity;
if (isWim)
capacity += additionalSpace;
AddDisk(env, systemID, diskId, diskPath, true, Messages.OVF_DISK_CAPTION, Messages.OVF_CREATED, imageLength, capacity);
@ -1426,6 +1422,45 @@ namespace XenOvf
return env;
}
public static EnvelopeType UpdateBootParams(EnvelopeType env, string systemID, string bootParams)
{
return UpdateOtherSystemSettingsData(env, systemID, "HVM_boot_params", "order=dc;" + bootParams);
}
public static EnvelopeType UpdatePlatform(EnvelopeType env, string systemID, string platformSettings)
{
return UpdateOtherSystemSettingsData(env, systemID, "platform", "nx=true;acpi=true;apic=true;pae=true;stdvga=0;" + platformSettings);
}
private static EnvelopeType UpdateOtherSystemSettingsData(EnvelopeType env, string systemID, string setting, string value)
{
VirtualHardwareSection_Type[] vhsArray = FindVirtualHardwareSection(env, systemID);
VirtualHardwareSection_Type foundVhs = null;
foreach (VirtualHardwareSection_Type vhs in vhsArray)
{
if (vhs.System?.VirtualSystemType == null)
continue;
var vst = vhs.System.VirtualSystemType.Value;
if (string.IsNullOrEmpty(vst) || !vst.ToLower().StartsWith("xen") && !vst.ToLower().StartsWith("hvm"))
continue;
foundVhs = vhs;
break;
}
if (foundVhs == null)
return env;
var config = foundVhs.VirtualSystemOtherConfigurationData.FirstOrDefault(d => d.Name == setting);
if (config == null)
return env;
config.Value = new cimString(value);
return env;
}
public EnvelopeType Create(DiskInfo[] vhdExports, string pathToOvf, string ovfName)
{
return Create(vhdExports, pathToOvf, ovfName, LANGUAGE);