CA-310974: Hide GPU page if the host has no GPU capability (#2847)

* CA-310974: Hide GPU page if the host has no GPU capability

* Hid GPU page in PropertiesDialog
* Hid GPU page in NewVMWizard

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-310974: Move GPU availability check to Helpers class

* Switch from field to method based check
* Update affected logic
* Remove rubric toggle in PopulatePage when GpuEditPage is shown
* Hide AddVGPUDialog when GpusAvailable returns false

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-310974: Remove missing GPUs strings in Messages.resx

* GPU_RUBRIC_NO_GPUS_POOL
* GPU_RUBRIC_NO_GPUS_SERVER

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-310974: Disable combobox in AddVGPUDialog when there are no GPUs

Avoids exception being thrown if user tries to select empty first item

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-310974: Amend position of GPU availability check

Moved since gpuCapability is used in the Finish method of the wizard

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-310974: Remove unecessary null checks in Helpers method

The Cache and its properties (e.g. GPU_groups) are readonly and initialised as empty.
The API object properties that are ref lists (g.PGPUs, g.supported_VGPU_types) are also initialised as empty and are demarshalled by the SDK as empty if they have no values.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>
This commit is contained in:
Danilo Del Busso 2021-08-23 10:58:41 +01:00 committed by GitHub
parent dbd5f0c344
commit bcc5cf8166
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 53 deletions

View File

@ -55,6 +55,14 @@ namespace XenAdmin.Dialogs
private void PopulateComboBox()
{
GPU_group[] gpu_groups = _vm.Connection.Cache.GPU_groups.Where(g => g.PGPUs.Count > 0 && g.supported_VGPU_types.Count != 0).ToArray();
//comboBoxTypes should not be available for selection
if (gpu_groups.Length == 0)
{
comboBoxTypes.Enabled = false;
return;
}
Array.Sort(gpu_groups);
foreach (GPU_group gpu_group in gpu_groups)
{

View File

@ -241,7 +241,8 @@ namespace XenAdmin.Dialogs
}
else
{
ShowTab(GpuEditPage = new GpuEditPage());
if(Helpers.GpusAvailable(connection))
ShowTab(GpuEditPage = new GpuEditPage());
}
}

View File

@ -40,6 +40,7 @@ using XenAdmin.Controls;
using XenAdmin.Controls.DataGridViewEx;
using XenAdmin.Core;
using XenAdmin.Dialogs;
using XenAdmin.Network;
using XenAPI;
@ -49,8 +50,6 @@ namespace XenAdmin.SettingsPanels
{
public VM vm;
private List<VGPU> currentGpus = new List<VGPU>();
private GPU_group[] gpu_groups;
private bool gpusAvailable;
public GpuEditPage()
{
@ -119,7 +118,7 @@ namespace XenAdmin.SettingsPanels
{
string txt = Messages.UNAVAILABLE;
if (gpusAvailable)
if (Helpers.GpusAvailable(Connection))
{
var vGpus = VGpus;
txt = vGpus.Count > 0 ? string.Join(",", vGpus.Select(v => v.VGpuTypeDescription())) : Messages.GPU_NONE;
@ -159,26 +158,8 @@ namespace XenAdmin.SettingsPanels
public override void PopulatePage()
{
currentGpus.Clear();
gpu_groups = Connection.Cache.GPU_groups.Where(g => g.PGPUs.Count > 0 && g.supported_VGPU_types.Count != 0).ToArray();
//not showing empty groups
gpusAvailable = gpu_groups.Length > 0;
if (gpusAvailable)
{
PopulateGrid();
ShowHideWarnings();
}
else
{
labelRubric.Text = Helpers.GetPool(Connection) == null
? Messages.GPU_RUBRIC_NO_GPUS_SERVER
: Messages.GPU_RUBRIC_NO_GPUS_POOL;
gpuGrid.Visible = addButton.Visible = deleteButton.Visible = false;
warningsTable.Visible = false;
}
PopulateGrid();
ShowHideWarnings();
}
public override void SelectDefaultControl()
@ -217,9 +198,6 @@ namespace XenAdmin.SettingsPanels
public void ShowHideWarnings()
{
if (!gpusAvailable)
return;
var vGpus = VGpus;
imgExperimental.Visible = labelExperimental.Visible =
@ -255,7 +233,7 @@ namespace XenAdmin.SettingsPanels
}
var multipleVgpuSupport = vGpus.All(v => { var x = Connection.Resolve(v.type); return x != null && x.compatible_types_in_vm.Count > 0; });
addButton.Enabled = multipleVgpuSupport;
addButton.Enabled = Helpers.GpusAvailable(Connection) && multipleVgpuSupport;
deleteButton.Enabled = gpuGrid.SelectedRows.Count > 0;
imgMulti.Visible = labelMulti.Visible = vGpus.Count > 0;

View File

@ -220,7 +220,7 @@ namespace XenAdmin.Wizards.NewVMWizard
RemovePage(pageVgpu);
gpuCapability = Helpers.GpuCapability(xenConnection) && selectedTemplate.CanHaveGpu();
gpuCapability = Helpers.GpuCapability(xenConnection) && selectedTemplate.CanHaveGpu() && Helpers.GpusAvailable(xenConnection);
if (gpuCapability)
AddAfterPage(page_5_CpuMem, pageVgpu);

View File

@ -17604,24 +17604,6 @@ namespace XenAdmin {
}
}
/// <summary>
/// Looks up a localized string similar to You can improve graphics performance by assigning a dedicated graphics processing unit (GPU) to a VM. However, no GPUs have been detected in this pool, so this option is not currently available..
/// </summary>
public static string GPU_RUBRIC_NO_GPUS_POOL {
get {
return ResourceManager.GetString("GPU_RUBRIC_NO_GPUS_POOL", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to You can improve graphics performance by assigning a dedicated graphics processing unit (GPU) to a VM. However, no GPUs have been detected in this server, so this option is not currently available..
/// </summary>
public static string GPU_RUBRIC_NO_GPUS_SERVER {
get {
return ResourceManager.GetString("GPU_RUBRIC_NO_GPUS_SERVER", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Select which virtual GPU types are allowed on these GPUs..
/// </summary>

View File

@ -6141,12 +6141,6 @@ Would you like to eject these ISOs before continuing?</value>
<data name="GPU_PLACEMENT_POLICY_MIXED_DESCRIPTION" xml:space="preserve">
<value>Mixed: different settings for different GPU groups</value>
</data>
<data name="GPU_RUBRIC_NO_GPUS_POOL" xml:space="preserve">
<value>You can improve graphics performance by assigning a dedicated graphics processing unit (GPU) to a VM. However, no GPUs have been detected in this pool, so this option is not currently available.</value>
</data>
<data name="GPU_RUBRIC_NO_GPUS_SERVER" xml:space="preserve">
<value>You can improve graphics performance by assigning a dedicated graphics processing unit (GPU) to a VM. However, no GPUs have been detected in this server, so this option is not currently available.</value>
</data>
<data name="GPU_RUBRIC_PLEASE_SELECT_WHICH_GPU_MULTIPLE" xml:space="preserve">
<value>Select which virtual GPU types are allowed on these GPUs.</value>
</data>

View File

@ -1910,5 +1910,10 @@ namespace XenAdmin.Core
orderby network.Key
select network.Value.Split(new[] { "\n", "%n" }, StringSplitOptions.RemoveEmptyEntries)).SelectMany(x => x).Distinct().ToList();
}
public static bool GpusAvailable(IXenConnection connection)
{
return connection?.Cache.GPU_groups.Any(g => g.PGPUs.Count > 0 && g.supported_VGPU_types.Count != 0) ?? false;
}
}
}