mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2024-11-24 22:06:59 +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>
239 lines
8.1 KiB
C#
239 lines
8.1 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;
|
||
using System.ComponentModel;
|
||
using System.Windows.Forms;
|
||
|
||
namespace XenAdmin.Controls.Ballooning
|
||
{
|
||
public partial class MemorySpinner : UserControl
|
||
{
|
||
public event EventHandler SpinnerValueChanged;
|
||
private double valueMB;
|
||
private string previousUnitsValue;
|
||
private bool initializing = true;
|
||
|
||
public MemorySpinner()
|
||
{
|
||
InitializeComponent();
|
||
previousUnitsValue = Messages.VAL_GIGB;
|
||
}
|
||
|
||
public void Initialize(double amount, double static_max)
|
||
{
|
||
amount = Util.CorrectRoundingErrors(amount);
|
||
|
||
Units = static_max <= Util.BINARY_GIGA ? Messages.VAL_MEGB : Messages.VAL_GIGB;
|
||
|
||
ChangeSpinnerSettings();
|
||
previousUnitsValue = Units;
|
||
Initialize(amount, RoundingBehaviour.None);
|
||
}
|
||
|
||
public void Initialize(double amount, RoundingBehaviour rounding)
|
||
{
|
||
ValueMB = Util.ToMB(amount, rounding);
|
||
setSpinnerValueDisplay(amount);
|
||
initializing = false;
|
||
}
|
||
|
||
[Browsable(false)]
|
||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||
public string Units
|
||
{
|
||
get
|
||
{
|
||
return SpinnerUnits.Text;
|
||
}
|
||
set
|
||
{
|
||
SpinnerUnits.Text = value;
|
||
}
|
||
}
|
||
|
||
[Browsable(false)]
|
||
public double Value
|
||
{
|
||
get
|
||
{
|
||
return ValueMB * Util.BINARY_MEGA;
|
||
}
|
||
}
|
||
|
||
double ValueMB
|
||
{
|
||
get
|
||
{
|
||
return valueMB;
|
||
}
|
||
|
||
set
|
||
{
|
||
valueMB = value;
|
||
}
|
||
}
|
||
|
||
private void setSpinnerValueDisplay(double value)
|
||
{
|
||
decimal newValue;
|
||
if (Units == "GB")
|
||
{
|
||
newValue = (decimal)Util.ToGB(value, RoundingBehaviour.Nearest, 1);
|
||
}
|
||
else
|
||
{
|
||
newValue = (long)Util.ToMB(value, RoundingBehaviour.Nearest);
|
||
}
|
||
if (newValue < Spinner.Minimum)
|
||
newValue = Spinner.Minimum;
|
||
if (newValue > Spinner.Maximum)
|
||
newValue = Spinner.Maximum;
|
||
Spinner.Value = newValue;
|
||
}
|
||
|
||
public static void CalcMBRanges(double minBytes, double maxBytes, out double minMB, out double maxMB)
|
||
{
|
||
// Round ranges inwards to avoid bugs like CA-34487 and CA-34996
|
||
minMB = Util.ToMB(minBytes, RoundingBehaviour.Up);
|
||
maxMB = Util.ToMB(maxBytes, RoundingBehaviour.Down);
|
||
if (minMB > maxMB) // just in case...
|
||
{
|
||
minMB = Util.ToMB(minBytes, RoundingBehaviour.None);
|
||
maxMB = Util.ToMB(maxBytes, RoundingBehaviour.None);
|
||
}
|
||
}
|
||
|
||
public static void CalcGBRanges(double minBytes, double maxBytes, out double minGB, out double maxGB)
|
||
{
|
||
// Round ranges inwards to avoid bugs like CA-34487 and CA-34996
|
||
minGB = Util.ToGB(minBytes, RoundingBehaviour.Up, 1);
|
||
maxGB = Util.ToGB(maxBytes, RoundingBehaviour.Down, 1);
|
||
if (minGB > maxGB) // just in case...
|
||
{
|
||
minGB = Util.ToGB(minBytes, RoundingBehaviour.None, 1);
|
||
maxGB = Util.ToGB(maxBytes, RoundingBehaviour.None, 1);
|
||
}
|
||
}
|
||
|
||
public void SetRange(double min, double max)
|
||
{
|
||
if (min > max)
|
||
return; // Can happen when we are adjusting several simultaneously: can cause a stack overflow
|
||
|
||
double spinnerMin, spinnerMax;
|
||
if (Units == "MB")
|
||
{
|
||
CalcMBRanges(min, max, out spinnerMin, out spinnerMax);
|
||
}
|
||
else
|
||
{
|
||
CalcGBRanges(min, max, out spinnerMin, out spinnerMax);
|
||
}
|
||
Spinner.Minimum = (decimal)spinnerMin;
|
||
Spinner.Maximum = (decimal)spinnerMax;
|
||
}
|
||
|
||
[Browsable(false)]
|
||
public double Increment
|
||
{
|
||
get
|
||
{
|
||
return (double)Spinner.Increment;
|
||
}
|
||
set
|
||
{
|
||
if (Units == "MB")
|
||
{
|
||
Spinner.Increment = (decimal)value / Util.BINARY_MEGA;
|
||
}
|
||
else
|
||
{
|
||
// When the units are GB, we simply want the numbers to increase by 1 if the spinner value is greater than 10 GB
|
||
// and by 0.1 if smaller than 10 GB, this being the reason we ignore the given value.
|
||
if (valueMB * Util.BINARY_MEGA < 10 * Util.BINARY_GIGA)
|
||
{
|
||
Spinner.Increment = 0.1M;
|
||
}
|
||
else
|
||
{
|
||
Spinner.Increment = 1;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private void Spinner_ValueChanged(object sender, EventArgs e)
|
||
{
|
||
// We do not want to modify the ValueMB if the user does not modify anything in the Spinner.Value.
|
||
// When the Memory Settings dialog is intiliazing and the units change because the new value is > 1 GB,
|
||
// we do not want any changes to be applied to ValueMB.
|
||
if (initializing)
|
||
return;
|
||
|
||
if (Units == "GB")
|
||
{
|
||
ValueMB = (double)Spinner.Value * Util.BINARY_KILO;
|
||
}
|
||
else
|
||
{
|
||
ValueMB = (double)Spinner.Value;
|
||
}
|
||
|
||
if (SpinnerValueChanged != null)
|
||
SpinnerValueChanged(this, e);
|
||
}
|
||
|
||
private void Spinner_Leave(object sender, EventArgs e)
|
||
{
|
||
var num = sender as NumericUpDown;
|
||
if (num != null)
|
||
num.Text = num.Value.ToString();
|
||
}
|
||
|
||
private void ChangeSpinnerSettings()
|
||
{
|
||
if (Units == previousUnitsValue)
|
||
return;
|
||
|
||
if (Units == "GB")
|
||
{
|
||
SetRange((double)Spinner.Minimum * Util.BINARY_MEGA, (double)Spinner.Maximum * Util.BINARY_MEGA);
|
||
Spinner.DecimalPlaces = 1;
|
||
}
|
||
else
|
||
{
|
||
SetRange((double)Spinner.Minimum * Util.BINARY_GIGA, (double)Spinner.Maximum * Util.BINARY_GIGA);
|
||
Spinner.DecimalPlaces = 0;
|
||
}
|
||
}
|
||
}
|
||
}
|