2017-01-16 20:59:50 +01:00
|
|
|
|
/* Copyright (c) Citrix Systems, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
* 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;
|
2020-04-08 01:57:39 +02:00
|
|
|
|
using System.Linq;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
using XenAdmin.Commands;
|
2018-09-11 16:51:32 +02:00
|
|
|
|
using XenAdmin.Core;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Controls.Ballooning
|
|
|
|
|
{
|
|
|
|
|
public partial class VMMemoryControlsBasic : VMMemoryControlsEdit
|
|
|
|
|
{
|
2020-04-08 01:57:39 +02:00
|
|
|
|
public event Action InstallTools;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
public VMMemoryControlsBasic()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
2015-09-21 17:09:12 +02:00
|
|
|
|
|
2020-04-12 02:27:49 +02:00
|
|
|
|
protected override void Populate()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
if (vms == null || vms.Count == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-04-12 02:27:49 +02:00
|
|
|
|
pictureBoxDynMin.Visible = hasBallooning;
|
|
|
|
|
pictureBoxDynMax.Visible = hasBallooning;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
// Calculate the maximum legal value of dynamic minimum
|
|
|
|
|
CalcMaxDynMin();
|
|
|
|
|
|
2018-08-13 02:39:09 +02:00
|
|
|
|
vmShinyBar.Populate(vms, true);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-09-11 16:51:32 +02:00
|
|
|
|
bool licenseRestriction = Helpers.FeatureForbidden(vm0.Connection, Host.RestrictDMC);
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
// Radio buttons and "DMC Unavailable" warning
|
2020-04-12 02:27:49 +02:00
|
|
|
|
if (hasBallooning && !licenseRestriction)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
if (vm0.memory_dynamic_min == vm0.memory_static_max)
|
2018-08-17 01:31:28 +02:00
|
|
|
|
radioFixed.Checked = true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
else
|
2018-08-17 01:31:28 +02:00
|
|
|
|
radioDynamic.Checked = true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
iconDMCUnavailable.Visible = labelDMCUnavailable.Visible = linkInstallTools.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-08-17 01:31:28 +02:00
|
|
|
|
radioFixed.Checked = true;
|
|
|
|
|
radioDynamic.Enabled = false;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
groupBoxOn.Enabled = false;
|
|
|
|
|
|
2018-09-11 16:51:32 +02:00
|
|
|
|
if (licenseRestriction)
|
|
|
|
|
{
|
|
|
|
|
labelDMCUnavailable.Text = Messages.DMC_UNAVAILABLE_LICENSE_RESTRICTION;
|
|
|
|
|
linkInstallTools.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
else if (vms.Count > 1)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
// If all the Virtualisation Statuses are the same, report that reason.
|
|
|
|
|
// Otherwise give a generic message.
|
2020-04-25 05:50:51 +02:00
|
|
|
|
VM.VirtualisationStatus vs0 = vm0.GetVirtualisationStatus(out _);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
bool identical = true;
|
|
|
|
|
foreach (VM vm in vms)
|
|
|
|
|
{
|
2020-04-25 05:50:51 +02:00
|
|
|
|
if (vm.GetVirtualisationStatus(out _) != vs0)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
identical = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (identical)
|
|
|
|
|
{
|
2020-04-25 05:50:51 +02:00
|
|
|
|
var status = vm0.GetVirtualisationStatus(out _);
|
2015-09-21 17:09:12 +02:00
|
|
|
|
if (status.HasFlag(VM.VirtualisationStatus.IO_DRIVERS_INSTALLED))
|
2015-09-14 17:21:44 +02:00
|
|
|
|
labelDMCUnavailable.Text = Messages.DMC_UNAVAILABLE_NOTSUPPORTED_PLURAL;
|
2015-09-18 16:48:59 +02:00
|
|
|
|
else if (!status.HasFlag(VM.VirtualisationStatus.IO_DRIVERS_INSTALLED))
|
2018-08-10 20:20:41 +02:00
|
|
|
|
labelDMCUnavailable.Text = vm0.HasNewVirtualisationStates()
|
|
|
|
|
? Messages.DMC_UNAVAILABLE_NO_IO_NO_MGMNT_PLURAL
|
|
|
|
|
: Messages.DMC_UNAVAILABLE_NOTOOLS_PLURAL;
|
2015-09-14 17:21:44 +02:00
|
|
|
|
else if (status.HasFlag(VM.VirtualisationStatus.PV_DRIVERS_OUT_OF_DATE))
|
2015-09-18 16:48:59 +02:00
|
|
|
|
labelDMCUnavailable.Text = Messages.DMC_UNAVAILABLE_OLDTOOLS_PLURAL;
|
2015-09-14 17:21:44 +02:00
|
|
|
|
else
|
|
|
|
|
labelDMCUnavailable.Text = Messages.DMC_UNAVAILABLE_VMS;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
labelDMCUnavailable.Text = Messages.DMC_UNAVAILABLE_VMS;
|
2020-04-08 01:57:39 +02:00
|
|
|
|
|
|
|
|
|
linkInstallTools.Visible = vms.All(InstallToolsCommand.CanExecute);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
else if (vm0.is_a_template)
|
|
|
|
|
{
|
|
|
|
|
labelDMCUnavailable.Text = Messages.DMC_UNAVAILABLE_TEMPLATE;
|
|
|
|
|
linkInstallTools.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-04-25 05:50:51 +02:00
|
|
|
|
var status = vm0.GetVirtualisationStatus(out _);
|
2015-09-14 17:21:44 +02:00
|
|
|
|
|
2015-09-21 17:09:12 +02:00
|
|
|
|
if (status.HasFlag(VM.VirtualisationStatus.IO_DRIVERS_INSTALLED))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
labelDMCUnavailable.Text = Messages.DMC_UNAVAILABLE_NOTSUPPORTED;
|
2015-09-18 16:48:59 +02:00
|
|
|
|
else if (!status.HasFlag(VM.VirtualisationStatus.IO_DRIVERS_INSTALLED))
|
2018-08-10 20:20:41 +02:00
|
|
|
|
labelDMCUnavailable.Text = vm0.HasNewVirtualisationStates()
|
|
|
|
|
? Messages.DMC_UNAVAILABLE_NO_IO_NO_MGMNT
|
|
|
|
|
: Messages.DMC_UNAVAILABLE_NOTOOLS;
|
2015-09-14 17:21:44 +02:00
|
|
|
|
else if (status.HasFlag(VM.VirtualisationStatus.PV_DRIVERS_OUT_OF_DATE))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
labelDMCUnavailable.Text = Messages.DMC_UNAVAILABLE_OLDTOOLS;
|
2015-09-14 17:21:44 +02:00
|
|
|
|
else
|
|
|
|
|
labelDMCUnavailable.Text = Messages.DMC_UNAVAILABLE_VM;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
linkInstallTools.Visible = InstallToolsCommand.CanExecute(vm0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-08 01:57:39 +02:00
|
|
|
|
if (linkInstallTools.Visible)
|
|
|
|
|
linkInstallTools.Text = vms.All(v => Helpers.StockholmOrGreater(v.Connection))
|
|
|
|
|
? Messages.INSTALLTOOLS_READ_MORE
|
|
|
|
|
: Messages.INSTALL_XENSERVER_TOOLS;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
// Spinners
|
|
|
|
|
FreeSpinnerRanges();
|
2018-08-29 16:01:51 +02:00
|
|
|
|
memorySpinnerDynMin.Initialize(vm0.memory_dynamic_min, vm0.memory_static_max);
|
|
|
|
|
memorySpinnerDynMax.Initialize(vm0.memory_dynamic_max, vm0.memory_static_max);
|
|
|
|
|
memorySpinnerFixed.Initialize(vm0.memory_static_max, vm0.memory_static_max);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
SetIncrements();
|
|
|
|
|
SetSpinnerRanges();
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-12 02:27:49 +02:00
|
|
|
|
protected override double dynamic_min
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2020-04-12 02:27:49 +02:00
|
|
|
|
System.Diagnostics.Trace.Assert(hasBallooning);
|
|
|
|
|
return radioDynamic.Checked ? memorySpinnerDynMin.Value : memorySpinnerFixed.Value;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-12 02:27:49 +02:00
|
|
|
|
protected override double dynamic_max
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2020-04-12 02:27:49 +02:00
|
|
|
|
System.Diagnostics.Trace.Assert(hasBallooning);
|
|
|
|
|
return radioDynamic.Checked ? memorySpinnerDynMax.Value : memorySpinnerFixed.Value;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-12 02:27:49 +02:00
|
|
|
|
protected override double static_max => (radioDynamic.Checked ? memorySpinnerDynMax.Value : memorySpinnerFixed.Value);
|
2018-08-29 16:01:51 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private void SetIncrements()
|
|
|
|
|
{
|
2016-03-10 12:44:48 +01:00
|
|
|
|
vmShinyBar.Increment = memorySpinnerDynMin.Increment = memorySpinnerDynMax.Increment = memorySpinnerFixed.Increment = CalcIncrement(static_max, memorySpinnerDynMax.Units);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DynamicSpinners_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2018-08-17 01:31:28 +02:00
|
|
|
|
radioDynamic.Checked = true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (sender == memorySpinnerDynMax)
|
|
|
|
|
{
|
|
|
|
|
// Force supported envelope
|
|
|
|
|
FreeSpinnerRanges();
|
2018-08-17 01:31:28 +02:00
|
|
|
|
long min = (long)(static_max * GetMemoryRatio());
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (memorySpinnerDynMin.Value < min)
|
2018-08-29 16:01:51 +02:00
|
|
|
|
memorySpinnerDynMin.Initialize(min, RoundingBehaviour.Up);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2015-08-20 13:41:39 +02:00
|
|
|
|
SetIncrements();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
SetSpinnerRanges();
|
2018-08-29 16:01:51 +02:00
|
|
|
|
vmShinyBar.ChangeSettings(vm0.memory_static_min, dynamic_min, dynamic_max, static_max);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
vmShinyBar.Refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FixedSpinner_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2018-08-17 01:31:28 +02:00
|
|
|
|
radioFixed.Checked = true;
|
2015-08-20 13:41:39 +02:00
|
|
|
|
SetIncrements();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetSpinnerRanges()
|
|
|
|
|
{
|
|
|
|
|
// Set the limit for the fixed spinner
|
2015-08-20 13:41:39 +02:00
|
|
|
|
double maxFixed = ((maxDynMin >= 0 && maxDynMin <= MemorySpinnerMax) ? maxDynMin : MemorySpinnerMax);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
memorySpinnerFixed.SetRange(vm0.memory_static_min >= Util.BINARY_MEGA ? vm0.memory_static_min : Util.BINARY_MEGA, maxFixed);
|
|
|
|
|
|
2020-04-12 02:27:49 +02:00
|
|
|
|
if (!hasBallooning)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Calculate limits for the dynamic spinners
|
2015-08-20 13:41:39 +02:00
|
|
|
|
double maxDM = DynMinSpinnerMax;
|
|
|
|
|
double minDM = DynMinSpinnerMin;
|
|
|
|
|
double maxSM = StatMaxSpinnerMax;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
// Set the limits
|
|
|
|
|
memorySpinnerDynMin.SetRange(minDM, maxDM);
|
|
|
|
|
memorySpinnerDynMax.SetRange(dynamic_min >= Util.BINARY_MEGA ? dynamic_min : Util.BINARY_MEGA, maxSM);
|
2015-08-20 13:41:39 +02:00
|
|
|
|
vmShinyBar.SetRanges(minDM, maxDM, dynamic_min, maxSM, memorySpinnerDynMax.Units);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FreeSpinnerRanges()
|
|
|
|
|
{
|
|
|
|
|
memorySpinnerDynMin.SetRange(0, MemorySpinnerMax);
|
|
|
|
|
memorySpinnerDynMax.SetRange(0, MemorySpinnerMax);
|
|
|
|
|
memorySpinnerFixed.SetRange(0, MemorySpinnerMax);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void vmShinyBar_SliderDragged(object sender, EventArgs e)
|
|
|
|
|
{
|
2018-08-29 16:01:51 +02:00
|
|
|
|
memorySpinnerDynMin.Initialize(vmShinyBar.Dynamic_min, RoundingBehaviour.None);
|
|
|
|
|
memorySpinnerDynMax.Initialize(vmShinyBar.Dynamic_max, RoundingBehaviour.None);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
memorySpinnerDynMin.Refresh();
|
|
|
|
|
memorySpinnerDynMax.Refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InstallTools_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Button != MouseButtons.Left)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-04-08 01:57:39 +02:00
|
|
|
|
if (vms.All(v => Helpers.StockholmOrGreater(v.Connection)))
|
2020-04-11 04:49:33 +02:00
|
|
|
|
{
|
2020-04-08 01:57:39 +02:00
|
|
|
|
Help.HelpManager.Launch("InstallToolsWarningDialog");
|
2020-04-11 04:49:33 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var cmd = new InstallToolsCommand(Program.MainWindow, vms);
|
|
|
|
|
cmd.InstallTools += _ => InstallTools?.Invoke();
|
|
|
|
|
cmd.Execute();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|