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;
|
2013-09-20 12:24:46 +02:00
|
|
|
|
using System.Collections.Generic;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Drawing;
|
2013-09-18 14:06:47 +02:00
|
|
|
|
using System.Linq;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using XenAdmin.Actions;
|
2013-09-18 14:06:47 +02:00
|
|
|
|
using XenAdmin.Controls;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using XenAdmin.Properties;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.SettingsPanels
|
|
|
|
|
{
|
2013-09-20 12:24:46 +02:00
|
|
|
|
public partial class GpuEditPage : XenTabPage, IEditPage
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-09-20 12:24:46 +02:00
|
|
|
|
public VM vm;
|
2013-09-18 14:06:47 +02:00
|
|
|
|
private GpuTuple currentGpuTuple;
|
|
|
|
|
private GPU_group[] gpu_groups;
|
|
|
|
|
private bool gpusAvailable;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
public GpuEditPage()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2013-09-20 12:24:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public GPU_group GpuGroup
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
GpuTuple tuple = comboBoxGpus.SelectedItem as GpuTuple;
|
|
|
|
|
return tuple == null ? null : tuple.GpuGroup;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public VGPU_type VgpuType
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
GpuTuple tuple = comboBoxGpus.SelectedItem as GpuTuple;
|
|
|
|
|
if (tuple == null || tuple.VgpuTypes == null || tuple.VgpuTypes.Length == 0)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
return tuple.VgpuTypes[0];
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region IEditPage Members
|
|
|
|
|
|
|
|
|
|
public AsyncAction SaveSettings()
|
|
|
|
|
{
|
2013-09-20 12:24:46 +02:00
|
|
|
|
return new GpuAssignAction(vm, GpuGroup, VgpuType);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetXenObjects(IXenObject orig, IXenObject clone)
|
|
|
|
|
{
|
|
|
|
|
Trace.Assert(clone is VM); // only VMs should show this page
|
|
|
|
|
Trace.Assert(Helpers.BostonOrGreater(clone.Connection)); // If not Boston or greater, we shouldn't see this page
|
|
|
|
|
Trace.Assert(!Helpers.FeatureForbidden(clone, Host.RestrictGpu)); // If license insufficient, we show upsell page instead
|
|
|
|
|
|
|
|
|
|
vm = (VM)clone;
|
2013-09-18 14:06:47 +02:00
|
|
|
|
|
2013-09-20 12:24:46 +02:00
|
|
|
|
if (Connection == null) // on the PropertiesDialog
|
|
|
|
|
Connection = vm.Connection;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2013-09-20 12:24:46 +02:00
|
|
|
|
PopulatePage();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ValidToSave
|
|
|
|
|
{
|
|
|
|
|
get { return true; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowLocalValidationMessages()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Cleanup()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool HasChanged
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2013-09-18 14:06:47 +02:00
|
|
|
|
var tuple = comboBoxGpus.SelectedItem as GpuTuple;
|
|
|
|
|
if (tuple == null)
|
|
|
|
|
return false;
|
|
|
|
|
return !tuple.Equals(currentGpuTuple);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region VerticalTab Members
|
|
|
|
|
|
|
|
|
|
public string SubText
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2013-09-18 14:06:47 +02:00
|
|
|
|
var tuple = comboBoxGpus.SelectedItem as GpuTuple;
|
|
|
|
|
return tuple == null ? "" : tuple.ToString();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Image Image
|
|
|
|
|
{
|
|
|
|
|
get { return Resources._000_GetMemoryInfo_h32bit_16; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2013-09-20 12:24:46 +02:00
|
|
|
|
#region XenTabPage overrides
|
|
|
|
|
|
|
|
|
|
public override string Text
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-09-20 12:24:46 +02:00
|
|
|
|
get { return Messages.GPU; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string PageTitle
|
|
|
|
|
{
|
|
|
|
|
get { return Messages.NEWVMWIZARD_VGPUPAGE_TITLE; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string HelpID
|
|
|
|
|
{
|
|
|
|
|
get { return "GPU"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override List<KeyValuePair<string, string>> PageSummary
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var summ = new List<KeyValuePair<string, string>>();
|
|
|
|
|
|
|
|
|
|
GpuTuple tuple = comboBoxGpus.SelectedItem as GpuTuple;
|
|
|
|
|
if (tuple != null)
|
|
|
|
|
summ.Add(new KeyValuePair<string, string>(Messages.GPU, tuple.ToString()));
|
|
|
|
|
|
|
|
|
|
return summ;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void PopulatePage()
|
|
|
|
|
{
|
|
|
|
|
currentGpuTuple = new GpuTuple(null, null);
|
|
|
|
|
|
|
|
|
|
if (vm.VGPUs.Count != 0)
|
|
|
|
|
{
|
|
|
|
|
VGPU vgpu = Connection.Resolve(vm.VGPUs[0]);
|
|
|
|
|
if (vgpu != null)
|
|
|
|
|
{
|
|
|
|
|
var vgpuGroup = Connection.Resolve(vgpu.GPU_group);
|
|
|
|
|
|
|
|
|
|
if (Helpers.FeatureForbidden(Connection, Host.RestrictVgpu))
|
|
|
|
|
currentGpuTuple = new GpuTuple(vgpuGroup, null);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
VGPU_type vgpuType = Connection.Resolve(vgpu.type);
|
|
|
|
|
currentGpuTuple = new GpuTuple(vgpuGroup, new[] { vgpuType });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gpu_groups = Connection.Cache.GPU_groups;
|
|
|
|
|
gpusAvailable = gpu_groups.Length > 0;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (!gpusAvailable)
|
|
|
|
|
{
|
|
|
|
|
labelGpuType.Visible = comboBoxGpus.Visible = false;
|
2013-09-20 12:24:46 +02:00
|
|
|
|
labelRubric.Text = Helpers.GetPool(Connection) == null
|
2013-09-18 14:06:47 +02:00
|
|
|
|
? Messages.GPU_RUBRIC_NO_GPUS_SERVER
|
|
|
|
|
: Messages.GPU_RUBRIC_NO_GPUS_POOL;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-09-18 14:06:47 +02:00
|
|
|
|
var noneItem = new GpuTuple(null, null);
|
|
|
|
|
comboBoxGpus.Items.Add(noneItem);
|
|
|
|
|
|
|
|
|
|
Array.Sort(gpu_groups);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
foreach (GPU_group gpu_group in gpu_groups)
|
2013-09-18 14:06:47 +02:00
|
|
|
|
{
|
2013-09-20 12:24:46 +02:00
|
|
|
|
if (Helpers.FeatureForbidden(Connection, Host.RestrictVgpu))
|
2013-09-18 14:06:47 +02:00
|
|
|
|
{
|
|
|
|
|
comboBoxGpus.Items.Add(new GpuTuple(gpu_group, null));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-09-20 12:24:46 +02:00
|
|
|
|
var enabledRefs = GPU_group.get_enabled_VGPU_types(Connection.Session, gpu_group.opaque_ref);
|
|
|
|
|
var enabledTypes = Connection.ResolveAll(enabledRefs);
|
2013-09-18 14:06:47 +02:00
|
|
|
|
|
|
|
|
|
if (enabledTypes.Count > 1)
|
|
|
|
|
{
|
|
|
|
|
enabledTypes.Sort((t1, t2) =>
|
|
|
|
|
{
|
|
|
|
|
int result = t1.max_heads.CompareTo(t2.max_heads);
|
|
|
|
|
if (result != 0)
|
|
|
|
|
return result;
|
|
|
|
|
return t1.Name.CompareTo(t2.Name);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
comboBoxGpus.Items.Add(new GpuTuple(gpu_group, enabledTypes.ToArray()));
|
|
|
|
|
|
|
|
|
|
foreach (var vgpuType in enabledTypes)
|
|
|
|
|
comboBoxGpus.Items.Add(new GpuTuple(gpu_group, new[] { vgpuType }));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
comboBoxGpus.Items.Add(new GpuTuple(gpu_group, null));
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2013-09-18 14:06:47 +02:00
|
|
|
|
foreach (var item in comboBoxGpus.Items)
|
|
|
|
|
{
|
|
|
|
|
var tuple = item as GpuTuple;
|
|
|
|
|
if (tuple == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (tuple.Equals(currentGpuTuple))
|
|
|
|
|
{
|
|
|
|
|
comboBoxGpus.SelectedItem = item;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ShowHideWarnings();
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-20 12:24:46 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private void ShowHideWarnings()
|
|
|
|
|
{
|
|
|
|
|
if (!gpusAvailable)
|
|
|
|
|
{
|
2013-09-18 14:06:47 +02:00
|
|
|
|
imgRDP.Visible = labelRDP.Visible =
|
|
|
|
|
imgNeedDriver.Visible = labelNeedDriver.Visible =
|
|
|
|
|
imgNeedGpu.Visible = labelNeedGpu.Visible =
|
|
|
|
|
imgStopVM.Visible = labelStopVM.Visible =
|
2013-06-24 13:41:48 +02:00
|
|
|
|
false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-20 12:24:46 +02:00
|
|
|
|
if (vm.power_state != vm_power_state.Halted)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-09-18 14:06:47 +02:00
|
|
|
|
imgRDP.Visible = labelRDP.Visible =
|
|
|
|
|
imgNeedDriver.Visible = labelNeedDriver.Visible =
|
|
|
|
|
imgNeedGpu.Visible = labelNeedGpu.Visible =
|
2013-06-24 13:41:48 +02:00
|
|
|
|
false;
|
|
|
|
|
|
2013-09-18 14:06:47 +02:00
|
|
|
|
imgStopVM.Visible = labelStopVM.Visible = true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2013-09-18 14:06:47 +02:00
|
|
|
|
labelGpuType.Enabled = comboBoxGpus.Enabled = false;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-18 14:06:47 +02:00
|
|
|
|
GpuTuple tuple = comboBoxGpus.SelectedItem as GpuTuple;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
imgStopVM.Visible = labelStopVM.Visible = false;
|
2013-09-18 14:06:47 +02:00
|
|
|
|
imgRDP.Visible = labelRDP.Visible =
|
|
|
|
|
HasChanged && currentGpuTuple.GpuGroup == null &&
|
|
|
|
|
tuple != null && !tuple.IsFractionalVgpu;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2013-09-18 14:06:47 +02:00
|
|
|
|
imgNeedGpu.Visible = labelNeedGpu.Visible =
|
|
|
|
|
labelNeedDriver.Visible = imgNeedDriver.Visible =
|
|
|
|
|
tuple != null && tuple.GpuGroup != null;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void comboBoxGpus_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2013-09-18 14:06:47 +02:00
|
|
|
|
warningsTable.SuspendLayout();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
ShowHideWarnings();
|
2013-09-18 14:06:47 +02:00
|
|
|
|
warningsTable.ResumeLayout();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void warningsTable_SizeChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
int[] columnsWidth = warningsTable.GetColumnWidths();
|
2013-09-18 14:06:47 +02:00
|
|
|
|
int textColumnWidth = columnsWidth.Length > 1 ? columnsWidth[1] : 1;
|
|
|
|
|
|
|
|
|
|
labelRDP.MaximumSize = labelStopVM.MaximumSize = new Size(textColumnWidth, 999);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|