CA-110610: It should be possible to apply a free license to a 6.1 or earlier pool if the pool has two or more servers in it.

- split the pool members out when they're free, as the activation keys can only be applied to one XenServer host at a time

Signed-off-by: Mihaela Stoica <mihaela.stoica@citrix.com>
This commit is contained in:
Mihaela Stoica 2013-07-16 11:46:18 +01:00
parent b7d6b03577
commit 31fb3218b0
5 changed files with 88 additions and 6 deletions

View File

@ -36,6 +36,7 @@ using System.IO;
using System.Text;
using System.Xml;
using System.Linq;
using XenAdmin.Core;
using XenAPI;
namespace XenAdmin.Dialogs
@ -60,12 +61,17 @@ namespace XenAdmin.Dialogs
Hosts = hosts;
}
private bool CanActivate(Host host)
public static bool CanActivate(Host host)
{
//This check used to be "_expiresText != Messages.LICENSE_NEVER" but I've swapped it for
//"!host.isOEM" according to the ticket CA-37336 where this 3rd part of the check was added
//OEM licenses (< XS ver 5.5) have perpetual (2036) expiry dates
return host.IsFreeLicense() && host.IsFloodgateOrLater() && !host.isOEM;
return host.IsFreeLicense() && host.IsFloodgateOrLater() && !host.isOEM && !Helpers.ClearwaterOrGreater(host);
}
public static bool CanActivate(Pool pool)
{
return pool.Connection.Cache.Hosts.All(CanActivate);
}
public ReadOnlyCollection<Host> HostsThatCanBeActivated

View File

@ -43,6 +43,9 @@ namespace XenAdmin.Controls
{
private const string statusColumnKey = "statusImageColumn";
public delegate void RefreshAllEvent(object sender, EventArgs e);
public event RefreshAllEvent RefreshAll;
private LicenseCheckableDataGridViewController LicenseController
{
get { return Controller as LicenseCheckableDataGridViewController; }
@ -119,5 +122,12 @@ namespace XenAdmin.Controls
}
[EditorBrowsable(EditorBrowsableState.Never)]
public void TriggerRefreshAllEvent()
{
if (RefreshAll != null)
RefreshAll(this, EventArgs.Empty);
}
}
}

View File

@ -32,6 +32,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using XenAdmin.Controls;
using XenAdmin.Controls.CheckableDataGridView;
using XenAdmin.Core;
using XenAPI;
@ -71,9 +72,26 @@ namespace XenAdmin.Dialogs
licenseStatus.BeginUpdate();
}
private bool refreshing = false;
private void licenseStatus_ItemUpdated(object sender, EventArgs e)
{
TriggerCellTextUpdatedEvent();
if (refreshing)
return;
// check if we need to do a full refresh (i.e. pool members need to be displayed as individual items in the list)
if (RowShouldBeExpanded(XenObject) && DataGridView is LicenseCheckableDataGridView)
{
refreshing = true;
TriggerRefreshAllEvent();
}
else
TriggerCellTextUpdatedEvent();
}
public static bool RowShouldBeExpanded(IXenObject xenObject)
{
return xenObject is Pool && xenObject.Connection.Cache.Hosts.Length > 1
&& LicenseActivationRequest.CanActivate(xenObject as Pool);
}
public override Queue<object> CellText
@ -353,5 +371,12 @@ namespace XenAdmin.Dialogs
}
base.Dispose(disposing);
}
protected void TriggerRefreshAllEvent()
{
var view = DataGridView as LicenseCheckableDataGridView;
if (view != null)
view.TriggerRefreshAllEvent();
}
}
}

View File

@ -65,6 +65,7 @@ namespace XenAdmin.Dialogs
checkableDataGridView.SelectionChanged += checkableDataGridView_SelectionChanged;
checkableDataGridView.RowUpdated += checkableDataGridView_RowUpdated;
checkableDataGridView.RowChecked += checkableDataGridView_RowChecked;
checkableDataGridView.RefreshAll += checkableDataGridView_RefreshAll;
//Buttons
activateFreeXenServerButton.Click += activateFreeXenServerButton_Click;
@ -160,6 +161,11 @@ namespace XenAdmin.Dialogs
Controller.Repopulate(itemsToShow, selectedItems);
}
void checkableDataGridView_RefreshAll(object sender, EventArgs eventArgs)
{
Program.Invoke(this, Controller.Repopulate);
}
#region ISummaryPanelView Members
[EditorBrowsable(EditorBrowsableState.Never)]
public LicenseManagerController Controller { set; private get; }

View File

@ -40,6 +40,7 @@ using XenAdmin.Controls.CheckableDataGridView;
using XenAdmin.Controls.SummaryPanel;
using XenAdmin.Core;
using XenAdmin.Dialogs.LicenseManagerSelectionVerifiers;
using XenAdmin.Network;
using XenAPI;
namespace XenAdmin.Dialogs
@ -76,14 +77,26 @@ namespace XenAdmin.Dialogs
return;
}
AddToGrid(itemsToShow);
// show pool members as individual hosts if needed (i.e. can activate free license)
var allItemsToShow = new List<IXenObject>();
foreach (var xenObject in itemsToShow)
{
if (LicenseDataGridViewRow.RowShouldBeExpanded(xenObject))
{
allItemsToShow.AddRange(xenObject.Connection.Cache.Hosts);
}
else
allItemsToShow.Add(xenObject);
}
foreach (LicenseDataGridViewRow row in ConvertXenObjects(itemsToShow).ConvertAll(r => r as LicenseDataGridViewRow))
AddToGrid(allItemsToShow);
foreach (LicenseDataGridViewRow row in ConvertXenObjects(allItemsToShow).ConvertAll(r => r as LicenseDataGridViewRow))
{
UpdateButtonEnablement(new List<LicenseDataGridViewRow>{row});
}
CheckPreSelectedRows(selectedItems);
SelectAndSummariseSelectedRow(itemsToShow, selectedItems);
SelectAndSummariseSelectedRow(allItemsToShow, selectedItems);
}
public void Repopulate(List<IXenObject> itemsToShow, List<IXenObject> selectedItems)
@ -393,5 +406,27 @@ namespace XenAdmin.Dialogs
}
return hosts;
}
public void Repopulate()
{
Repopulate(GetAllObjects(), new List<IXenObject>());
}
private List<IXenObject> GetAllObjects()
{
List<IXenObject> allObjects = new List<IXenObject>();
foreach (IXenConnection conn in ConnectionsManager.XenConnections)
{
if (conn == null || !conn.IsConnected)
continue;
Pool pool = Helpers.GetPool(conn);
if (pool == null)
allObjects.AddRange(conn.Cache.Hosts);
else
allObjects.Add(pool);
}
return allObjects;
}
}
}