2017-01-16 20:59:50 +01:00
|
|
|
|
/* Copyright (c) Citrix Systems, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
* 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;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using XenAdmin.Controls;
|
|
|
|
|
using XenAdmin.Controls.DataGridViewEx;
|
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using XenAdmin.Dialogs;
|
|
|
|
|
using XenAdmin.Network;
|
|
|
|
|
using XenAdmin.Properties;
|
|
|
|
|
using XenAPI;
|
2015-07-20 15:28:44 +02:00
|
|
|
|
using XenAdmin.Alerts;
|
2016-07-19 10:12:30 +02:00
|
|
|
|
using System.Linq;
|
2018-07-06 04:03:40 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Wizards.PatchingWizard
|
|
|
|
|
{
|
|
|
|
|
public partial class PatchingWizard_SelectServers : XenTabPage
|
|
|
|
|
{
|
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
|
|
|
|
private const int PLUS_MINUS_COL = 0;
|
|
|
|
|
private const int POOL_CHECKBOX_COL = 1;
|
|
|
|
|
private const int POOL_ICON_HOST_CHECKBOX_COL = 2;
|
|
|
|
|
|
|
|
|
|
private const int UNCHECKED = 0;
|
|
|
|
|
private const int CHECKED = 1;
|
|
|
|
|
private const int INDETERMINATE = 2;
|
|
|
|
|
|
2017-01-11 12:32:57 +01:00
|
|
|
|
private bool poolSelectionOnly;
|
|
|
|
|
|
2015-07-20 15:28:44 +02:00
|
|
|
|
public XenServerPatchAlert SelectedUpdateAlert { private get; set; }
|
2015-07-20 16:27:41 +02:00
|
|
|
|
public XenServerPatchAlert FileFromDiskAlert { private get; set; }
|
2018-07-06 18:31:29 +02:00
|
|
|
|
public bool FileFromDiskHasUpdateXml { private get; set; }
|
2017-03-24 17:43:19 +01:00
|
|
|
|
public WizardMode WizardMode { private get; set; }
|
2015-07-20 16:27:41 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
public PatchingWizard_SelectServers()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
dataGridViewHosts.CheckBoxClicked += dataGridViewHosts_CheckBoxClicked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Text
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Messages.PATCHINGWIZARD_SELECTSERVERPAGE_TEXT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string PageTitle
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Messages.PATCHINGWIZARD_SELECTSERVERPAGE_TITLE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string HelpID
|
|
|
|
|
{
|
|
|
|
|
get { return "SelectServers"; }
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-09 01:31:46 +01:00
|
|
|
|
protected override void PageLoadedCore(PageLoadedDirection direction)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-07-06 02:46:12 +02:00
|
|
|
|
poolSelectionOnly = WizardMode == WizardMode.AutomatedUpdates || SelectedUpdateAlert != null || FileFromDiskAlert != null;
|
|
|
|
|
|
|
|
|
|
switch (WizardMode)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-07-06 02:46:12 +02:00
|
|
|
|
case WizardMode.AutomatedUpdates:
|
|
|
|
|
label1.Text = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_RUBRIC_AUTOMATED_MODE;
|
|
|
|
|
break;
|
|
|
|
|
case WizardMode.NewVersion:
|
|
|
|
|
label1.Text = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_RUBRIC_NEW_VERSION_MODE;
|
|
|
|
|
break;
|
|
|
|
|
case WizardMode.SingleUpdate:
|
|
|
|
|
label1.Text = poolSelectionOnly ? Messages.PATCHINGWIZARD_SELECTSERVERPAGE_RUBRIC_POOL_SELECTION : Messages.PATCHINGWIZARD_SELECTSERVERPAGE_RUBRIC_DEFAULT;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-03-28 12:17:26 +02:00
|
|
|
|
|
2018-07-06 02:46:12 +02:00
|
|
|
|
// catch selected servers, in order to restore selection after the dataGrid is reloaded
|
|
|
|
|
List<Host> selectedServers = SelectedServers;
|
|
|
|
|
|
|
|
|
|
dataGridViewHosts.Rows.Clear();
|
|
|
|
|
|
|
|
|
|
List<IXenConnection> xenConnections = ConnectionsManager.XenConnectionsCopy;
|
|
|
|
|
xenConnections.Sort();
|
|
|
|
|
int licensedPoolCount = 0;
|
|
|
|
|
int poolCount = 0;
|
|
|
|
|
foreach (IXenConnection xenConnection in xenConnections)
|
|
|
|
|
{
|
|
|
|
|
// add pools, their members and standalone hosts
|
|
|
|
|
Pool pool = Helpers.GetPool(xenConnection);
|
|
|
|
|
bool hasPool = pool != null;
|
|
|
|
|
PatchingHostsDataGridViewRow poolRow = null;
|
|
|
|
|
|
|
|
|
|
if (hasPool)
|
2017-03-28 12:17:26 +02:00
|
|
|
|
{
|
2018-07-06 02:46:12 +02:00
|
|
|
|
poolRow = new PatchingHostsDataGridViewRow(pool);
|
2018-07-06 04:03:40 +02:00
|
|
|
|
dataGridViewHosts.Rows.Add(poolRow);
|
2018-07-06 02:46:12 +02:00
|
|
|
|
poolRow.Enabled = false;
|
2017-03-28 12:17:26 +02:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-07-06 02:46:12 +02:00
|
|
|
|
Host[] hosts = xenConnection.Cache.Hosts;
|
2016-07-01 18:41:49 +02:00
|
|
|
|
|
2018-07-06 02:46:12 +02:00
|
|
|
|
if (hosts.Length > 0)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-07-06 02:46:12 +02:00
|
|
|
|
poolCount++;
|
|
|
|
|
var automatedUpdatesRestricted = hosts.Any(Host.RestrictBatchHotfixApply); //if any host is not licensed for automated updates
|
|
|
|
|
if (!automatedUpdatesRestricted)
|
|
|
|
|
licensedPoolCount++;
|
|
|
|
|
}
|
2016-06-17 15:15:59 +02:00
|
|
|
|
|
2018-07-06 02:46:12 +02:00
|
|
|
|
Array.Sort(hosts);
|
2018-07-06 04:03:40 +02:00
|
|
|
|
PatchingHostsDataGridViewRow masterRow = null;
|
|
|
|
|
|
2018-07-06 02:46:12 +02:00
|
|
|
|
foreach (Host host in hosts)
|
|
|
|
|
{
|
2018-07-06 04:03:40 +02:00
|
|
|
|
var hostRow = new PatchingHostsDataGridViewRow(host, hasPool, !poolSelectionOnly) {ParentPoolRow = poolRow};
|
|
|
|
|
dataGridViewHosts.Rows.Add(hostRow);
|
|
|
|
|
string tooltipText;
|
|
|
|
|
hostRow.Enabled = CanEnableRow(host, out tooltipText);
|
|
|
|
|
hostRow.Cells[3].ToolTipText = tooltipText;
|
|
|
|
|
|
2018-07-06 02:46:12 +02:00
|
|
|
|
//Enable the pool row
|
2018-07-06 04:03:40 +02:00
|
|
|
|
if (poolRow != null && hostRow.Enabled)
|
2018-07-06 02:46:12 +02:00
|
|
|
|
poolRow.Enabled = true;
|
2017-03-27 17:12:49 +02:00
|
|
|
|
|
2018-07-06 04:03:40 +02:00
|
|
|
|
if (masterRow == null) //this will be true for the first iteration
|
|
|
|
|
masterRow = hostRow;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2018-07-06 04:03:40 +02:00
|
|
|
|
|
|
|
|
|
if (poolRow != null && !poolRow.Enabled && masterRow != null)
|
|
|
|
|
poolRow.Cells[3].ToolTipText = masterRow.Cells[3].ToolTipText;
|
2018-07-06 02:46:12 +02:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-07-06 02:46:12 +02:00
|
|
|
|
if (WizardMode == WizardMode.NewVersion && licensedPoolCount > 0) // in NewVersion mode and at least one pool licensed for automated updates
|
|
|
|
|
{
|
|
|
|
|
applyUpdatesCheckBox.Visible = true;
|
|
|
|
|
applyUpdatesCheckBox.Text = poolCount == licensedPoolCount
|
|
|
|
|
? Messages.PATCHINGWIZARD_SELECTSERVERPAGE_APPLY_UPDATES
|
|
|
|
|
: Messages.PATCHINGWIZARD_SELECTSERVERPAGE_APPLY_UPDATES_MIXED;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2018-07-06 02:46:12 +02:00
|
|
|
|
else // not in NewVersion mode or all pools unlicensed
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-07-06 02:46:12 +02:00
|
|
|
|
applyUpdatesCheckBox.Visible = false;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2018-07-06 02:46:12 +02:00
|
|
|
|
|
|
|
|
|
// restore server selection
|
|
|
|
|
SelectServers(selectedServers);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2016-03-14 17:10:16 +01:00
|
|
|
|
|
2016-12-08 15:47:58 +01:00
|
|
|
|
public override void SelectDefaultControl()
|
|
|
|
|
{
|
|
|
|
|
dataGridViewHosts.Select();
|
|
|
|
|
}
|
2016-03-14 17:10:16 +01:00
|
|
|
|
|
2018-07-06 04:03:40 +02:00
|
|
|
|
private bool CanEnableRow(Host host, out string tooltipText)
|
|
|
|
|
{
|
|
|
|
|
//if host is unreachable
|
|
|
|
|
if (!host.IsLive())
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-07-06 04:03:40 +02:00
|
|
|
|
tooltipText = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_HOST_UNREACHABLE;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-07-19 10:12:30 +02:00
|
|
|
|
|
2018-07-06 04:03:40 +02:00
|
|
|
|
return WizardMode == WizardMode.AutomatedUpdates
|
|
|
|
|
? CanEnableRowAutomatedUpdates(host, out tooltipText)
|
|
|
|
|
: CanEnableRowNonAutomated(host, out tooltipText);
|
|
|
|
|
}
|
2016-07-19 10:12:30 +02:00
|
|
|
|
|
2018-07-06 04:03:40 +02:00
|
|
|
|
private bool CanEnableRowAutomatedUpdates(Host host, out string tooltipText)
|
|
|
|
|
{
|
|
|
|
|
var poolOfOne = Helpers.GetPoolOfOne(host.Connection);
|
2016-07-19 10:12:30 +02:00
|
|
|
|
|
2018-07-06 04:03:40 +02:00
|
|
|
|
// This check is first because it generally can't be fixed, it's a property of the host
|
|
|
|
|
if (poolOfOne != null && poolOfOne.IsAutoUpdateRestartsForbidden()) // Forbids update auto restarts
|
|
|
|
|
{
|
|
|
|
|
tooltipText = Messages.POOL_FORBIDS_AUTOMATED_UPDATES;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-03-16 13:59:20 +01:00
|
|
|
|
|
2018-07-06 04:03:40 +02:00
|
|
|
|
var pool = Helpers.GetPool(host.Connection);
|
|
|
|
|
if (WizardMode != WizardMode.NewVersion && pool != null && !pool.IsPoolFullyUpgraded()) //partially upgraded pool is not supported
|
|
|
|
|
{
|
|
|
|
|
tooltipText = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_AUTOMATED_UPDATES_NOT_SUPPORTED_PARTIALLY_UPGRADED;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-01-24 18:41:35 +01:00
|
|
|
|
|
2018-07-06 04:03:40 +02:00
|
|
|
|
//check updgrade sequences
|
|
|
|
|
var minimalPatches = WizardMode == WizardMode.NewVersion
|
|
|
|
|
? Updates.GetMinimalPatches(host)
|
|
|
|
|
: Updates.GetMinimalPatches(host.Connection);
|
|
|
|
|
if (minimalPatches == null) //version not supported
|
|
|
|
|
{
|
|
|
|
|
tooltipText = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_AUTOMATED_UPDATES_NOT_SUPPORTED_HOST_VERSION;
|
|
|
|
|
return false;
|
2016-03-14 17:10:16 +01:00
|
|
|
|
}
|
2016-03-16 13:59:20 +01:00
|
|
|
|
|
2018-07-06 04:03:40 +02:00
|
|
|
|
//check all hosts are licensed for automated updates (there may be restrictions on individual hosts)
|
|
|
|
|
if (host.Connection.Cache.Hosts.Any(Host.RestrictBatchHotfixApply))
|
2016-03-14 17:10:16 +01:00
|
|
|
|
{
|
2018-07-06 04:03:40 +02:00
|
|
|
|
tooltipText = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_HOST_UNLICENSED_FOR_AUTOMATED_UPDATES;
|
|
|
|
|
return false;
|
2016-03-16 13:59:20 +01:00
|
|
|
|
}
|
2018-07-06 04:03:40 +02:00
|
|
|
|
|
|
|
|
|
var us = Updates.GetPatchSequenceForHost(host, minimalPatches);
|
|
|
|
|
if (us == null)
|
2016-03-16 13:59:20 +01:00
|
|
|
|
{
|
2018-07-06 04:03:40 +02:00
|
|
|
|
tooltipText = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_SERVER_NOT_AUTO_UPGRADABLE;
|
|
|
|
|
return false;
|
2016-03-16 13:59:20 +01:00
|
|
|
|
}
|
2016-06-20 15:10:00 +02:00
|
|
|
|
|
2018-07-06 04:03:40 +02:00
|
|
|
|
//if host is up to date
|
|
|
|
|
if (us.Count == 0)
|
2016-03-16 13:59:20 +01:00
|
|
|
|
{
|
2018-07-06 04:03:40 +02:00
|
|
|
|
tooltipText = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_SERVER_UP_TO_DATE;
|
|
|
|
|
return false;
|
2016-03-16 13:59:20 +01:00
|
|
|
|
}
|
2016-03-14 17:10:16 +01:00
|
|
|
|
|
2018-07-06 04:03:40 +02:00
|
|
|
|
tooltipText = null;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool CanEnableRowNonAutomated(Host host, out string tooltipText)
|
|
|
|
|
{
|
|
|
|
|
tooltipText = null;
|
|
|
|
|
|
|
|
|
|
if (!host.CanApplyHotfixes() && (Helpers.ElyOrGreater(host) || SelectedUpdateType != UpdateType.ISO))
|
2017-01-24 18:41:35 +01:00
|
|
|
|
{
|
2018-07-06 04:03:40 +02:00
|
|
|
|
tooltipText = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_HOST_UNLICENSED;
|
|
|
|
|
return false;
|
2017-01-24 18:41:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-18 11:46:41 +02:00
|
|
|
|
switch (SelectedUpdateType)
|
2016-03-16 13:59:20 +01:00
|
|
|
|
{
|
|
|
|
|
case UpdateType.NewRetail:
|
|
|
|
|
case UpdateType.Existing:
|
2017-02-17 17:56:44 +01:00
|
|
|
|
if (Helpers.ElyOrGreater(host))
|
|
|
|
|
{
|
2018-07-06 04:03:40 +02:00
|
|
|
|
tooltipText = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_PATCH_NOT_APPLICABLE;
|
2018-07-12 15:27:20 +02:00
|
|
|
|
return false;
|
2017-02-17 17:56:44 +01:00
|
|
|
|
}
|
2018-07-12 15:27:20 +02:00
|
|
|
|
|
2018-07-06 04:03:40 +02:00
|
|
|
|
string reason;
|
|
|
|
|
if (!IsHostAmongApplicable(host, out reason))
|
|
|
|
|
{
|
|
|
|
|
tooltipText = reason;
|
2018-07-12 15:27:20 +02:00
|
|
|
|
return false;
|
2018-07-06 04:03:40 +02:00
|
|
|
|
}
|
2018-07-11 17:31:57 +02:00
|
|
|
|
|
2018-07-12 15:27:20 +02:00
|
|
|
|
if (!Helpers.ElyOrGreater(host) && Helpers.ElyOrGreater(host.Connection)) // host is pre-Ely, but the master is Ely or greater
|
2018-07-11 17:31:57 +02:00
|
|
|
|
{
|
|
|
|
|
tooltipText = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_CANNOT_INSTALL_UPDATE_MASTER_POST_7_0;
|
2018-07-12 15:27:20 +02:00
|
|
|
|
return false;
|
2018-07-11 17:31:57 +02:00
|
|
|
|
}
|
2018-07-12 15:27:20 +02:00
|
|
|
|
|
|
|
|
|
return true;
|
2018-07-06 04:03:40 +02:00
|
|
|
|
|
2016-08-31 11:42:09 +02:00
|
|
|
|
case UpdateType.ISO:
|
2018-07-06 04:03:40 +02:00
|
|
|
|
//from Ely onwards, iso does not mean supplemental pack
|
|
|
|
|
if (!Helpers.CreamOrGreater(host.Connection))
|
2016-03-16 13:59:20 +01:00
|
|
|
|
{
|
2018-07-06 04:03:40 +02:00
|
|
|
|
tooltipText = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_CANNOT_INSTALL_SUPP_PACKS;
|
|
|
|
|
return false;
|
2016-03-16 13:59:20 +01:00
|
|
|
|
}
|
2018-07-06 04:03:40 +02:00
|
|
|
|
|
2018-07-06 18:31:29 +02:00
|
|
|
|
if (WizardMode == WizardMode.AutomatedUpdates || SelectedUpdateAlert != null || FileFromDiskAlert != null)
|
2018-07-06 04:03:40 +02:00
|
|
|
|
return IsHostAmongApplicable(host, out tooltipText);
|
2018-07-06 18:31:29 +02:00
|
|
|
|
|
|
|
|
|
// here a file from disk was selected, but it was not an update (FileFromDiskAlert == null)
|
|
|
|
|
if ((!Helpers.ElyOrGreater(host.Connection) && FileFromDiskHasUpdateXml) ||
|
|
|
|
|
(Helpers.ElyOrGreater(host.Connection) && !FileFromDiskHasUpdateXml))
|
2016-10-05 13:55:34 +02:00
|
|
|
|
{
|
2018-07-06 18:31:29 +02:00
|
|
|
|
tooltipText = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_PATCH_NOT_APPLICABLE;
|
2018-07-06 04:03:40 +02:00
|
|
|
|
return false;
|
2016-10-05 13:55:34 +02:00
|
|
|
|
}
|
2018-07-06 18:31:29 +02:00
|
|
|
|
|
2018-07-06 04:03:40 +02:00
|
|
|
|
return true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-06 04:03:40 +02:00
|
|
|
|
return true;
|
2017-02-27 17:14:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-06 04:03:40 +02:00
|
|
|
|
private bool IsHostAmongApplicable(Host host, out string tooltipText)
|
2015-07-20 15:28:44 +02:00
|
|
|
|
{
|
2018-07-06 04:03:40 +02:00
|
|
|
|
string patchUuidFromAlert = null;
|
|
|
|
|
List<Host> applicableHosts = null;
|
2017-01-11 12:32:57 +01:00
|
|
|
|
|
2018-07-06 04:03:40 +02:00
|
|
|
|
if (SelectedUpdateAlert != null)
|
2015-07-20 15:28:44 +02:00
|
|
|
|
{
|
2018-07-06 04:03:40 +02:00
|
|
|
|
applicableHosts = SelectedUpdateAlert.DistinctHosts;
|
|
|
|
|
if(SelectedUpdateAlert.Patch != null)
|
2016-10-05 13:55:34 +02:00
|
|
|
|
patchUuidFromAlert = SelectedUpdateAlert.Patch.Uuid;
|
2018-07-06 04:03:40 +02:00
|
|
|
|
}
|
|
|
|
|
else if (FileFromDiskAlert != null)
|
|
|
|
|
{
|
|
|
|
|
applicableHosts = FileFromDiskAlert.DistinctHosts;
|
|
|
|
|
if (FileFromDiskAlert.Patch != null)
|
2016-10-05 13:55:34 +02:00
|
|
|
|
patchUuidFromAlert = FileFromDiskAlert.Patch.Uuid;
|
2018-07-06 04:03:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tooltipText = null;
|
|
|
|
|
if (applicableHosts == null)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (host.Connection.Cache.Hosts.Length == 1 && applicableHosts.Contains(host)) //standalone host
|
|
|
|
|
return true;
|
2015-07-20 15:28:44 +02:00
|
|
|
|
|
2018-07-06 04:03:40 +02:00
|
|
|
|
if (WizardMode == WizardMode.NewVersion)
|
|
|
|
|
{
|
|
|
|
|
if (applicableHosts.Contains(host))
|
2015-07-20 16:27:41 +02:00
|
|
|
|
{
|
2018-07-06 04:03:40 +02:00
|
|
|
|
var nonApplicables = host.Connection.Cache.Hosts.Count(h =>
|
|
|
|
|
!applicableHosts.Contains(h) && !string.IsNullOrEmpty(patchUuidFromAlert) &&
|
|
|
|
|
!isPatchApplied(patchUuidFromAlert, h));
|
|
|
|
|
|
|
|
|
|
if (0 < nonApplicables && nonApplicables < host.Connection.Cache.Hosts.Length)
|
2015-07-20 16:27:41 +02:00
|
|
|
|
{
|
2018-07-06 04:03:40 +02:00
|
|
|
|
tooltipText = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_NEW_VERSION_UPGRADE_SLAVES_FIRST;
|
|
|
|
|
return false;
|
2015-07-20 16:27:41 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-20 15:28:44 +02:00
|
|
|
|
}
|
2018-07-06 04:03:40 +02:00
|
|
|
|
|
|
|
|
|
if (!applicableHosts.Contains(host) && !string.IsNullOrEmpty(patchUuidFromAlert))
|
|
|
|
|
{
|
|
|
|
|
if (isPatchApplied(patchUuidFromAlert, host))
|
|
|
|
|
{
|
|
|
|
|
if (applyUpdatesCheckBox.Checked)
|
|
|
|
|
return CanEnableRowAutomatedUpdates(host, out tooltipText);
|
|
|
|
|
|
|
|
|
|
tooltipText = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_PATCH_ALREADY_APPLIED;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tooltipText = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_PATCH_NOT_APPLICABLE;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
2015-07-20 15:28:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-21 12:03:34 +02:00
|
|
|
|
private bool isPatchApplied(string uuid, Host host)
|
2015-07-20 15:28:44 +02:00
|
|
|
|
{
|
2016-10-04 15:58:54 +02:00
|
|
|
|
if (Helpers.ElyOrGreater(host))
|
2015-07-20 15:28:44 +02:00
|
|
|
|
{
|
2016-10-05 00:26:35 +02:00
|
|
|
|
return host.AppliedUpdates().Any(u => u != null && string.Equals(u.uuid, uuid, StringComparison.InvariantCultureIgnoreCase));
|
2016-10-04 15:58:54 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
List<Pool_patch> hostPatches = host.AppliedPatches();
|
|
|
|
|
foreach (Pool_patch patch in hostPatches)
|
2015-07-20 15:28:44 +02:00
|
|
|
|
{
|
2016-10-04 15:58:54 +02:00
|
|
|
|
if (string.Equals(patch.uuid, uuid, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-07-20 15:28:44 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-09 00:55:50 +01:00
|
|
|
|
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-07-06 02:46:12 +02:00
|
|
|
|
if (direction == PageLoadedDirection.Forward)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-07-06 02:46:12 +02:00
|
|
|
|
if (!AllSelectedHostsConnected())
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-07-06 02:46:12 +02:00
|
|
|
|
foreach (PatchingHostsDataGridViewRow row in dataGridViewHosts.Rows)
|
|
|
|
|
row.UpdateIcon();
|
|
|
|
|
dataGridViewHosts.Invalidate();
|
|
|
|
|
cancel = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-07-06 02:46:12 +02:00
|
|
|
|
//Upload the patches to the masters if it is necessary
|
|
|
|
|
List<Host> masters = SelectedMasters;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-07-06 02:46:12 +02:00
|
|
|
|
//Do RBAC check
|
|
|
|
|
foreach (Host master in masters)
|
|
|
|
|
{
|
|
|
|
|
if (!(Role.CanPerform(new RbacMethodList("pool_patch.apply"), master.Connection)))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-07-06 02:46:12 +02:00
|
|
|
|
string nameLabel = master.Name();
|
|
|
|
|
Pool pool = Helpers.GetPoolOfOne(master.Connection);
|
|
|
|
|
if (pool != null)
|
|
|
|
|
nameLabel = pool.Name();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-07-06 02:46:12 +02:00
|
|
|
|
using (var dlg = new ThreeButtonDialog(new ThreeButtonDialog.Details(SystemIcons.Warning, string.Format(Messages.RBAC_UPDATES_WIZARD, master.Connection.Username, nameLabel), Messages.UPDATES_WIZARD)))
|
|
|
|
|
{
|
|
|
|
|
dlg.ShowDialog(this);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2018-07-06 02:46:12 +02:00
|
|
|
|
|
|
|
|
|
cancel = true;
|
|
|
|
|
return;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool AllSelectedHostsConnected()
|
|
|
|
|
{
|
|
|
|
|
var disconnectedServerNames = new List<string>();
|
|
|
|
|
|
|
|
|
|
foreach (PatchingHostsDataGridViewRow row in dataGridViewHosts.Rows)
|
|
|
|
|
{
|
2017-01-11 12:32:57 +01:00
|
|
|
|
if ((int)row.Cells[POOL_CHECKBOX_COL].Value > UNCHECKED && row.IsPoolOrStandaloneHost)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
IXenConnection connection = ((IXenObject) row.Tag).Connection;
|
|
|
|
|
if (connection == null || !connection.IsConnected)
|
2017-09-03 04:33:29 +02:00
|
|
|
|
disconnectedServerNames.Add(((IXenObject) row.Tag).Name());
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (disconnectedServerNames.Count > 0)
|
|
|
|
|
{
|
2016-06-20 11:49:12 +02:00
|
|
|
|
using (var dlg = new ThreeButtonDialog(
|
2013-06-24 13:41:48 +02:00
|
|
|
|
new ThreeButtonDialog.Details(SystemIcons.Warning,
|
|
|
|
|
string.Format(Messages.UPDATES_WIZARD_DISCONNECTED_SERVER, Helpers.StringifyList(disconnectedServerNames)),
|
2016-06-20 11:49:12 +02:00
|
|
|
|
Messages.UPDATES_WIZARD)))
|
|
|
|
|
{
|
|
|
|
|
dlg.ShowDialog(this);
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool EnableNext()
|
|
|
|
|
{
|
|
|
|
|
bool clearAllButtonEnabled = false;
|
|
|
|
|
bool selectAllButtonEnabled = false;
|
|
|
|
|
|
|
|
|
|
foreach (PatchingHostsDataGridViewRow row in dataGridViewHosts.Rows)
|
|
|
|
|
{
|
2017-01-11 12:32:57 +01:00
|
|
|
|
if (row.IsPoolOrStandaloneHost && row.Enabled)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
int val = (int)row.Cells[POOL_CHECKBOX_COL].Value;
|
|
|
|
|
if (val > UNCHECKED)
|
|
|
|
|
{
|
|
|
|
|
clearAllButtonEnabled = true;
|
|
|
|
|
if (val == INDETERMINATE)
|
|
|
|
|
selectAllButtonEnabled = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
selectAllButtonEnabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buttonClearAll.Enabled = clearAllButtonEnabled;
|
|
|
|
|
buttonSelectAll.Enabled = selectAllButtonEnabled;
|
|
|
|
|
return clearAllButtonEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Accessors
|
|
|
|
|
|
2015-01-09 13:54:12 +01:00
|
|
|
|
public Pool_patch Patch { private get; set; }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
public List<Host> SelectedMasters
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
List<Host> result = new List<Host>();
|
|
|
|
|
foreach (Host selectedServer in SelectedServers)
|
|
|
|
|
{
|
|
|
|
|
Host master = Helpers.GetMaster(selectedServer.Connection);
|
|
|
|
|
if (!result.Contains(master))
|
|
|
|
|
result.Add(master);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Host> SelectedServers
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-01-11 12:32:57 +01:00
|
|
|
|
if (poolSelectionOnly)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-06-22 12:38:38 +02:00
|
|
|
|
var enabledHosts = new List<Host>();
|
|
|
|
|
foreach (PatchingHostsDataGridViewRow row in dataGridViewHosts.Rows)
|
|
|
|
|
{
|
|
|
|
|
if (row.IsAHostRow && row.Enabled)
|
|
|
|
|
enabledHosts.Add((Host)row.Tag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (WizardMode != WizardMode.SingleUpdate)
|
2017-01-24 18:41:35 +01:00
|
|
|
|
//prechecks will fail in automated updates mode if one of the hosts is unreachable
|
2018-08-20 16:46:58 +02:00
|
|
|
|
return SelectedPools.SelectMany(p => p.Connection.Cache.Hosts.Where(host => enabledHosts.Contains(host)).OrderBy(host => host)).ToList();
|
2017-01-24 18:41:35 +01:00
|
|
|
|
//prechecks will issue warning but allow updates to be installed on the reachable hosts only
|
2018-08-20 16:46:58 +02:00
|
|
|
|
return SelectedPools.SelectMany(p => p.Connection.Cache.Hosts.Where(host => host.IsLive() && enabledHosts.Contains(host)).OrderBy(host => host)).ToList();
|
2016-08-08 19:05:42 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
List<Host> hosts = new List<Host>();
|
|
|
|
|
foreach (PatchingHostsDataGridViewRow row in dataGridViewHosts.Rows)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-01-24 18:41:35 +01:00
|
|
|
|
if (row.IsSelectableHost)
|
2016-08-08 19:05:42 +02:00
|
|
|
|
{
|
|
|
|
|
if ((row.HasPool && ((int)row.Cells[POOL_ICON_HOST_CHECKBOX_COL].Value) == CHECKED) || (!row.HasPool && ((int)row.Cells[POOL_CHECKBOX_COL].Value) == CHECKED))
|
|
|
|
|
hosts.Add((Host)row.Tag);
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2016-08-08 19:05:42 +02:00
|
|
|
|
return hosts;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Pool> SelectedPools
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
List<Pool> pools = new List<Pool>();
|
|
|
|
|
foreach (PatchingHostsDataGridViewRow row in dataGridViewHosts.Rows)
|
|
|
|
|
{
|
|
|
|
|
if (row.Tag is Pool)
|
|
|
|
|
{
|
2017-09-05 19:38:20 +02:00
|
|
|
|
if (((int)row.Cells[POOL_CHECKBOX_COL].Value) != UNCHECKED && !pools.Contains((Pool)row.Tag))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
pools.Add((Pool)row.Tag);
|
|
|
|
|
}
|
|
|
|
|
else if (row.Tag is Host)
|
|
|
|
|
{
|
|
|
|
|
if (((int)row.Cells[POOL_CHECKBOX_COL].Value) != UNCHECKED)
|
|
|
|
|
{
|
|
|
|
|
Host host = (Host)row.Tag;
|
|
|
|
|
Pool pool = Helpers.GetPoolOfOne(host.Connection);
|
2017-09-05 19:38:20 +02:00
|
|
|
|
if (pool != null && !pools.Contains(pool))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
pools.Add(pool);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return pools;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-27 17:12:49 +02:00
|
|
|
|
public bool ApplyUpdatesToNewVersion
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return applyUpdatesCheckBox.Visible && applyUpdatesCheckBox.Checked;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
public UpdateType SelectedUpdateType { private get; set; }
|
|
|
|
|
|
|
|
|
|
public void SelectServers(List<Host> selectedServers)
|
|
|
|
|
{
|
|
|
|
|
if (selectedServers.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (PatchingHostsDataGridViewRow row in dataGridViewHosts.Rows)
|
|
|
|
|
{
|
2017-01-11 12:32:57 +01:00
|
|
|
|
if (row.IsSelectableHost)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
var host = (Host) row.Tag;
|
|
|
|
|
if (selectedServers.Contains(host))
|
|
|
|
|
dataGridViewHosts.CheckBoxChange(row.Index,
|
|
|
|
|
Helpers.GetPool(host.Connection) != null
|
|
|
|
|
? POOL_ICON_HOST_CHECKBOX_COL
|
|
|
|
|
: POOL_CHECKBOX_COL);
|
|
|
|
|
}
|
2017-01-11 12:32:57 +01:00
|
|
|
|
else if (poolSelectionOnly && row.IsSelectablePool)
|
|
|
|
|
{
|
|
|
|
|
// select the pools of the selected servers
|
|
|
|
|
var pool = (Pool) row.Tag;;
|
|
|
|
|
foreach (var host in pool.Connection.Cache.Hosts)
|
|
|
|
|
{
|
|
|
|
|
if (selectedServers.Contains(host))
|
2017-10-04 17:48:58 +02:00
|
|
|
|
{
|
2017-01-11 12:32:57 +01:00
|
|
|
|
dataGridViewHosts.CheckBoxChange(row.Index, POOL_CHECKBOX_COL);
|
2017-10-04 17:48:58 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
2017-01-11 12:32:57 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-07 13:52:14 +02:00
|
|
|
|
public void DisableUnselectedServers()
|
|
|
|
|
{
|
|
|
|
|
foreach (PatchingHostsDataGridViewRow row in dataGridViewHosts.Rows)
|
|
|
|
|
{
|
|
|
|
|
if (row.Enabled && row.CheckValue == UNCHECKED)
|
|
|
|
|
{
|
|
|
|
|
row.Enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
private void buttonSelectAll_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CheckAllCheckBoxes(CHECKED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckAllCheckBoxes(int value)
|
|
|
|
|
{
|
|
|
|
|
foreach (PatchingHostsDataGridViewRow row in dataGridViewHosts.Rows)
|
|
|
|
|
{
|
2017-01-11 12:32:57 +01:00
|
|
|
|
if (row.IsSelectableHost)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
if (row.HasPool && (int)row.Cells[POOL_ICON_HOST_CHECKBOX_COL].Value != value)
|
|
|
|
|
dataGridViewHosts.CheckBoxChange(row.Index, POOL_ICON_HOST_CHECKBOX_COL);
|
|
|
|
|
else if ((int)row.Cells[POOL_CHECKBOX_COL].Value != value)
|
|
|
|
|
dataGridViewHosts.CheckBoxChange(row.Index, POOL_CHECKBOX_COL);
|
|
|
|
|
}
|
2017-01-11 12:32:57 +01:00
|
|
|
|
else if (row.IsSelectablePool && (int)row.Cells[POOL_CHECKBOX_COL].Value != value)
|
2016-07-01 18:41:49 +02:00
|
|
|
|
{
|
|
|
|
|
dataGridViewHosts.CheckBoxChange(row.Index, POOL_CHECKBOX_COL);
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonClearAll_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CheckAllCheckBoxes(UNCHECKED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void dataGridViewHosts_CheckBoxClicked(object sender, EventArgs e)
|
|
|
|
|
{
|
2018-07-06 04:03:40 +02:00
|
|
|
|
OnPageUpdated();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void applyUpdatesCheckBox_CheckedChanged(object sender, System.EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
PatchingHostsDataGridViewRow masterRow = null;
|
|
|
|
|
|
2017-02-27 17:14:42 +01:00
|
|
|
|
foreach (PatchingHostsDataGridViewRow row in dataGridViewHosts.Rows)
|
|
|
|
|
{
|
2018-06-18 11:46:41 +02:00
|
|
|
|
var host = row.Tag as Host;
|
2017-02-27 17:14:42 +01:00
|
|
|
|
if (host != null)
|
2018-07-06 04:03:40 +02:00
|
|
|
|
{
|
|
|
|
|
string tooltipText;
|
|
|
|
|
row.Enabled = CanEnableRow(host, out tooltipText);
|
|
|
|
|
row.Cells[3].ToolTipText = tooltipText;
|
|
|
|
|
|
|
|
|
|
if (row.ParentPoolRow != null)
|
|
|
|
|
{
|
|
|
|
|
if (row.Enabled)
|
|
|
|
|
{
|
|
|
|
|
row.ParentPoolRow.Enabled = true;
|
|
|
|
|
row.ParentPoolRow.Cells[3].ToolTipText = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (masterRow == null)
|
|
|
|
|
{
|
|
|
|
|
masterRow = row;
|
|
|
|
|
if (!row.Enabled)
|
|
|
|
|
row.ParentPoolRow.Cells[3].ToolTipText = row.Cells[3].ToolTipText;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-18 11:46:41 +02:00
|
|
|
|
else
|
2018-07-06 04:03:40 +02:00
|
|
|
|
{
|
|
|
|
|
row.Enabled = false;
|
|
|
|
|
masterRow = null;//reset the stored masterRow
|
|
|
|
|
}
|
2017-02-27 17:14:42 +01:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Nested items
|
|
|
|
|
|
|
|
|
|
private class PatchingHostsDataGridView : CollapsingPoolHostDataGridView
|
|
|
|
|
{
|
|
|
|
|
protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnCellPainting(e);
|
|
|
|
|
|
|
|
|
|
if (e.RowIndex >= 0 && Rows[e.RowIndex].Tag is Host)
|
|
|
|
|
{
|
|
|
|
|
PatchingHostsDataGridViewRow row = (PatchingHostsDataGridViewRow)Rows[e.RowIndex];
|
|
|
|
|
if (row.HasPool && (e.ColumnIndex == POOL_CHECKBOX_COL || e.ColumnIndex == PLUS_MINUS_COL))
|
|
|
|
|
{
|
|
|
|
|
e.PaintBackground(e.ClipBounds, true);
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
else if (!row.HasPool && e.ColumnIndex == PLUS_MINUS_COL)
|
|
|
|
|
{
|
|
|
|
|
e.PaintBackground(e.ClipBounds, true);
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
2017-01-11 12:32:57 +01:00
|
|
|
|
else if (row.HasPool && !row.IsSelectableHost && e.ColumnIndex == POOL_ICON_HOST_CHECKBOX_COL)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
e.PaintBackground(e.ClipBounds, true);
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
else if (!row.HasPool && !row.Enabled && e.ColumnIndex == POOL_CHECKBOX_COL)
|
|
|
|
|
{
|
|
|
|
|
e.PaintBackground(e.ClipBounds, true);
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e.RowIndex >= 0 && Rows[e.RowIndex].Tag is Pool)
|
|
|
|
|
{
|
|
|
|
|
PatchingHostsDataGridViewRow row = (PatchingHostsDataGridViewRow)Rows[e.RowIndex];
|
|
|
|
|
if (!row.Enabled && e.ColumnIndex == POOL_CHECKBOX_COL)
|
|
|
|
|
{
|
|
|
|
|
e.PaintBackground(e.ClipBounds, true);
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void CheckBoxChange(int RowIndex, int ColumnIndex)
|
|
|
|
|
{
|
|
|
|
|
if (RowIndex >= 0 && !((PatchingHostsDataGridViewRow)Rows[RowIndex]).Enabled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (RowIndex >= 0 && Rows[RowIndex].Tag is Host)
|
|
|
|
|
{
|
|
|
|
|
if (ColumnIndex == POOL_ICON_HOST_CHECKBOX_COL && Rows[RowIndex].Cells[ColumnIndex].Value is int) //Checkbox
|
|
|
|
|
{
|
|
|
|
|
int hostNewValue = ClickCheckBox(RowIndex, ColumnIndex);
|
|
|
|
|
|
|
|
|
|
PatchingHostsDataGridViewRow poolRow = FindPoolRow(RowIndex);
|
|
|
|
|
bool allHostSameValue = true;
|
|
|
|
|
bool atLeastOneHostChecked = false;
|
|
|
|
|
for (int i = poolRow.Index + 1; i < Rows.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (Rows[i].Tag is Host &&
|
|
|
|
|
((PatchingHostsDataGridViewRow)Rows[i]).HasPool)
|
|
|
|
|
{
|
|
|
|
|
if (((int)Rows[i].Cells[POOL_ICON_HOST_CHECKBOX_COL].Value) == CHECKED)
|
|
|
|
|
{
|
|
|
|
|
atLeastOneHostChecked = true;
|
|
|
|
|
}
|
|
|
|
|
if (((PatchingHostsDataGridViewRow)Rows[i]).Enabled && ((int)Rows[i].Cells[POOL_ICON_HOST_CHECKBOX_COL].Value) != hostNewValue)
|
|
|
|
|
{
|
|
|
|
|
allHostSameValue = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (allHostSameValue)
|
|
|
|
|
{
|
|
|
|
|
poolRow.Cells[POOL_CHECKBOX_COL].Value = hostNewValue;
|
|
|
|
|
}
|
|
|
|
|
else if (atLeastOneHostChecked)
|
|
|
|
|
{
|
|
|
|
|
poolRow.Cells[POOL_CHECKBOX_COL].Value = INDETERMINATE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ColumnIndex == POOL_CHECKBOX_COL)
|
|
|
|
|
{
|
|
|
|
|
ClickCheckBox(RowIndex, ColumnIndex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (RowIndex >= 0 && Rows[RowIndex].Tag is Pool)
|
|
|
|
|
{
|
|
|
|
|
if (ColumnIndex == POOL_CHECKBOX_COL)
|
|
|
|
|
{
|
|
|
|
|
ClickCheckBox(RowIndex, ColumnIndex);
|
|
|
|
|
for (int i = RowIndex + 1; i < Rows.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (Rows[i].Tag is Host && ((PatchingHostsDataGridViewRow)Rows[i]).HasPool)
|
|
|
|
|
{
|
|
|
|
|
var value = (int)Rows[RowIndex].Cells[ColumnIndex].Value;
|
|
|
|
|
|
|
|
|
|
if (value == UNCHECKED || value == CHECKED)
|
|
|
|
|
Rows[i].Cells[POOL_ICON_HOST_CHECKBOX_COL].Value = value;
|
|
|
|
|
}
|
|
|
|
|
else break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
OnCheckBoxClicked();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private PatchingHostsDataGridViewRow FindPoolRow(int rowIndex)
|
|
|
|
|
{
|
|
|
|
|
for (int i = rowIndex; i >= 0; i--)
|
|
|
|
|
{
|
|
|
|
|
if (Rows[i].Tag is Pool)
|
|
|
|
|
return (PatchingHostsDataGridViewRow)Rows[i];
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int ClickCheckBox(int rowIndex, int columnIndex)
|
|
|
|
|
{
|
|
|
|
|
int value = (int)Rows[rowIndex].Cells[columnIndex].Value;
|
|
|
|
|
if (value == CHECKED)
|
|
|
|
|
{
|
|
|
|
|
Rows[rowIndex].Cells[columnIndex].Value = UNCHECKED;
|
|
|
|
|
return UNCHECKED;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Rows[rowIndex].Cells[columnIndex].Value = CHECKED;
|
|
|
|
|
return CHECKED;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-14 18:01:43 +02:00
|
|
|
|
|
2017-08-16 12:46:00 +02:00
|
|
|
|
protected override void SortColumns()
|
2017-08-14 18:01:43 +02:00
|
|
|
|
{
|
|
|
|
|
PatchingHostsDataGridViewRow firstRow = Rows[0] as PatchingHostsDataGridViewRow;
|
|
|
|
|
if (firstRow == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-08-16 12:46:00 +02:00
|
|
|
|
if (columnToBeSortedIndex == firstRow.NameCellIndex ||
|
|
|
|
|
columnToBeSortedIndex == firstRow.VersionCellIndex)
|
|
|
|
|
SortAndRebuildTree(new CollapsingPoolHostRowSorter<PatchingHostsDataGridViewRow>(direction, columnToBeSortedIndex));
|
2017-08-14 18:01:43 +02:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class PatchingHostsDataGridViewRow : CollapsingPoolHostDataGridViewRow
|
|
|
|
|
{
|
2017-08-08 13:25:18 +02:00
|
|
|
|
private class DataGridViewNameCell : DataGridViewTextBoxCell
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
Pool pool = value as Pool;
|
|
|
|
|
|
|
|
|
|
if (pool != null)
|
|
|
|
|
base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Host host = value as Host;
|
|
|
|
|
if (host != null)
|
|
|
|
|
{
|
|
|
|
|
PatchingHostsDataGridViewRow row = (PatchingHostsDataGridViewRow)this.DataGridView.Rows[this.RowIndex];
|
|
|
|
|
if (row.HasPool)
|
|
|
|
|
{
|
|
|
|
|
Image hostIcon = Images.GetImage16For(host);
|
|
|
|
|
base.Paint(graphics, clipBounds,
|
|
|
|
|
new Rectangle(cellBounds.X + 16, cellBounds.Y, cellBounds.Width - 16,
|
|
|
|
|
cellBounds.Height), rowIndex, cellState, value, formattedValue,
|
|
|
|
|
errorText, cellStyle, advancedBorderStyle, paintParts);
|
|
|
|
|
|
|
|
|
|
if ((cellState & DataGridViewElementStates.Selected) != 0 && row.Enabled)
|
|
|
|
|
{
|
2013-08-16 18:43:57 +02:00
|
|
|
|
using (var brush = new SolidBrush(DataGridView.DefaultCellStyle.SelectionBackColor))
|
|
|
|
|
graphics.FillRectangle(
|
|
|
|
|
brush, cellBounds.X,
|
|
|
|
|
cellBounds.Y, hostIcon.Width, cellBounds.Height);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-08-16 18:43:57 +02:00
|
|
|
|
using (var brush = new SolidBrush(DataGridView.DefaultCellStyle.BackColor))
|
|
|
|
|
graphics.FillRectangle(brush,
|
|
|
|
|
cellBounds.X, cellBounds.Y, hostIcon.Width, cellBounds.Height);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (row.Enabled)
|
|
|
|
|
graphics.DrawImage(hostIcon, cellBounds.X, cellBounds.Y + 3, hostIcon.Width,
|
|
|
|
|
hostIcon.Height);
|
|
|
|
|
else
|
|
|
|
|
graphics.DrawImage(hostIcon,
|
|
|
|
|
new Rectangle(cellBounds.X, cellBounds.Y + 3,
|
|
|
|
|
hostIcon.Width, hostIcon.Height),
|
|
|
|
|
0, 0, hostIcon.Width, hostIcon.Height, GraphicsUnit.Pixel,
|
|
|
|
|
Drawing.GreyScaleAttributes);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue,
|
|
|
|
|
errorText, cellStyle, advancedBorderStyle, paintParts);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class DataGridViewIconCell : DataGridViewImageCell
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
Image icon = value as Image;
|
|
|
|
|
if (icon == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
PatchingHostsDataGridViewRow row = (PatchingHostsDataGridViewRow)DataGridView.Rows[RowIndex];
|
|
|
|
|
if ((cellState & DataGridViewElementStates.Selected) != 0 && row.Enabled)
|
|
|
|
|
{
|
2013-08-16 18:43:57 +02:00
|
|
|
|
using (var brush = new SolidBrush(DataGridView.DefaultCellStyle.SelectionBackColor))
|
|
|
|
|
graphics.FillRectangle(
|
|
|
|
|
brush, cellBounds.X,
|
|
|
|
|
cellBounds.Y, cellBounds.Width, cellBounds.Height);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-08-16 18:43:57 +02:00
|
|
|
|
using (var brush = new SolidBrush(DataGridView.DefaultCellStyle.BackColor))
|
|
|
|
|
graphics.FillRectangle(brush, cellBounds.X,
|
|
|
|
|
cellBounds.Y, cellBounds.Width, cellBounds.Height);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (row.Enabled)
|
|
|
|
|
graphics.DrawImage(icon, cellBounds.X, cellBounds.Y + 3, icon.Width, icon.Height);
|
|
|
|
|
else
|
|
|
|
|
graphics.DrawImage(icon, new Rectangle(cellBounds.X, cellBounds.Y + 3, icon.Width, icon.Height),
|
|
|
|
|
0, 0, icon.Width, icon.Height, GraphicsUnit.Pixel,
|
|
|
|
|
Drawing.GreyScaleAttributes);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private DataGridViewCell _poolIconHostCheckCell;
|
|
|
|
|
private DataGridViewTextBoxCell _versionCell;
|
|
|
|
|
|
2017-01-11 12:32:57 +01:00
|
|
|
|
private readonly bool _showHostCheckBox = true;
|
|
|
|
|
|
2016-07-05 12:00:40 +02:00
|
|
|
|
public PatchingHostsDataGridViewRow(Pool pool)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
: base(pool)
|
|
|
|
|
{
|
|
|
|
|
SetupCells();
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-11 12:32:57 +01:00
|
|
|
|
public PatchingHostsDataGridViewRow(Host host, bool hasPool, bool showHostCheckBox = true)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
: base(host, hasPool)
|
|
|
|
|
{
|
2017-01-11 12:32:57 +01:00
|
|
|
|
_showHostCheckBox = showHostCheckBox;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
SetupCells();
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-14 18:01:43 +02:00
|
|
|
|
public int VersionCellIndex
|
|
|
|
|
{
|
|
|
|
|
get { return Cells.IndexOf(_versionCell); }
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
public override bool IsCheckable
|
|
|
|
|
{
|
|
|
|
|
get { return !HasPool; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Enabled
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return base.Enabled;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
base.Enabled = value;
|
|
|
|
|
UpdateDetails();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-07 13:52:14 +02:00
|
|
|
|
public int CheckValue
|
|
|
|
|
{
|
|
|
|
|
get {
|
2017-01-11 12:32:57 +01:00
|
|
|
|
return IsPoolOrStandaloneHost
|
2014-08-07 13:52:14 +02:00
|
|
|
|
? (int) Cells[POOL_CHECKBOX_COL].Value
|
|
|
|
|
: (int) Cells[POOL_ICON_HOST_CHECKBOX_COL].Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-11 12:32:57 +01:00
|
|
|
|
public bool IsSelectableHost
|
|
|
|
|
{
|
|
|
|
|
get { return IsAHostRow && Enabled && (_showHostCheckBox || !HasPool); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsSelectablePool
|
|
|
|
|
{
|
|
|
|
|
get { return IsAPoolRow && Enabled; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private void SetupCells()
|
|
|
|
|
{
|
|
|
|
|
_poolCheckBoxCell = new DataGridViewCheckBoxCell { ThreeState = true };
|
|
|
|
|
|
|
|
|
|
_expansionCell = new DataGridViewImageCell();
|
|
|
|
|
|
2017-01-11 12:32:57 +01:00
|
|
|
|
if (IsPoolOrStandaloneHost)
|
|
|
|
|
_poolIconHostCheckCell = new DataGridViewIconCell();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
else
|
|
|
|
|
_poolIconHostCheckCell = new DataGridViewCheckBoxCell();
|
|
|
|
|
|
|
|
|
|
_nameCell = new DataGridViewNameCell();
|
|
|
|
|
_versionCell = new DataGridViewTextBoxCell();
|
|
|
|
|
|
2018-07-06 04:03:40 +02:00
|
|
|
|
Cells.AddRange(_expansionCell, _poolCheckBoxCell, _poolIconHostCheckCell, _nameCell, _versionCell);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
this.UpdateDetails();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateDetails()
|
|
|
|
|
{
|
2018-07-06 04:03:40 +02:00
|
|
|
|
var pool = Tag as Pool;
|
|
|
|
|
if (pool != null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
Host master = pool.Connection.Resolve(pool.master);
|
2018-07-06 04:03:40 +02:00
|
|
|
|
if (_poolCheckBoxCell.Value == null)
|
|
|
|
|
_poolCheckBoxCell.Value = CheckState.Unchecked;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
_expansionCell.Value = Resources.tree_minus;
|
|
|
|
|
_poolIconHostCheckCell.Value = Images.GetImage16For(pool);
|
|
|
|
|
_nameCell.Value = pool;
|
2017-09-03 04:33:29 +02:00
|
|
|
|
_versionCell.Value = master.ProductVersionTextShort();
|
2018-07-06 04:03:40 +02:00
|
|
|
|
return;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2018-07-06 04:03:40 +02:00
|
|
|
|
|
|
|
|
|
var host = Tag as Host;
|
|
|
|
|
if (host != null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-07-06 04:03:40 +02:00
|
|
|
|
if (_poolCheckBoxCell.Value == null)
|
|
|
|
|
_poolCheckBoxCell.Value = CheckState.Unchecked;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
_expansionCell.Value = Resources.tree_plus;
|
|
|
|
|
if (_hasPool)
|
2018-07-06 04:03:40 +02:00
|
|
|
|
{
|
|
|
|
|
if (_poolIconHostCheckCell.Value == null)
|
|
|
|
|
_poolIconHostCheckCell.Value = CheckState.Unchecked;
|
|
|
|
|
}
|
|
|
|
|
else
|
2013-06-24 13:41:48 +02:00
|
|
|
|
_poolIconHostCheckCell.Value = Images.GetImage16For(host);
|
|
|
|
|
_nameCell.Value = host;
|
2017-09-03 04:33:29 +02:00
|
|
|
|
_versionCell.Value = host.ProductVersionTextShort();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void UpdateIcon()
|
|
|
|
|
{
|
|
|
|
|
if (_poolIconHostCheckCell is DataGridViewImageCell)
|
|
|
|
|
{
|
|
|
|
|
_poolIconHostCheckCell.Value = Images.GetImage16For((IXenObject)Tag);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-06 04:03:40 +02:00
|
|
|
|
|
|
|
|
|
public PatchingHostsDataGridViewRow ParentPoolRow { get; set; }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|