xenadmin/XenAdmin/SettingsPanels/CPUMemoryEditPage.cs

610 lines
24 KiB
C#
Raw Normal View History

/* 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;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using XenAdmin.Actions;
using XenAdmin.Commands;
using XenAdmin.Core;
using XenAPI;
using XenAdmin.Dialogs;
namespace XenAdmin.SettingsPanels
{
public partial class CPUMemoryEditPage : UserControl, IEditPage
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private VM vm;
bool ShowMemory = false; // If this VM has DMC, we don't show the memory controls on this page.
private bool _ValidToSave = true;
private decimal _OrigMemory;
private long _OrigVCPUs;
private long _OrigVCPUsMax;
private long _OrigVCPUsAtStartup;
private decimal _OrigVCPUWeight;
private decimal _CurrentVCPUWeight;
private bool isVcpuHotplugSupported;
private int minVCPUs;
// Please note that the comboBoxVCPUs control can represent two different VM properties, depending whether the VM supports vCPU hotplug or not:
// If vCPU hotplug is supported, comboBoxVCPUs represents the maximum number of vCPUs (VCPUs_max). And the initial number of vCPUs is represented in comboBoxInitialVCPUs (which is only visible in this case)
// If vCPU hotplug is not supported, comboBoxVCPUs represents the initial number of vCPUs (VCPUs_at_startup). In this case we will also set the VM property VCPUs_max to the same value.
// We use the _OrigVCPUs variable to store the original value that populates this combo box (VCPUs_max if hotplug is allowed, otherwise VCPUs_at_startup)
private ChangeMemorySettingsAction memoryAction;
public bool ValidToSave
{
get
{
if (!_ValidToSave)
return false;
// Also confirm whether the user wants to save memory changes.
// If not, don't close the properties dialog.
if (HasMemoryChanged)
{
long mem = Convert.ToInt64(this.nudMemory.Value * Util.BINARY_MEGA);
memoryAction = ConfirmAndCalcActions(mem);
if (memoryAction == null)
return false;
}
return true;
}
}
private ChangeMemorySettingsAction ConfirmAndCalcActions(long mem)
{
if (vm.memory_static_max / Util.BINARY_MEGA == mem / Util.BINARY_MEGA)
{
// don't want to show warning dialog just for rounding errors
mem = vm.memory_static_max;
}
else if (vm.power_state != vm_power_state.Halted)
{
var msg = vm.SupportsBallooning() && !Helpers.FeatureForbidden(vm, Host.RestrictDMC)
? Messages.CONFIRM_CHANGE_MEMORY_MAX_SINGULAR
: Messages.CONFIRM_CHANGE_MEMORY_SINGULAR;
using (var dlg = new WarningDialog(msg,
ThreeButtonDialog.ButtonYes, ThreeButtonDialog.ButtonNo))
{
if (dlg.ShowDialog(this) != DialogResult.Yes)
return null;
}
}
return new ChangeMemorySettingsAction(vm,
string.Format(Messages.ACTION_CHANGE_MEMORY_SETTINGS, vm.Name()),
vm.memory_static_min, mem, mem, mem,
VMOperationCommand.WarningDialogHAInvalidConfig, VMOperationCommand.StartDiagnosisForm, true);
}
public CPUMemoryEditPage()
{
InitializeComponent();
Text = Messages.CPU_AND_MEMORY;
transparentTrackBar1.Scroll += new EventHandler(tbPriority_Scroll);
this.nudMemory.TextChanged += new EventHandler(nudMemory_TextChanged);
this.nudMemory.LostFocus += new EventHandler(nudMemory_LostFocus);
}
public Image Image => Images.StaticImages._000_CPU_h32bit_16;
void nudMemory_LostFocus(object sender, EventArgs e)
{
ValidateNud(nudMemory, (decimal)vm.memory_static_max / Util.BINARY_MEGA);
}
private void ValidateNud(NumericUpDown nud, Decimal defaultValue)
{
if (!String.IsNullOrEmpty(nud.Text.Trim()))
return;
nud.Value = defaultValue >= nud.Minimum && defaultValue <= nud.Maximum ?
defaultValue : nud.Maximum;
nud.Text = nud.Value.ToString();
}
void nudMemory_TextChanged(object sender, EventArgs e)
{
decimal val;
if (decimal.TryParse(nudMemory.Text, out val))
{
if (val >= nudMemory.Minimum && val <= nudMemory.Maximum)
nudMemory_ValueChanged(null, null);
else if (val > nudMemory.Maximum)
ShowMemError(true, false);
else
ShowMemError(false, false);
}
if (this.nudMemory.Text == "")
{
_ValidToSave = false;
}
else
{
_ValidToSave = true;
}
}
private void tbPriority_Scroll(object sender, EventArgs e)
{
_CurrentVCPUWeight = Convert.ToDecimal(Math.Pow(4.0d, Convert.ToDouble(transparentTrackBar1.Value)));
if (transparentTrackBar1.Value == transparentTrackBar1.Max)
_CurrentVCPUWeight--;
}
/// <summary>
/// Must be a VM.
/// </summary>
public void SetXenObjects(IXenObject orig, IXenObject clone)
{
vm = (VM)clone;
2015-10-26 17:01:55 +01:00
ShowMemory = Helpers.FeatureForbidden(vm, Host.RestrictDMC);
Repopulate();
}
public void Repopulate()
{
VM vm = this.vm;
Text = ShowMemory ? Messages.CPU_AND_MEMORY : Messages.CPU;
if (!ShowMemory)
lblMemory.Visible = panel2.Visible = MemWarningLabel.Visible = false;
else if (vm.power_state != vm_power_state.Halted && vm.power_state != vm_power_state.Running)
{
panel2.Enabled = false;
MemWarningLabel.Text = Messages.MEM_NOT_WHEN_SUSPENDED;
MemWarningLabel.ForeColor = SystemColors.ControlText;
MemWarningLabel.Visible = true;
}
// Since updates come in dribs and drabs, avoid error if new max and min arrive
// out of sync and maximum < minimum.
if (vm.memory_dynamic_max >= vm.memory_dynamic_min &&
vm.memory_static_max >= vm.memory_static_min)
{
decimal min = Convert.ToDecimal(vm.memory_static_min / Util.BINARY_MEGA);
decimal max = Convert.ToDecimal(vm.MaxMemAllowed() / Util.BINARY_MEGA);
decimal value = Convert.ToDecimal(vm.memory_static_max / Util.BINARY_MEGA);
// Avoid setting the range to exclude the current value: CA-40041
if (value > max)
max = value;
if (value < min)
min = value;
this.nudMemory.Minimum = min;
this.nudMemory.Maximum = max;
this.nudMemory.Text = (this.nudMemory.Value = value).ToString();
}
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 12:31:16 +02:00
Host currentHost = Helpers.GetCoordinator(this.vm.Connection);
if (currentHost != null)
{
// Show the performance warning about vCPUs > pCPUs.
// Don't show if the VM isn't running, since we don't know which server it will
// run on (and so can't count the number of pCPUs).
if ( vm.power_state == vm_power_state.Running
&& vm.VCPUs_at_startup > currentHost.host_CPUs.Count
&& !vm.GetIgnoreExcessiveVcpus())
{
lblVcpuWarning.Visible = true;
this.tableLayoutPanel1.RowStyles[1].SizeType = SizeType.Absolute;
this.tableLayoutPanel1.RowStyles[1].Height = 30;
}
else
{
lblVcpuWarning.Visible = false;
}
}
else
{
lblVcpuWarning.Visible = false;
}
isVcpuHotplugSupported = vm.SupportsVcpuHotplug();
minVCPUs = vm.MinVCPUs();
label1.Text = GetRubric();
_OrigMemory = nudMemory.Value;
_OrigVCPUsMax = vm.VCPUs_max > 0 ? vm.VCPUs_max : 1;
_OrigVCPUsAtStartup = vm.VCPUs_at_startup > 0 ? vm.VCPUs_at_startup : 1;
_OrigVCPUWeight = _CurrentVCPUWeight;
_OrigVCPUs = isVcpuHotplugSupported ? _OrigVCPUsMax : _OrigVCPUsAtStartup;
_prevVCPUsMax = _OrigVCPUsMax; // we use variable in RefreshCurrentVCPUs for checking if VcpusAtStartup and VcpusMax were equal before VcpusMax changed
_CurrentVCPUWeight = Convert.ToDecimal(vm.GetVcpuWeight());
InitializeVcpuControls();
_ValidToSave = true;
}
private void InitializeVcpuControls()
{
lblVCPUs.Text = isVcpuHotplugSupported
? Messages.VM_CPUMEMPAGE_MAX_VCPUS_LABEL
: Messages.VM_CPUMEMPAGE_VCPUS_LABEL;
labelInitialVCPUs.Text = vm.power_state == vm_power_state.Halted
? Messages.VM_CPUMEMPAGE_INITIAL_VCPUS_LABEL
: Messages.VM_CPUMEMPAGE_CURRENT_VCPUS_LABEL;
labelInitialVCPUs.Visible = comboBoxInitialVCPUs.Visible = isVcpuHotplugSupported;
comboBoxInitialVCPUs.Enabled = isVcpuHotplugSupported &&
(vm.power_state == vm_power_state.Halted ||
vm.power_state == vm_power_state.Running);
comboBoxVCPUs.Enabled = comboBoxTopology.Enabled = vm.power_state == vm_power_state.Halted;
comboBoxTopology.Populate(vm.VCPUs_at_startup, vm.VCPUs_max, vm.GetCoresPerSocket(), vm.MaxCoresPerSocket());
// CA-12941
// We set a sensible maximum based on the template, but if the user sets something higher
// from the CLI then use that as the maximum.
var maxAllowed = vm.MaxVCPUsAllowed();
long maxVCPUs = maxAllowed < _OrigVCPUs ? _OrigVCPUs : maxAllowed;
PopulateVCPUs(maxVCPUs, _OrigVCPUs);
if (isVcpuHotplugSupported)
PopulateVCPUsAtStartup(_OrigVCPUsMax, _OrigVCPUsAtStartup);
transparentTrackBar1.Value = Convert.ToInt32(Math.Log(Convert.ToDouble(vm.GetVcpuWeight())) / Math.Log(4.0d));
panel1.Enabled = vm.power_state == vm_power_state.Halted;
}
private void PopulateVCPUComboBox(ComboBox comboBox, long min, long max, long currentValue, Predicate<long> isValid)
{
comboBox.BeginUpdate();
comboBox.Items.Clear();
for (long i = min; i <= max; ++i)
{
if (i == currentValue || isValid(i))
comboBox.Items.Add(i);
}
if (currentValue > max)
comboBox.Items.Add(currentValue);
comboBox.SelectedItem = currentValue;
comboBox.EndUpdate();
}
private void PopulateVCPUs(long maxVCPUs, long currentVCPUs)
{
PopulateVCPUComboBox(comboBoxVCPUs, 1, maxVCPUs, currentVCPUs, i => comboBoxTopology.IsValidVCPU(i));
}
private void PopulateVCPUsAtStartup(long max, long currentValue)
{
long min = vm.power_state == vm_power_state.Halted ? 1 : _OrigVCPUsAtStartup;
PopulateVCPUComboBox(comboBoxInitialVCPUs, min, max, currentValue, i => true);
}
private string GetRubric()
{
StringBuilder sb = new StringBuilder();
sb.Append(Messages.VM_CPUMEMPAGE_RUBRIC);
// add hotplug text
if (isVcpuHotplugSupported)
sb.Append(Messages.VM_CPUMEMPAGE_RUBRIC_HOTPLUG);
// add power state warning
if (vm.power_state != vm_power_state.Halted)
{
sb.AppendLine();
sb.AppendLine();
sb.Append(isVcpuHotplugSupported ? Messages.VM_CPUMEMPAGE_MAX_VCPUS_READONLY : Messages.VCPU_ONLY_WHEN_HALTED);
}
// add power state warning for Current number of vCPUs
if (isVcpuHotplugSupported && vm.power_state != vm_power_state.Halted && vm.power_state != vm_power_state.Running)
{
sb.Append(Messages.VM_CPUMEMPAGE_CURRENT_VCPUS_READONLY);
}
return sb.ToString();
}
public bool HasChanged
{
get { return HasVCPUChanged || HasMemoryChanged || HasTopologyChanged || HasVCPUsAtStartupChanged || HasVCPUWeightChanged; }
}
private bool HasMemoryChanged
{
get
{
return _OrigMemory != nudMemory.Value;
}
}
private bool HasVCPUChanged
{
get
{
return _OrigVCPUs != (long)comboBoxVCPUs.SelectedItem;
}
}
private bool HasVCPUWeightChanged
{
get
{
return _OrigVCPUWeight != _CurrentVCPUWeight;
}
}
private bool HasVCPUsAtStartupChanged
{
get
{
return isVcpuHotplugSupported && _OrigVCPUsAtStartup != (long)comboBoxInitialVCPUs.SelectedItem;
}
}
private bool HasTopologyChanged
{
get
{
return vm.GetCoresPerSocket() != comboBoxTopology.CoresPerSocket;
}
}
private long SelectedVcpusMax
{
get
{
return (long)comboBoxVCPUs.SelectedItem;
}
}
private long SelectedVcpusAtStartup
{
get
{
return isVcpuHotplugSupported ? (long)comboBoxInitialVCPUs.SelectedItem : (long)comboBoxVCPUs.SelectedItem;
}
}
public AsyncAction SaveSettings()
{
List<AsyncAction> actions = new List<AsyncAction>();
if (HasVCPUWeightChanged)
{
vm.SetVcpuWeight(Convert.ToInt32(_CurrentVCPUWeight));
}
if (HasVCPUChanged || HasVCPUsAtStartupChanged)
{
actions.Add(new ChangeVCPUSettingsAction(vm, SelectedVcpusMax, SelectedVcpusAtStartup));
}
if (HasTopologyChanged)
{
vm.SetCoresPerSocket(comboBoxTopology.CoresPerSocket);
}
if (HasMemoryChanged)
{
actions.Add(memoryAction); // Calculated in ValidToSave
}
if (actions.Count == 0)
return null;
else if (actions.Count == 1)
return actions[0];
else
{
MultipleAction multipleAction = new MultipleAction(vm.Connection, "", "", "", actions, true);
return multipleAction;
}
}
/** Show local validation balloon tooltips */
public void ShowLocalValidationMessages() { }
public void HideLocalValidationMessages() { }
/** Unregister listeners, dispose balloon tooltips, etc. */
public void Cleanup() { }
/// <summary>
/// Shows the warning dialog about vCPUs > pCPUs.
/// </summary>
private void lblVcpuWarning_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (vm == null)
{
System.Diagnostics.Trace.Assert(false, "Selected object should be a vm");
return;
}
using (var dialog = new WarningDialog(Messages.VCPUS_MORE_THAN_PCPUS)
{
ShowCheckbox = true,
CheckboxCaption = Messages.DO_NOT_SHOW_THIS_MESSAGE
})
{
dialog.ShowDialog(this);
if (dialog.IsCheckBoxChecked)
{
// User clicked 'ignore': set flag in VM.
log.DebugFormat("Setting IgnoreExcessiveVcpus flag to true for VM {0}", vm.Name());
VM copyVm = (VM)vm.Clone();
copyVm.SetIgnoreExcessiveVcpus(true);
try
{
vm.Locked = true;
copyVm.SaveChanges(vm.Connection.Session);
}
finally
{
vm.Locked = false;
}
}
else if (Program.MainWindow.SelectObjectInTree(vm))
{
Program.MainWindow.SwitchToTab(MainWindow.Tab.General);
}
}
Refresh();
}
private void nudMemory_ValueChanged(object sender, EventArgs e)
{
ShowMemError(false, true);
}
private void ShowMemError(bool showAlways, bool testValue)
{
if (vm == null || !ShowMemory)
return;
Host selectedAffinity = vm.Connection.Resolve<Host>(vm.power_state == vm_power_state.Running ? vm.resident_on : vm.affinity);
if (selectedAffinity != null)
{
Host_metrics host_metrics = vm.Connection.Resolve<Host_metrics>(selectedAffinity.metrics);
if ((showAlways || (testValue && (host_metrics != null && (double)host_metrics.memory_total < (double)nudMemory.Value * (double)Util.BINARY_MEGA))))
{
MemWarningLabel.Visible = true;
}
else
{
MemWarningLabel.Visible = false;
}
}
}
private void comboBoxVCPUs_SelectedIndexChanged(object sender, EventArgs e)
{
ValidateVCPUSettings();
comboBoxTopology.Update((long)comboBoxVCPUs.SelectedItem);
ValidateTopologySettings();
RefreshCurrentVCPUs();
}
private void ValidateVCPUSettings()
{
if (vm == null || !comboBoxVCPUs.Enabled)
return;
Host selectedAffinity = vm.Home();
if (selectedAffinity == null && vm.Connection.Cache.Hosts.Length == 1)
selectedAffinity = vm.Connection.Cache.Hosts[0];
if (selectedAffinity != null && comboBoxVCPUs.SelectedItem != null && selectedAffinity.host_CPUs.Count < SelectedVcpusMax)
{
VCPUWarningLabel.Text = Messages.VM_CPUMEMPAGE_VCPU_WARNING;
VCPUWarningLabel.Visible = true;
}
else if (comboBoxVCPUs.SelectedItem != null && SelectedVcpusMax < minVCPUs)
{
VCPUWarningLabel.Text = string.Format(Messages.VM_CPUMEMPAGE_VCPU_MIN_WARNING, minVCPUs);
VCPUWarningLabel.Visible = true;
}
else
{
VCPUWarningLabel.Visible = false;
}
if (comboBoxInitialVCPUs.SelectedItem != null && SelectedVcpusAtStartup < minVCPUs)
{
initialVCPUWarningLabel.Text = string.Format(Messages.VM_CPUMEMPAGE_VCPU_MIN_WARNING, minVCPUs);
initialVCPUWarningLabel.Visible = true;
}
else
{
initialVCPUWarningLabel.Visible = false;
}
}
private void ValidateTopologySettings()
{
if (comboBoxVCPUs.SelectedItem != null)
labelInvalidVCPUWarning.Text = VM.ValidVCPUConfiguration((long)comboBoxVCPUs.SelectedItem, comboBoxTopology.CoresPerSocket);
}
private long _prevVCPUsMax;
private void RefreshCurrentVCPUs()
{
// refresh comboBoxInitialVCPUs if it's visible and populated
if (comboBoxInitialVCPUs.Visible && comboBoxInitialVCPUs.Items.Count > 0)
{
// VcpusAtStartup is always <= VcpusMax
// So if VcpusMax is decreased below VcpusAtStartup, then VcpusAtStartup is decreased to that number too
// If VcpusAtStartup and VcpusMax are equal, and VcpusMax is changed, then VcpusAtStartup is changed to match
// But if the numbers are unequal, and VcpusMax is changed but is still higher than VcpusAtStartup, then VcpusAtStartup is unchanged
var newValue = SelectedVcpusAtStartup;
if (SelectedVcpusMax < SelectedVcpusAtStartup)
newValue = SelectedVcpusMax;
else if (SelectedVcpusAtStartup == _prevVCPUsMax && SelectedVcpusMax != _prevVCPUsMax)
newValue = SelectedVcpusMax;
PopulateVCPUsAtStartup(SelectedVcpusMax, newValue);
_prevVCPUsMax = SelectedVcpusMax;
}
}
public String SubText
{
get
{
return ShowMemory ?
String.Format(Messages.CPU_AND_MEMORY_SUB, SelectedVcpusAtStartup, nudMemory.Value) :
String.Format(Messages.CPU_SUB, SelectedVcpusAtStartup);
}
}
private void comboBoxTopology_SelectedIndexChanged(object sender, EventArgs e)
{
ValidateTopologySettings();
}
private void comboBoxInitialVCPUs_SelectedIndexChanged(object sender, EventArgs e)
{
ValidateVCPUSettings();
}
}
}