Merge pull request #1269 from mcintyre94/CA-228051

[CA-228051] XenCenter allows user to create unusable PVS Proxy cache config
This commit is contained in:
Mihaela Stoica 2016-11-11 17:08:13 +00:00 committed by GitHub
commit ab033700ad
6 changed files with 96 additions and 15 deletions

View File

@ -1,3 +1,5 @@
using XenAdmin.Controls;
namespace XenAdmin.Dialogs
{
partial class EnablePvsReadCachingDialog
@ -30,7 +32,7 @@ namespace XenAdmin.Dialogs
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(EnablePvsReadCachingDialog));
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.pvsSiteList = new System.Windows.Forms.ComboBox();
this.pvsSiteList = new LongStringComboBox();
this.rubricLabel = new System.Windows.Forms.Label();
this.pvsSiteLabel = new System.Windows.Forms.Label();
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
@ -118,7 +120,7 @@ namespace XenAdmin.Dialogs
private XenAdmin.Controls.ToolTipContainer readonlyCheckboxToolTipContainer;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.Label rubricLabel;
private System.Windows.Forms.ComboBox pvsSiteList;
private LongStringComboBox pvsSiteList;
private System.Windows.Forms.Label pvsSiteLabel;
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
private System.Windows.Forms.Button cancel;

View File

@ -31,25 +31,24 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using XenAdmin.Core;
using XenAPI;
using XenAdmin.Actions;
namespace XenAdmin.Dialogs
{
public partial class EnablePvsReadCachingDialog : XenDialogBase
{
private IList<VM> vms;
private readonly IList<VM> _vms;
public EnablePvsReadCachingDialog(IList<VM> vms)
{
InitializeComponent();
this.vms = vms;
_vms = vms;
if (vms.Count() > 1)
if (vms.Count > 1)
{
rubricLabel.Text = Messages.ENABLE_PVS_READ_CACHING_RUBRIC_MULTIPLE;
}
@ -64,10 +63,11 @@ namespace XenAdmin.Dialogs
private void PopulateSiteList()
{
// We assume all VMs share a pool
var vm = vms[0];
var vm = _vms[0];
foreach (var site in vm.Connection.Cache.PVS_sites)
{
var siteToAdd = new ToStringWrapper<PVS_site>(site, site.Name);
var siteToAdd = new PvsSiteComboBoxItem(site);
pvsSiteList.Items.Add(siteToAdd);
}
@ -79,12 +79,12 @@ namespace XenAdmin.Dialogs
private void enableButton_Click(object sender, EventArgs e)
{
var siteItemSelected = (ToStringWrapper<PVS_site>) pvsSiteList.SelectedItem;
var siteSelected = siteItemSelected.item;
var siteItemSelected = (PvsSiteComboBoxItem) pvsSiteList.SelectedItem;
var siteSelected = (PVS_site) siteItemSelected.Item;
var actions = new List<AsyncAction>();
foreach (var vm in vms)
foreach (var vm in _vms)
{
var action = GetAsyncActionForVm(vm, siteSelected);
if (action != null)
@ -140,4 +140,25 @@ namespace XenAdmin.Dialogs
return vifs.FirstOrDefault(vif => vif.device.Equals("0"));
}
}
internal class PvsSiteComboBoxItem
{
private readonly PVS_site _site;
public PvsSiteComboBoxItem(PVS_site site)
{
Debug.Assert(site != null, "site passed to combobox was null");
_site = site;
}
public override string ToString()
{
return _site.NameWithWarning;
}
public IXenObject Item
{
get { return _site; }
}
}
}

View File

@ -208,7 +208,7 @@ namespace XenAdmin.TabPages
PVS_site pvsSite = pvsProxy == null ? null : Connection.Resolve(pvsProxy.site);
row.Cells[0].Value = vm.Name;
row.Cells[1].Value = pvsProxy == null ? Messages.NO : Messages.YES;
row.Cells[2].Value = pvsProxy == null || pvsSite == null ? Messages.NO_VALUE : pvsSite.Name;
row.Cells[2].Value = pvsProxy == null || pvsSite == null ? Messages.NO_VALUE : pvsSite.NameWithWarning;
row.Cells[3].Value = pvsProxy == null ? Messages.NO_VALUE : pvs_proxy_status_extensions.ToFriendlyString(pvsProxy.status);
}
@ -327,7 +327,7 @@ namespace XenAdmin.TabPages
private void PvsSitePropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName != "name_label")
if (e.PropertyName != "name_label" && e.PropertyName != "cache_storage")
return;
Program.Invoke(this, () =>

View File

@ -28110,6 +28110,15 @@ namespace XenAdmin {
}
}
/// <summary>
/// Looks up a localized string similar to {0} (Incomplete PVS configuration).
/// </summary>
public static string PVS_CACHE_INCOMPLETE_CONFIGURATION {
get {
return ResourceManager.GetString("PVS_CACHE_INCOMPLETE_CONFIGURATION", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Memory and disk.
/// </summary>
@ -28146,6 +28155,15 @@ namespace XenAdmin {
}
}
/// <summary>
/// Looks up a localized string similar to {0} (Incomplete Cache Storage configuration).
/// </summary>
public static string PVS_CACHE_STORAGE_NOT_CONFIGURED {
get {
return ResourceManager.GetString("PVS_CACHE_STORAGE_NOT_CONFIGURED", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to This PVS cache configuration cannot be removed because there are VMs that are streamed from this site..
/// </summary>

View File

@ -9763,6 +9763,9 @@ Press OK to continue the wizard and return to the server and follow the instruct
<data name="PVS_CACHE_CONFIG_DIALOG_TITLE" xml:space="preserve">
<value>PVS Cache Configuration - '{0}'</value>
</data>
<data name="PVS_CACHE_INCOMPLETE_CONFIGURATION" xml:space="preserve">
<value>{0} (Incomplete PVS configuration)</value>
</data>
<data name="PVS_CACHE_MEMORY_AND_DISK" xml:space="preserve">
<value>Memory and disk</value>
</data>
@ -9775,6 +9778,9 @@ Press OK to continue the wizard and return to the server and follow the instruct
<data name="PVS_CACHE_NOT_CONFIGURED" xml:space="preserve">
<value>Not configured</value>
</data>
<data name="PVS_CACHE_STORAGE_NOT_CONFIGURED" xml:space="preserve">
<value>{0} (Incomplete Cache Storage configuration)</value>
</data>
<data name="PVS_SITE_CANNOT_BE_REMOVED" xml:space="preserve">
<value>This PVS cache configuration cannot be removed because there are VMs that are streamed from this site.</value>
</data>

View File

@ -30,6 +30,7 @@
using System;
using System.Linq;
using XenAdmin;
namespace XenAPI
{
@ -54,6 +55,39 @@ namespace XenAPI
pvsCacheStorage.site.opaque_ref == opaque_ref && pvsCacheStorage.host.opaque_ref == host.opaque_ref);
}
public string NameWithWarning
{
get
{
if (!IsCacheConfigured())
{
return string.Format(Messages.PVS_CACHE_INCOMPLETE_CONFIGURATION, Name);
}
if (!IsStorageConfigured())
{
return string.Format(Messages.PVS_CACHE_STORAGE_NOT_CONFIGURED, Name);
}
return Name;
}
}
private bool IsCacheConfigured()
{
return !string.IsNullOrEmpty(PVS_uuid);
}
private bool IsStorageConfigured()
{
var connectionHosts = Connection.Cache.Hosts;
var siteStorages = Connection.ResolveAll(cache_storage);
var storageHosts = Connection.ResolveAll(siteStorages.Select(storage => storage.host));
return connectionHosts.All(host => storageHosts.Contains(host));
}
#region IEquatable<PVS_site> Members
/// <summary>