2013-06-24 13:41:48 +02:00
|
|
|
|
/* Copyright (c) Citrix Systems Inc.
|
|
|
|
|
* 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;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
using XenAdmin.Controls;
|
|
|
|
|
using XenAdmin.Controls.Ballooning;
|
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Wizards.NewVMWizard
|
|
|
|
|
{
|
|
|
|
|
public partial class Page_CpuMem : XenTabPage
|
|
|
|
|
{
|
|
|
|
|
private VM Template;
|
|
|
|
|
int memoryMode = 1; // number of spinners to show: 1 for just "memory", 2 for "minimum" and "maximum", 3 for "static max" too
|
|
|
|
|
double memoryRatio = 0.0; // the permitted ratio of dynamic_min / static_max
|
|
|
|
|
bool initialising = true;
|
|
|
|
|
|
|
|
|
|
public Page_CpuMem()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Text
|
|
|
|
|
{
|
|
|
|
|
get { return Messages.NEWVMWIZARD_CPUMEMPAGE_NAME; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string PageTitle
|
|
|
|
|
{
|
|
|
|
|
get { return Messages.NEWVMWIZARD_CPUMEMPAGE_TITLE; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string HelpID
|
|
|
|
|
{
|
|
|
|
|
get { return "CPU&Memory"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void PageLoaded(PageLoadedDirection direction)
|
|
|
|
|
{
|
|
|
|
|
base.PageLoaded(direction);
|
|
|
|
|
|
|
|
|
|
if (SelectedTemplate == Template)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
initialising = true;
|
|
|
|
|
|
|
|
|
|
Template = SelectedTemplate;
|
2015-10-26 17:01:55 +01:00
|
|
|
|
if (Template.has_ballooning && !Helpers.FeatureForbidden(Template, Host.RestrictDMC))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
memoryMode = (Template.memory_dynamic_max == Template.memory_static_max ? 2 : 3);
|
|
|
|
|
else
|
|
|
|
|
memoryMode = 1;
|
|
|
|
|
|
|
|
|
|
memoryRatio = VMMemoryControlsEdit.GetMemoryRatio(Template);
|
|
|
|
|
|
|
|
|
|
FreeSpinnerLimits();
|
|
|
|
|
|
|
|
|
|
if (memoryMode == 1)
|
|
|
|
|
{
|
2015-08-20 13:41:39 +02:00
|
|
|
|
spinnerDynMin.Initialize(Messages.MEMORY_COLON, null, Template.memory_static_max, Template.memory_static_max);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
spinnerDynMax.Visible = spinnerStatMax.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
spinnerDynMax.Visible = true;
|
2015-08-20 13:41:39 +02:00
|
|
|
|
spinnerDynMin.Initialize(Messages.DYNAMIC_MIN_COLON, null, Template.memory_dynamic_min, Template.memory_static_max);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
FreeSpinnerLimits(); // same as CA-33831
|
2015-08-20 13:41:39 +02:00
|
|
|
|
spinnerDynMax.Initialize(Messages.DYNAMIC_MAX_COLON, null, Template.memory_dynamic_max, Template.memory_static_max);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (memoryMode == 3)
|
|
|
|
|
{
|
|
|
|
|
FreeSpinnerLimits();
|
2015-08-20 13:41:39 +02:00
|
|
|
|
spinnerStatMax.Initialize(Messages.STATIC_MAX_COLON, null, Template.memory_static_max, Template.memory_static_max);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
spinnerStatMax.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-05 14:03:06 +02:00
|
|
|
|
comboBoxTopology.Populate(Template.VCPUs_at_startup, Template.VCPUs_max, Template.CoresPerSocket, Template.MaxCoresPerSocket);
|
2016-02-12 18:01:05 +01:00
|
|
|
|
PopulateVCPUs(Template.MaxVCPUsAllowed, Template.VCPUs_at_startup);
|
2014-06-05 14:03:06 +02:00
|
|
|
|
|
2016-03-10 12:44:48 +01:00
|
|
|
|
SetSpinnerLimitsAndIncrement();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
ValuesUpdated();
|
|
|
|
|
|
|
|
|
|
initialising = false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-12 18:01:05 +01:00
|
|
|
|
private void PopulateVCPUs(long maxVCPUs, long currentVCPUs)
|
|
|
|
|
{
|
|
|
|
|
comboBoxVCPUs.BeginUpdate();
|
|
|
|
|
comboBoxVCPUs.Items.Clear();
|
|
|
|
|
for (long i = 1; i <= maxVCPUs; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (i == currentVCPUs || comboBoxTopology.IsValidVCPU(i))
|
|
|
|
|
comboBoxVCPUs.Items.Add(i);
|
|
|
|
|
}
|
|
|
|
|
if (currentVCPUs > maxVCPUs)
|
|
|
|
|
comboBoxVCPUs.Items.Add(currentVCPUs);
|
|
|
|
|
comboBoxVCPUs.SelectedItem = currentVCPUs;
|
|
|
|
|
comboBoxVCPUs.EndUpdate();
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
public VM SelectedTemplate { private get; set; }
|
|
|
|
|
|
|
|
|
|
// Return the larger of the template's MaxMemAllowed and the template's static max,
|
|
|
|
|
// to avoid crashes in the spinners (CA-40041).
|
|
|
|
|
private long MaxMemAllowed
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
long msm = Template.memory_static_max;
|
|
|
|
|
long mma = Template.MaxMemAllowed;
|
|
|
|
|
return (msm > mma ? msm : mma);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FreeSpinnerLimits()
|
|
|
|
|
{
|
|
|
|
|
long maxMemAllowed = MaxMemAllowed;
|
|
|
|
|
spinnerDynMin.SetRange(0, maxMemAllowed);
|
|
|
|
|
spinnerDynMax.SetRange(0, maxMemAllowed);
|
|
|
|
|
spinnerStatMax.SetRange(0, maxMemAllowed);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-10 12:44:48 +01:00
|
|
|
|
private void SetSpinnerLimitsAndIncrement()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2016-03-10 12:44:48 +01:00
|
|
|
|
spinnerDynMin.Increment = spinnerDynMax.Increment = spinnerStatMax.Increment = VMMemoryControlsEdit.CalcIncrement(Template.memory_static_max, spinnerDynMin.Units);
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
long maxMemAllowed = MaxMemAllowed;
|
2015-08-20 13:41:39 +02:00
|
|
|
|
double min = Template.memory_static_min;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (memoryMode == 1)
|
|
|
|
|
{
|
|
|
|
|
spinnerDynMin.SetRange(min, maxMemAllowed);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-08-20 13:41:39 +02:00
|
|
|
|
long min2 = (long)(SelectedMemoryStaticMax * memoryRatio);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (min < min2)
|
|
|
|
|
min = min2;
|
2015-08-20 13:41:39 +02:00
|
|
|
|
double max = SelectedMemoryDynamicMax;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (max < min)
|
|
|
|
|
max = min;
|
|
|
|
|
spinnerDynMin.SetRange(min, max);
|
|
|
|
|
spinnerDynMax.SetRange(SelectedMemoryDynamicMin,
|
|
|
|
|
memoryMode == 2 ? maxMemAllowed : SelectedMemoryStaticMax);
|
|
|
|
|
spinnerStatMax.SetRange(SelectedMemoryDynamicMax, maxMemAllowed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DisableMemoryControls()
|
|
|
|
|
{
|
|
|
|
|
spinnerDynMin.Enabled = false;
|
|
|
|
|
spinnerDynMax.Enabled = false;
|
|
|
|
|
spinnerStatMax.Enabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-20 13:41:39 +02:00
|
|
|
|
public double SelectedMemoryDynamicMin
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return spinnerDynMin.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-20 13:41:39 +02:00
|
|
|
|
public double SelectedMemoryDynamicMax
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return memoryMode == 1 ? spinnerDynMin.Value : spinnerDynMax.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-20 13:41:39 +02:00
|
|
|
|
public double SelectedMemoryStaticMax
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return
|
|
|
|
|
memoryMode == 1 ? spinnerDynMin.Value :
|
|
|
|
|
memoryMode == 2 ? spinnerDynMax.Value :
|
|
|
|
|
spinnerStatMax.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public long SelectedVcpus
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-02-12 18:01:05 +01:00
|
|
|
|
return (long)comboBoxVCPUs.SelectedItem;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-05 14:03:06 +02:00
|
|
|
|
public long SelectedCoresPerSocket
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return comboBoxTopology.CoresPerSocket;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
public override List<KeyValuePair<string, string>> PageSummary
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
List<KeyValuePair<string, string>> sum = new List<KeyValuePair<string, string>>();
|
|
|
|
|
sum.Add(new KeyValuePair<string, string>(Messages.NEWVMWIZARD_CPUMEMPAGE_VCPUS, SelectedVcpus.ToString()));
|
2014-06-05 14:03:06 +02:00
|
|
|
|
sum.Add(new KeyValuePair<string, string>(Messages.NEWVMWIZARD_CPUMEMPAGE_TOPOLOGY, comboBoxTopology.Text));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (memoryMode == 1)
|
2015-09-10 15:36:46 +02:00
|
|
|
|
sum.Add(new KeyValuePair<string, string>(Messages.MEMORY, Util.MemorySizeStringSuitableUnits(SelectedMemoryStaticMax, false)));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
2015-09-10 15:36:46 +02:00
|
|
|
|
sum.Add(new KeyValuePair<string, string>(Messages.DYNAMIC_MIN, Util.MemorySizeStringSuitableUnits(SelectedMemoryDynamicMin, false)));
|
|
|
|
|
sum.Add(new KeyValuePair<string, string>(Messages.DYNAMIC_MAX, Util.MemorySizeStringSuitableUnits(SelectedMemoryDynamicMax, false)));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (memoryMode == 3)
|
2015-09-10 15:36:46 +02:00
|
|
|
|
sum.Add(new KeyValuePair<string, string>(Messages.STATIC_MAX, Util.MemorySizeStringSuitableUnits(SelectedMemoryStaticMax, false)));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
return sum;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ValuesUpdated()
|
|
|
|
|
{
|
|
|
|
|
CheckForError();
|
|
|
|
|
OnPageUpdated();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckForError()
|
|
|
|
|
{
|
|
|
|
|
long max_mem_total = 0;
|
|
|
|
|
long max_mem_free = 0;
|
|
|
|
|
long max_vcpus = 0;
|
|
|
|
|
Host max_mem_total_host = null;
|
|
|
|
|
Host max_mem_free_host = null;
|
|
|
|
|
Host max_vcpus_host = null;
|
|
|
|
|
|
|
|
|
|
foreach (Host host in Connection.Cache.Hosts)
|
|
|
|
|
{
|
|
|
|
|
long host_cpus = 0;
|
|
|
|
|
|
|
|
|
|
foreach (Host_cpu cpu in Connection.Cache.Host_cpus)
|
|
|
|
|
{
|
|
|
|
|
if (cpu.host.opaque_ref.Equals(host.opaque_ref))
|
|
|
|
|
host_cpus++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Host_metrics metrics = Connection.Resolve(host.metrics);
|
|
|
|
|
|
|
|
|
|
if (host_cpus > max_vcpus)
|
|
|
|
|
{
|
|
|
|
|
max_vcpus = host_cpus;
|
|
|
|
|
max_vcpus_host = host;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (metrics != null && metrics.memory_total > max_mem_total)
|
|
|
|
|
{
|
|
|
|
|
max_mem_total = metrics.memory_total;
|
|
|
|
|
max_mem_total_host = host;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The available memory of a server is taken to be the current memory_free,
|
|
|
|
|
// plus however much we can squeeze down the existing VMs. This assumes
|
|
|
|
|
// that the overhead won't increase when we create the new VM, so it
|
|
|
|
|
// has false negatives.
|
|
|
|
|
long memory_free = host.memory_available_calc;
|
|
|
|
|
|
|
|
|
|
if (metrics != null && memory_free > max_mem_free)
|
|
|
|
|
{
|
|
|
|
|
max_mem_free = memory_free;
|
|
|
|
|
max_mem_free_host = host;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (max_mem_total_host != null && SelectedMemoryDynamicMin > max_mem_total)
|
|
|
|
|
{
|
|
|
|
|
ErrorPanel.Visible = true;
|
2015-09-10 15:36:46 +02:00
|
|
|
|
ErrorLabel.Text = string.Format(Messages.NEWVMWIZARD_CPUMEMPAGE_MEMORYWARN1, Helpers.GetName(max_mem_total_host), Util.MemorySizeStringSuitableUnits(max_mem_total, false));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
else if (max_mem_free_host != null && SelectedMemoryDynamicMin > max_mem_free)
|
|
|
|
|
{
|
|
|
|
|
ErrorPanel.Visible = true;
|
2015-09-10 15:36:46 +02:00
|
|
|
|
ErrorLabel.Text = string.Format(Messages.NEWVMWIZARD_CPUMEMPAGE_MEMORYWARN2, Helpers.GetName(max_mem_free_host), Util.MemorySizeStringSuitableUnits(max_mem_free, false));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
else if (max_vcpus_host != null && SelectedVcpus > max_vcpus)
|
|
|
|
|
{
|
|
|
|
|
ErrorPanel.Visible = true;
|
|
|
|
|
ErrorLabel.Text = string.Format(Messages.NEWVMWIZARD_CPUMEMPAGE_VCPUSWARN, Helpers.GetName(max_vcpus_host), max_vcpus);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ErrorPanel.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void vCPU_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2016-02-12 18:01:05 +01:00
|
|
|
|
comboBoxTopology.Update((long)comboBoxVCPUs.SelectedItem);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
ValuesUpdated();
|
2014-06-06 16:33:22 +02:00
|
|
|
|
ValidateVCPUSettings();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void memory_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (initialising)
|
|
|
|
|
return;
|
|
|
|
|
|
2016-03-10 12:44:48 +01:00
|
|
|
|
SetSpinnerLimitsAndIncrement();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
ValuesUpdated();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-06 16:33:22 +02:00
|
|
|
|
private void ValidateVCPUSettings()
|
|
|
|
|
{
|
2016-02-12 18:01:05 +01:00
|
|
|
|
if (comboBoxVCPUs.SelectedItem != null)
|
|
|
|
|
labelInvalidVCPUWarning.Text = VM.ValidVCPUConfiguration((long)comboBoxVCPUs.SelectedItem, comboBoxTopology.CoresPerSocket);
|
2014-06-06 16:33:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void comboBoxTopology_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ValidateVCPUSettings();
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|