mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2024-11-23 20:36:33 +01:00
6c584bb351
* Tidy up `SelectMultipleVMDestinationPage.cs` * CA-375532 & CA-336510: Add warning when importing VMs with too many vCPUs * CA-375532 & CA-336510: Prevent users from starting appliance if a VM has too many vCPUs * Tidy up `Page_CpuMem`: use expression-bodied properties * Tidy up `Page_CpuMem`: use conventional naming scheme * Tidy up `Page_CpuMem`: use explicit modifiers * Tidy up `Page_CpuMem`: use `en-US` locale for names * Tidy up `Page_CpuMem`: use `var` when possible * Tidy up `Page_CpuMem`: rename `Vcpus` to `VCpus` * Tidy up `Page_CpuMem`: reorder elements * Tidy up `Page_CpuMem`: revert class renaming and fix `vCpus` typos * CA-375532: Prevent users from starting VM if they select too many vCPUs * Tidy up `Page_Finish`: use expression-bodied properties * Tidy up `Page_Finish`: fix typo * Tidy up `Page_CpuMem`: rename `CanStartVM` to `CanStartVm` * Remove unnecessary using directives * Anchor warning icon to the top-left corner of its parent * CA-375532 & CA-336510: Warn users when selecting more vCPUs than pCPUs in the Properties page * CP-41825: Add warning for imported VMs with > 32 vCPUs * CP-41825: Add warning for new VMs with > 32 vCPUs * CP-41825: Add warning for existing VMs when selecting > 32 vCPUs * CP-41825: Update wording used to alert users running VMs with > 32vCPUs * Remove unused local variable in `VappStartCommand.cs` * Reword some vCPUs messages * Simplify assignment of `CanStartImmediately` in `Page_Finish.cs` * Simplify assignment of `CanStartVmsAutomatically` in `ImportFinishPage.cs` * Remove useless `Count` check in `VappStartCommand` * Rename `pictureBox1` to `warningPictureBox` and change its `SizeMode` * Separate CPU and memory warnings in `Page_CpuMem` * Shorten warning messages shown in `Page_CpuMem` * Disable option to start VM when memory configuration isn't valid * Report number of vCPUs and pCPUs when showing warning in New VM wizard * Tidy up `CpuMemoryEditPage`: rename elements * Tidy up `CpuMemoryEditPage`: use explicity modifiers * Tidy up `CpuMemoryEditPage`: Rename `CPUMemoryEditPage` to `CpuMemoryEditPage` * Tidy up `CpuMemoryEditPage`: Miscellaneous renames and improvements * Tidy up `CpuMemoryEditPage`: Fix whitespace * Tidy up `CpuMemoryEditPage`: Use ReSharper code formatter * Tidy up `CpuMemoryEditPage`: Move events to own region * Tidy up `CpuMemoryEditPage`: Move `IEditPage` members to own region * Tidy up `CpuMemoryEditPage`: Order members outside of regions * Replace topology and vCPU warning labels with structured warnings * Ensure warnings ends with a dot * Allow multiple CPU warnings to show at the same time * Remove warning link for vCPUS > pCPUS Option is not achievable * Enable option to force unit used in `MemorySpinner` * Replace `NumericUpDown` with `MemorySpinner` and show warnings at bottom of control * Check destination pCPUs count when destination is not a pool * Do not disable option to start VMs after import if user selects a shared SR * Add memory warning when importing appliance with too much memory * Sort vCPUs and memory warning strings * Remove target from `ImportWizard`'s summary Target is not useful and can cause confusion as appliance VMs could start on non-target hosts * The home server is needed in the summary when importing XVA. The target server is not needed in the summary when migrating a VM. * Update warnings when the server selection changes. Corrected memory calculation. * Show all warnings for vCPUs. Moved topology warning to the bottom. Separated methods for showing memory and vCPU warnings. * Removed the memory setting from the VM Properties dialog. Split running VM info to a separate panel. * Corrections to the logic for starting the VM automatically. Also, Fixed a bit the layout of the Finish page to make better use of the available space. * Corrections as per code review. Signed-off-by: Danilo Del Busso <danilo.delbusso@cloud.com> Co-authored-by: Konstantina Chremmou <Konstantina.Chremmou@cloud.com>
329 lines
15 KiB
C#
329 lines
15 KiB
C#
/* Copyright (c) Cloud Software Group, Inc.
|
|
*
|
|
* 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.Linq;
|
|
using XenAdmin.Commands;
|
|
using XenAdmin.Controls;
|
|
using XenAdmin.Network;
|
|
using XenAdmin.Actions.VMActions;
|
|
using XenAdmin.SettingsPanels;
|
|
|
|
using XenAPI;
|
|
using System.Collections.Generic;
|
|
using XenAdmin.Wizards.GenericPages;
|
|
using XenAdmin.Core;
|
|
|
|
using XenAdmin.Actions;
|
|
using System.Windows.Forms;
|
|
|
|
namespace XenAdmin.Wizards.NewVMWizard
|
|
{
|
|
public partial class NewVMWizard : XenWizardBase
|
|
{
|
|
private readonly Page_Template page_1_Template;
|
|
private readonly Page_CopyBiosStrings page_1b_BiosLocking;
|
|
private readonly Page_Name page_2_Name;
|
|
private readonly Page_InstallationMedia page_3_InstallationMedia;
|
|
private readonly Page_HomeServer page_4_HomeServer;
|
|
private readonly Page_CpuMem page_5_CpuMem;
|
|
private readonly Page_Storage page_6_Storage;
|
|
private readonly Page_Networking page_7_Networking;
|
|
private readonly Page_Finish page_8_Finish;
|
|
private readonly RBACWarningPage page_RbacWarning;
|
|
private readonly LunPerVdiNewVMMappingPage page_6b_LunPerVdi;
|
|
private readonly GpuEditPage pageVgpu;
|
|
private readonly Page_CloudConfigParameters page_CloudConfigParameters;
|
|
|
|
private Host m_affinity;
|
|
private bool BlockAffinitySelection;
|
|
private bool gpuCapability;
|
|
|
|
public AsyncAction Action;
|
|
|
|
public NewVMWizard(IXenConnection connection, VM template, Host affinity)
|
|
: base(connection)
|
|
{
|
|
InitializeComponent();
|
|
|
|
page_1_Template = new Page_Template();
|
|
page_1b_BiosLocking = new Page_CopyBiosStrings();
|
|
page_2_Name = new Page_Name();
|
|
page_3_InstallationMedia = new Page_InstallationMedia();
|
|
page_4_HomeServer = new Page_HomeServer();
|
|
page_5_CpuMem = new Page_CpuMem();
|
|
page_6_Storage = new Page_Storage();
|
|
page_7_Networking = new Page_Networking();
|
|
page_8_Finish = new Page_Finish();
|
|
page_RbacWarning = new RBACWarningPage();
|
|
page_6b_LunPerVdi = new LunPerVdiNewVMMappingPage { Connection = xenConnection };
|
|
pageVgpu = new GpuEditPage();
|
|
page_CloudConfigParameters = new Page_CloudConfigParameters();
|
|
|
|
#region RBAC Warning Page Checks
|
|
if (Helpers.ConnectionRequiresRbac(connection))
|
|
{
|
|
var createCheck = new WizardRbacCheck(Messages.RBAC_WARNING_VM_WIZARD_BLOCK,
|
|
CreateVMAction.StaticRBACDependencies) {Blocking = true};
|
|
|
|
// Check to see if they can set memory values
|
|
var memCheck = new WizardRbacCheck(Messages.RBAC_WARNING_VM_WIZARD_MEM,
|
|
"vm.set_memory_limits")
|
|
{
|
|
WarningAction = () => page_5_CpuMem.DisableMemoryControls()
|
|
};
|
|
|
|
|
|
// Check to see if they can set the VM's affinity
|
|
var affinityCheck = new WizardRbacCheck(Messages.RBAC_WARNING_VM_WIZARD_AFFINITY, "vm.set_affinity")
|
|
{
|
|
WarningAction = () =>
|
|
{
|
|
page_4_HomeServer.DisableStep = true;
|
|
BlockAffinitySelection = true;
|
|
Program.Invoke(this, RefreshProgress);
|
|
}
|
|
};
|
|
|
|
page_RbacWarning.AddPermissionChecks(xenConnection, createCheck, affinityCheck, memCheck);
|
|
|
|
if (Helpers.GpuCapability(xenConnection))
|
|
{
|
|
var vgpuCheck = new WizardRbacCheck(Messages.RBAC_WARNING_VM_WIZARD_GPU, "vgpu.create")
|
|
{
|
|
WarningAction = () =>
|
|
{
|
|
pageVgpu.DisableStep = true;
|
|
Program.Invoke(this, RefreshProgress);
|
|
}
|
|
};
|
|
|
|
page_RbacWarning.AddPermissionChecks(xenConnection, vgpuCheck);
|
|
}
|
|
|
|
AddPage(page_RbacWarning, 0);
|
|
}
|
|
#endregion
|
|
|
|
page_8_Finish.SummaryRetriever = GetSummary;
|
|
|
|
AddPages(page_1_Template, page_2_Name, page_3_InstallationMedia, page_4_HomeServer,
|
|
page_5_CpuMem, page_6_Storage, page_7_Networking, page_8_Finish);
|
|
|
|
m_affinity = affinity;
|
|
page_1_Template.SelectedTemplate = template;
|
|
page_1b_BiosLocking.Affinity = affinity;
|
|
page_3_InstallationMedia.Affinity = affinity;
|
|
page_4_HomeServer.Affinity = affinity;
|
|
page_6_Storage.Affinity = affinity;
|
|
|
|
ShowXenAppXenDesktopWarning(connection);
|
|
}
|
|
|
|
protected override void FinishWizard()
|
|
{
|
|
Action = new CreateVMAction(xenConnection,
|
|
page_1_Template.SelectedTemplate,
|
|
page_1_Template.CopyBiosStrings
|
|
? page_1b_BiosLocking.CopyBiosStringsFrom
|
|
: null,
|
|
page_2_Name.SelectedName,
|
|
page_2_Name.SelectedDescription,
|
|
page_3_InstallationMedia.SelectedInstallMethod,
|
|
page_3_InstallationMedia.SelectedPvArgs,
|
|
page_3_InstallationMedia.SelectedCD,
|
|
page_3_InstallationMedia.SelectedUrl,
|
|
page_3_InstallationMedia.SelectedBootMode,
|
|
m_affinity,
|
|
page_5_CpuMem.SelectedVCpusMax,
|
|
page_5_CpuMem.SelectedVCpusAtStartup,
|
|
(long)page_5_CpuMem.SelectedMemoryDynamicMin,
|
|
(long)page_5_CpuMem.SelectedMemoryDynamicMax,
|
|
(long)page_5_CpuMem.SelectedMemoryStaticMax,
|
|
page_6b_LunPerVdi.MapLunsToVdisRequired
|
|
? page_6b_LunPerVdi.MappedDisks
|
|
: page_6_Storage.SelectedDisks,
|
|
page_6_Storage.FullCopySR,
|
|
page_7_Networking.SelectedVifs,
|
|
page_8_Finish.StartImmediately,
|
|
page_3_InstallationMedia.AssignVtpm,
|
|
VMOperationCommand.WarningDialogHAInvalidConfig,
|
|
VMOperationCommand.StartDiagnosisForm,
|
|
gpuCapability ? pageVgpu.VGpus : null,
|
|
pageVgpu.HasChanged,
|
|
page_5_CpuMem.SelectedCoresPerSocket,
|
|
page_CloudConfigParameters.ConfigDriveTemplateText);
|
|
|
|
Action.RunAsync();
|
|
|
|
base.FinishWizard();
|
|
}
|
|
|
|
protected override void OnKeyPress(KeyPressEventArgs e)
|
|
{
|
|
if (page_CloudConfigParameters != null && page_CloudConfigParameters.ActiveControl is TextBox && e.KeyChar == (char)Keys.Enter)
|
|
return;
|
|
|
|
base.OnKeyPress(e);
|
|
}
|
|
|
|
protected override void UpdateWizardContent(XenTabPage senderPage)
|
|
{
|
|
var prevPageType = senderPage.GetType();
|
|
|
|
if (prevPageType == typeof(Page_Template))
|
|
{
|
|
var selectedTemplate = page_1_Template.SelectedTemplate;
|
|
|
|
page_1b_BiosLocking.SelectedTemplate = selectedTemplate;
|
|
page_2_Name.SelectedTemplate = selectedTemplate;
|
|
page_3_InstallationMedia.SelectedTemplate = selectedTemplate;
|
|
page_4_HomeServer.SelectedTemplate = selectedTemplate;
|
|
page_5_CpuMem.SelectedTemplate = selectedTemplate;
|
|
pageVgpu.vm = selectedTemplate;
|
|
page_6_Storage.Template = selectedTemplate;
|
|
page_7_Networking.SelectedTemplate = selectedTemplate;
|
|
page_CloudConfigParameters.Affinity = m_affinity;
|
|
page_CloudConfigParameters.SelectedTemplate = selectedTemplate;
|
|
|
|
|
|
RemovePage(pageVgpu);
|
|
gpuCapability = Helpers.GpuCapability(xenConnection) && selectedTemplate.CanHaveGpu() && Helpers.GpusAvailable(xenConnection);
|
|
if (gpuCapability)
|
|
AddAfterPage(page_5_CpuMem, pageVgpu);
|
|
|
|
RemovePage(page_1b_BiosLocking);
|
|
|
|
if (page_1_Template.CopyBiosStrings)
|
|
{
|
|
// insert after template page
|
|
AddAfterPage(page_1_Template, page_1b_BiosLocking);
|
|
|
|
page_4_HomeServer.DisableStep = selectedTemplate.DefaultTemplate();
|
|
}
|
|
else
|
|
{
|
|
if (!BlockAffinitySelection)
|
|
page_4_HomeServer.DisableStep = false;
|
|
}
|
|
|
|
// The user cannot set their own affinity, use the one off the template
|
|
if (BlockAffinitySelection)
|
|
m_affinity = xenConnection.Resolve(selectedTemplate.affinity);
|
|
|
|
RemovePage(page_CloudConfigParameters);
|
|
if (selectedTemplate != null && Helpers.ContainerCapability(xenConnection) &&
|
|
selectedTemplate.CanHaveCloudConfigDrive())
|
|
{
|
|
AddAfterPage(page_6_Storage, page_CloudConfigParameters);
|
|
}
|
|
}
|
|
else if (prevPageType == typeof(Page_CopyBiosStrings))
|
|
{
|
|
if (page_1_Template.CopyBiosStrings && page_1_Template.SelectedTemplate.DefaultTemplate())
|
|
{
|
|
m_affinity = page_1b_BiosLocking.CopyBiosStringsFrom;
|
|
page_4_HomeServer.Affinity = m_affinity;
|
|
page_6_Storage.Affinity = m_affinity;
|
|
}
|
|
}
|
|
else if (prevPageType == typeof(Page_Name))
|
|
{
|
|
var selectedName = page_2_Name.SelectedName;
|
|
page_6_Storage.SelectedName = selectedName;
|
|
page_7_Networking.SelectedName = selectedName;
|
|
}
|
|
else if (prevPageType == typeof(Page_InstallationMedia))
|
|
{
|
|
var selectedInstallMethod = page_3_InstallationMedia.SelectedInstallMethod;
|
|
page_4_HomeServer.SelectedCD = page_3_InstallationMedia.SelectedCD;
|
|
page_4_HomeServer.SelectedInstallMethod = selectedInstallMethod;
|
|
page_6_Storage.SelectedInstallMethod = selectedInstallMethod;
|
|
}
|
|
else if (prevPageType == typeof(Page_HomeServer))
|
|
{
|
|
if (!page_4_HomeServer.DisableStep)
|
|
{
|
|
m_affinity = page_4_HomeServer.Affinity;
|
|
page_6_Storage.Affinity = m_affinity;
|
|
page_CloudConfigParameters.Affinity = m_affinity;
|
|
}
|
|
}
|
|
else if (prevPageType == typeof(Page_Storage))
|
|
{
|
|
RemovePage(page_6b_LunPerVdi);
|
|
List<SR> srs = page_6_Storage.SelectedDisks.ConvertAll(d => xenConnection.Resolve(d.Disk.SR));
|
|
if (srs.Any(sr => sr.HBALunPerVDI()))
|
|
{
|
|
page_6b_LunPerVdi.DisksToMap = page_6_Storage.SelectedDisks;
|
|
AddAfterPage(page_6_Storage, page_6b_LunPerVdi);
|
|
}
|
|
}
|
|
else if (prevPageType == typeof(Page_CpuMem))
|
|
{
|
|
page_8_Finish.CanStartImmediately = CanStartVm();
|
|
}
|
|
}
|
|
|
|
protected override string WizardPaneHelpID()
|
|
{
|
|
return CurrentStepTabPage is RBACWarningPage ? FormatHelpId("Rbac") : base.WizardPaneHelpID();
|
|
}
|
|
|
|
private bool CanStartVm()
|
|
{
|
|
var homeHost = page_6_Storage.FullCopySR?.Home();
|
|
|
|
if (homeHost != null)
|
|
{
|
|
if (homeHost.CpuCount() < page_5_CpuMem.SelectedVCpusMax)
|
|
return false;
|
|
|
|
if (homeHost.memory_available_calc() < page_5_CpuMem.SelectedMemoryDynamicMin)
|
|
return false;
|
|
}
|
|
|
|
return page_5_CpuMem.CanStartVm;
|
|
}
|
|
|
|
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.CompanyNameLegacy));
|
|
}
|
|
else
|
|
HideInformationMessage();
|
|
}
|
|
}
|
|
}
|