Merge pull request #1782 from MihaelaStoica/REQ-566

CP-24498: RPU wizard to block the selection of unlicensed hosts
This commit is contained in:
Gabor Apati-Nagy 2017-09-26 15:04:24 +01:00 committed by GitHub
commit fb3cd9fc32
7 changed files with 83 additions and 21 deletions

View File

@ -56,33 +56,34 @@ namespace XenAdmin.Controls.DataGridViewEx
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
PoolHostDataGridViewOneCheckboxRow row = (PoolHostDataGridViewOneCheckboxRow)this.OwningRow;
Host host = value as Host;
if (host != null)
if (value is Host || value is Pool)
{
Image hostIcon = Images.GetImage16For(host);
Image hostIcon = Images.GetImage16For(value as IXenObject);
var iconIndent = row.IsCheckable ? 0 : 16;
var textIndent = iconIndent + 16;
base.Paint(graphics, clipBounds,
new Rectangle(cellBounds.X + 16, cellBounds.Y, cellBounds.Width - 16,
new Rectangle(cellBounds.X + textIndent, cellBounds.Y, cellBounds.Width - textIndent,
cellBounds.Height), rowIndex, cellState, value, formattedValue,
errorText, cellStyle, advancedBorderStyle, paintParts);
if ((cellState & DataGridViewElementStates.Selected) != 0 && row.Enabled )
{
using (var brush = new SolidBrush(DataGridView.DefaultCellStyle.SelectionBackColor))
graphics.FillRectangle(
brush, cellBounds.X, cellBounds.Y, hostIcon.Width, cellBounds.Height);
brush, cellBounds.X, cellBounds.Y, hostIcon.Width + iconIndent, cellBounds.Height);
}
else
{
//Background behind the host icon
using (var brush = new SolidBrush(this.DataGridView.DefaultCellStyle.BackColor))
graphics.FillRectangle(brush,
cellBounds.X, cellBounds.Y, hostIcon.Width, cellBounds.Height);
cellBounds.X, cellBounds.Y, hostIcon.Width + iconIndent, cellBounds.Height);
}
if (row.Enabled)
graphics.DrawImage(hostIcon, cellBounds.X, cellBounds.Y + 3, hostIcon.Width, hostIcon.Height);
graphics.DrawImage(hostIcon, cellBounds.X + iconIndent, cellBounds.Y + 3, hostIcon.Width, hostIcon.Height);
else
graphics.DrawImage(hostIcon,
new Rectangle(cellBounds.X, cellBounds.Y + 3, hostIcon.Width, hostIcon.Height),
new Rectangle(cellBounds.X + iconIndent, cellBounds.Y + 3, hostIcon.Width, hostIcon.Height),
0, 0, hostIcon.Width, hostIcon.Height, GraphicsUnit.Pixel,
Drawing.GreyScaleAttributes);
}

View File

@ -66,7 +66,7 @@ namespace XenAdmin.Wizards.RollingUpgradeWizard
this.expansionColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCells;
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle1.NullValue = ((object)(resources.GetObject("dataGridViewCellStyle1.NullValue")));
dataGridViewCellStyle1.Padding = new System.Windows.Forms.Padding(3, 0, 3, 0);
dataGridViewCellStyle1.Padding = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.expansionColumn.DefaultCellStyle = dataGridViewCellStyle1;
this.expansionColumn.FillWeight = 25.80645F;
resources.ApplyResources(this.expansionColumn, "expansionColumn");

View File

@ -153,11 +153,6 @@ namespace XenAdmin.Wizards.RollingUpgradeWizard
}
}
private static bool IsNotAnUpgradeableVersion(Host host)
{
return false; // currently, all supported versions are upgradable
}
public IList<Host> SelectedMasters
{
get
@ -205,13 +200,18 @@ namespace XenAdmin.Wizards.RollingUpgradeWizard
Pool pool = Helpers.GetPool(xenConnection);
Pool poolOfOne = Helpers.GetPoolOfOne(xenConnection);
bool restricted = Helpers.FeatureForbidden(xenConnection, Host.RestrictRpu);
bool hasPool = true;
if (pool != null)
{
int index = dataGridView1.Rows.Add(new UpgradeDataGridViewRow(pool));
if ((IsNotAnUpgradeableVersion(pool.SmallerVersionHost()) && !pool.RollingUpgrade()) || pool.IsUpgradeForbidden())
if ((restricted && !pool.RollingUpgrade()) || pool.IsUpgradeForbidden())
{
((DataGridViewExRow)dataGridView1.Rows[index]).Enabled = false;
if (restricted)
dataGridView1.Rows[index].Cells[NameColumn.Name].ToolTipText = Messages.ROLLING_UPGRADE_UNLICENSED_POOL;
}
else if (masters.Contains(pool.Connection.Resolve(pool.master)))
dataGridView1.CheckBoxChange(index, 1);
}
@ -225,8 +225,12 @@ namespace XenAdmin.Wizards.RollingUpgradeWizard
foreach (Host host in hosts)
{
int index = dataGridView1.Rows.Add(new UpgradeDataGridViewRow(host, hasPool));
if (IsNotAnUpgradeableVersion(host) || (poolOfOne != null && poolOfOne.IsUpgradeForbidden()))
if (restricted || (poolOfOne != null && poolOfOne.IsUpgradeForbidden()))
{
((DataGridViewExRow)dataGridView1.Rows[index]).Enabled = false;
if (restricted)
dataGridView1.Rows[index].Cells[NameColumn.Name].ToolTipText = Messages.ROLLING_UPGRADE_UNLICENSED_HOST;
}
else if (!hasPool && masters.Contains(host))
dataGridView1.CheckBoxChange(index, 1);
}
@ -276,6 +280,21 @@ namespace XenAdmin.Wizards.RollingUpgradeWizard
columnToBeSortedIndex == firstRow.VersionCellIndex)
SortAndRebuildTree(new CollapsingPoolHostRowSorter<UpgradeDataGridViewRow>(direction, columnToBeSortedIndex));
}
protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e)
{
base.OnCellPainting(e);
if (e.RowIndex >= 0)
{
var row = (PoolHostDataGridViewOneCheckboxRow)Rows[e.RowIndex];
if (row != null && !row.Enabled && e.ColumnIndex == row.PoolCheckBoxCellIndex)
{
e.PaintBackground(e.ClipBounds, true);
e.Handled = true;
}
}
}
}
public class UpgradeDataGridViewRow : PoolHostDataGridViewOneCheckboxRow

View File

@ -147,10 +147,10 @@
</data>
<assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="expansionColumn.MinimumWidth" type="System.Int32, mscorlib">
<value>20</value>
<value>18</value>
</data>
<data name="expansionColumn.Width" type="System.Int32, mscorlib">
<value>20</value>
<value>18</value>
</data>
<metadata name="checkBoxColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
@ -159,10 +159,10 @@
<value />
</data>
<data name="checkBoxColumn.MinimumWidth" type="System.Int32, mscorlib">
<value>24</value>
<value>20</value>
</data>
<data name="checkBoxColumn.Width" type="System.Int32, mscorlib">
<value>24</value>
<value>20</value>
</data>
<metadata name="NameColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>

View File

@ -29596,6 +29596,24 @@ namespace XenAdmin {
}
}
/// <summary>
/// Looks up a localized string similar to This server is not licensed for rolling pool upgrade.
/// </summary>
public static string ROLLING_UPGRADE_UNLICENSED_HOST {
get {
return ResourceManager.GetString("ROLLING_UPGRADE_UNLICENSED_HOST", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to This pool is not licensed for rolling pool upgrade.
/// </summary>
public static string ROLLING_UPGRADE_UNLICENSED_POOL {
get {
return ResourceManager.GetString("ROLLING_UPGRADE_UNLICENSED_POOL", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Rolling pool upgrade is complete..
/// </summary>

View File

@ -10300,6 +10300,12 @@ The master must be upgraded first, so if you skip the master, the rolling pool u
<data name="ROLLING_UPGRADE_TITLE_MODE" xml:space="preserve">
<value>Upgrade Mode</value>
</data>
<data name="ROLLING_UPGRADE_UNLICENSED_HOST" xml:space="preserve">
<value>This server is not licensed for rolling pool upgrade</value>
</data>
<data name="ROLLING_UPGRADE_UNLICENSED_POOL" xml:space="preserve">
<value>This pool is not licensed for rolling pool upgrade</value>
</data>
<data name="ROLLING_UPGRADE_UPGRADE_COMPLETED" xml:space="preserve">
<value>Rolling pool upgrade is complete.</value>
</data>

View File

@ -263,6 +263,13 @@ namespace XenAPI
return edition == "free";
}
public virtual bool IsFreeLicenseOrExpired()
{
if (Connection != null && Connection.CacheIsPopulated)
return IsFreeLicense() || LicenseExpiryUTC() < DateTime.UtcNow - Connection.ServerTimeOffset;
return true;
}
public static bool RestrictHA(Host h)
{
return !BoolKey(h.license_params, "enable_xha");
@ -402,6 +409,17 @@ namespace XenAPI
return true;
}
/// <summary>
/// The feature is restricted if the "restrict_rpu" key exists and it is true
/// or if the key is absent and the host is unlicensed
/// </summary>
public static bool RestrictRpu(Host h)
{
return h.license_params.ContainsKey("restrict_rpu")
? BoolKey(h.license_params, "restrict_rpu")
: h.IsFreeLicenseOrExpired(); // restrict on Free edition or if the license has expired
}
public bool HasPBDTo(SR sr)
{
foreach (XenRef<PBD> pbd in PBDs)