2023-01-24 15:29:31 +01:00
|
|
|
|
/* Copyright (c) Cloud Software Group, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
*
|
|
|
|
|
* 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;
|
2013-12-05 13:46:39 +01:00
|
|
|
|
using System.ComponentModel;
|
2020-07-26 15:54:52 +02:00
|
|
|
|
using System.Diagnostics;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using XenAdmin.Actions;
|
|
|
|
|
using XenAdmin.Alerts;
|
2019-08-21 12:43:11 +02:00
|
|
|
|
using XenAdmin.Alerts.Types;
|
2020-07-26 15:54:52 +02:00
|
|
|
|
using XenAdmin.Network;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Core
|
|
|
|
|
{
|
|
|
|
|
public class Updates
|
|
|
|
|
{
|
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
2022-06-16 12:11:56 +02:00
|
|
|
|
public static event Action CheckForUpdatesCompleted;
|
2013-12-05 13:46:39 +01:00
|
|
|
|
public static event Action CheckForUpdatesStarted;
|
2020-07-26 15:54:52 +02:00
|
|
|
|
public static event Action<CollectionChangeEventArgs> UpdateAlertCollectionChanged;
|
2013-11-21 15:27:34 +01:00
|
|
|
|
|
2014-01-08 14:17:02 +01:00
|
|
|
|
private static readonly object downloadedUpdatesLock = new object();
|
2015-08-04 18:28:29 +02:00
|
|
|
|
private static List<XenServerVersion> XenServerVersionsForAutoCheck = new List<XenServerVersion>();
|
2013-12-05 13:46:39 +01:00
|
|
|
|
private static List<XenServerPatch> XenServerPatches = new List<XenServerPatch>();
|
2021-06-04 17:35:52 +02:00
|
|
|
|
private static List<ClientVersion> ClientVersions = new List<ClientVersion>();
|
2016-06-29 13:49:53 +02:00
|
|
|
|
public static List<XenServerVersion> XenServerVersions = new List<XenServerVersion>();
|
2013-12-05 13:46:39 +01:00
|
|
|
|
|
|
|
|
|
private static readonly object updateAlertsLock = new object();
|
2020-07-26 15:54:52 +02:00
|
|
|
|
private static readonly List<Alert> updateAlerts = new List<Alert>();
|
2013-12-05 13:46:39 +01:00
|
|
|
|
|
2015-07-29 14:43:47 +02:00
|
|
|
|
/// <summary>
|
2020-07-26 15:54:52 +02:00
|
|
|
|
/// Locks and creates a new list of the update alerts
|
2015-07-29 14:43:47 +02:00
|
|
|
|
/// </summary>
|
2020-07-26 15:54:52 +02:00
|
|
|
|
public static List<Alert> UpdateAlerts
|
2015-07-29 14:43:47 +02:00
|
|
|
|
{
|
2020-07-26 15:54:52 +02:00
|
|
|
|
get
|
2015-07-29 14:43:47 +02:00
|
|
|
|
{
|
2020-07-26 15:54:52 +02:00
|
|
|
|
lock (updateAlertsLock)
|
|
|
|
|
return updateAlerts.ToList();
|
2015-07-29 14:43:47 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-26 15:54:52 +02:00
|
|
|
|
public static void RemoveUpdate(Alert update)
|
2013-12-05 13:46:39 +01:00
|
|
|
|
{
|
|
|
|
|
lock (updateAlertsLock)
|
2020-07-26 15:54:52 +02:00
|
|
|
|
updateAlerts.Remove(update);
|
2013-11-21 15:27:34 +01:00
|
|
|
|
|
2020-07-26 15:54:52 +02:00
|
|
|
|
UpdateAlertCollectionChanged?.Invoke(new CollectionChangeEventArgs(CollectionChangeAction.Remove, update));
|
|
|
|
|
}
|
2014-01-08 14:17:02 +01:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// If AutomaticCheck is enabled it checks for updates regardless the
|
2022-06-20 14:55:42 +02:00
|
|
|
|
/// value of the parameter userRequested. If AutomaticCheck is disabled it checks
|
|
|
|
|
/// for all update types if userRequested is true.
|
2014-01-08 14:17:02 +01:00
|
|
|
|
/// </summary>
|
2022-06-20 14:55:42 +02:00
|
|
|
|
public static void CheckForUpdates(bool userRequested = false)
|
2014-01-08 14:17:02 +01:00
|
|
|
|
{
|
|
|
|
|
if (Helpers.CommonCriteriaCertificationRelease)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-06-20 14:55:42 +02:00
|
|
|
|
if (Properties.Settings.Default.AllowXenCenterUpdates || userRequested)
|
2014-01-08 14:17:02 +01:00
|
|
|
|
{
|
2023-01-14 05:29:04 +01:00
|
|
|
|
string userAgent = $"{BrandManager.BrandConsole}/{Program.Version} ({IntPtr.Size * 8}-bit)";
|
2016-08-08 15:37:47 +02:00
|
|
|
|
|
2022-06-20 14:55:42 +02:00
|
|
|
|
var action = new DownloadUpdatesXmlAction(Properties.Settings.Default.AllowXenCenterUpdates || userRequested,
|
|
|
|
|
false, false, userAgent, !userRequested);
|
2016-08-08 15:37:47 +02:00
|
|
|
|
action.Completed += actionCompleted;
|
2014-01-08 14:17:02 +01:00
|
|
|
|
|
2022-06-16 12:11:56 +02:00
|
|
|
|
CheckForUpdatesStarted?.Invoke();
|
2014-01-08 14:17:02 +01:00
|
|
|
|
|
|
|
|
|
action.RunAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-07 17:02:43 +02:00
|
|
|
|
|
2013-11-21 15:27:34 +01:00
|
|
|
|
private static void actionCompleted(ActionBase sender)
|
|
|
|
|
{
|
|
|
|
|
Program.AssertOffEventThread();
|
2013-12-05 13:46:39 +01:00
|
|
|
|
|
2020-07-26 15:54:52 +02:00
|
|
|
|
if (!(sender is DownloadUpdatesXmlAction action))
|
2013-12-05 13:46:39 +01:00
|
|
|
|
return;
|
2013-11-21 15:27:34 +01:00
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
bool succeeded = action.Succeeded;
|
2013-11-21 15:27:34 +01:00
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
if (succeeded)
|
|
|
|
|
{
|
2014-01-08 14:17:02 +01:00
|
|
|
|
lock (downloadedUpdatesLock)
|
|
|
|
|
{
|
2021-06-04 17:35:52 +02:00
|
|
|
|
ClientVersions = action.ClientVersions;
|
2017-01-19 18:51:25 +01:00
|
|
|
|
XenServerVersionsForAutoCheck = action.XenServerVersionsForAutoCheck;
|
|
|
|
|
XenServerVersions = action.XenServerVersions;
|
|
|
|
|
XenServerPatches = action.XenServerPatches;
|
2014-01-08 14:17:02 +01:00
|
|
|
|
}
|
2013-12-05 13:46:39 +01:00
|
|
|
|
}
|
2013-11-21 15:27:34 +01:00
|
|
|
|
|
2020-07-26 15:54:52 +02:00
|
|
|
|
lock (updateAlertsLock)
|
|
|
|
|
{
|
|
|
|
|
updateAlerts.Clear();
|
2013-11-21 15:27:34 +01:00
|
|
|
|
|
2020-07-26 15:54:52 +02:00
|
|
|
|
if (succeeded)
|
|
|
|
|
{
|
2021-06-04 17:35:52 +02:00
|
|
|
|
var clientUpdateAlerts = NewClientUpdateAlerts(ClientVersions, Program.Version);
|
|
|
|
|
updateAlerts.AddRange(clientUpdateAlerts.Where(a => !a.IsDismissed()));
|
2014-01-08 14:17:02 +01:00
|
|
|
|
|
2020-07-26 15:54:52 +02:00
|
|
|
|
var xenServerUpdateAlerts = NewXenServerVersionAlerts(XenServerVersionsForAutoCheck);
|
|
|
|
|
updateAlerts.AddRange(xenServerUpdateAlerts.Where(a => !a.CanIgnore));
|
2013-12-05 13:46:39 +01:00
|
|
|
|
|
2020-07-26 15:54:52 +02:00
|
|
|
|
var xenServerPatchAlerts = NewXenServerPatchAlerts(XenServerVersions, XenServerPatches);
|
|
|
|
|
updateAlerts.AddRange(xenServerPatchAlerts.Where(a => !a.CanIgnore));
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-05 13:46:39 +01:00
|
|
|
|
|
2020-07-26 15:54:52 +02:00
|
|
|
|
UpdateAlertCollectionChanged?.Invoke(new CollectionChangeEventArgs(CollectionChangeAction.Refresh, UpdateAlerts));
|
|
|
|
|
|
2022-06-16 12:11:56 +02:00
|
|
|
|
CheckForUpdatesCompleted?.Invoke();
|
2020-07-26 15:54:52 +02:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-06-04 17:35:52 +02:00
|
|
|
|
public static List<ClientUpdateAlert> NewClientUpdateAlerts(List<ClientVersion> clientVersions,
|
2017-03-14 16:25:49 +01:00
|
|
|
|
Version currentProgramVersion)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
if (Helpers.CommonCriteriaCertificationRelease)
|
2021-06-04 17:35:52 +02:00
|
|
|
|
return new List<ClientUpdateAlert>();
|
2020-07-26 15:54:52 +02:00
|
|
|
|
|
2021-06-04 17:35:52 +02:00
|
|
|
|
var alerts = new List<ClientUpdateAlert>();
|
|
|
|
|
ClientVersion latest = null, latestCr = null;
|
2020-07-26 15:54:52 +02:00
|
|
|
|
|
2021-06-04 17:35:52 +02:00
|
|
|
|
if (clientVersions.Count != 0 && currentProgramVersion != new Version(0, 0, 0, 0))
|
2014-01-08 14:17:02 +01:00
|
|
|
|
{
|
2021-06-04 17:35:52 +02:00
|
|
|
|
var latestVersions = from v in clientVersions where v.Latest select v;
|
2017-03-14 16:25:49 +01:00
|
|
|
|
latest = latestVersions.FirstOrDefault(xcv => xcv.Lang == Program.CurrentLanguage) ??
|
|
|
|
|
latestVersions.FirstOrDefault(xcv => string.IsNullOrEmpty(xcv.Lang));
|
2014-01-08 14:17:02 +01:00
|
|
|
|
|
2021-06-04 17:35:52 +02:00
|
|
|
|
if (IsSuitableForClientUpdateAlert(latest, currentProgramVersion))
|
|
|
|
|
alerts.Add(new ClientUpdateAlert(latest));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-06-04 17:35:52 +02:00
|
|
|
|
var latestCrVersions = from v in clientVersions where v.LatestCr select v;
|
2017-03-14 16:25:49 +01:00
|
|
|
|
latestCr = latestCrVersions.FirstOrDefault(xcv => xcv.Lang == Program.CurrentLanguage) ??
|
|
|
|
|
latestCrVersions.FirstOrDefault(xcv => string.IsNullOrEmpty(xcv.Lang));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-06-04 17:35:52 +02:00
|
|
|
|
if (latestCr != latest && IsSuitableForClientUpdateAlert(latestCr, currentProgramVersion))
|
|
|
|
|
alerts.Add(new ClientUpdateAlert(latestCr));
|
2017-03-14 16:25:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (alerts.Count == 0)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-01-03 10:45:43 +01:00
|
|
|
|
log.InfoFormat("Not alerting XenCenter update - latest = {0}, latestcr = {1}, detected = {2}",
|
|
|
|
|
latest != null ? latest.VersionAndLang : "", latestCr != null ? latestCr.VersionAndLang : "", Program.VersionAndLanguage);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-14 16:25:49 +01:00
|
|
|
|
return alerts;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-04 17:35:52 +02:00
|
|
|
|
private static bool IsSuitableForClientUpdateAlert(ClientVersion toUse, Version currentProgramVersion)
|
2017-03-14 16:25:49 +01:00
|
|
|
|
{
|
|
|
|
|
if (toUse == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
2021-06-03 16:46:39 +02:00
|
|
|
|
if (!toUse.Name.Contains(BrandManager.BrandConsole))
|
|
|
|
|
return false;
|
|
|
|
|
|
2017-03-14 16:25:49 +01:00
|
|
|
|
return toUse.Version > currentProgramVersion ||
|
2021-06-03 16:46:39 +02:00
|
|
|
|
toUse.Version == currentProgramVersion && toUse.Lang == Program.CurrentLanguage &&
|
|
|
|
|
!FriendlyNameManager.IsCultureLoaded(Program.CurrentCulture);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 13:59:38 +01:00
|
|
|
|
public static List<XenServerPatchAlert> NewXenServerPatchAlerts(List<XenServerVersion> xenServerVersions,
|
2013-12-05 12:34:16 +01:00
|
|
|
|
List<XenServerPatch> xenServerPatches)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
if (Helpers.CommonCriteriaCertificationRelease)
|
2020-07-26 15:54:52 +02:00
|
|
|
|
return new List<XenServerPatchAlert>();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2014-01-08 14:17:02 +01:00
|
|
|
|
var alerts = new List<XenServerPatchAlert>();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2017-03-20 11:17:35 +01:00
|
|
|
|
var xenServerVersionsAsUpdates = xenServerVersions.Where(v => v.IsVersionAvailableAsAnUpdate);
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
foreach (IXenConnection xenConnection in ConnectionsManager.XenConnectionsCopy)
|
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
Host coordinator = Helpers.GetCoordinator(xenConnection);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
Pool pool = Helpers.GetPoolOfOne(xenConnection);
|
|
|
|
|
List<Host> hosts = xenConnection.Cache.Hosts.ToList();
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (coordinator == null || pool == null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
continue;
|
|
|
|
|
|
2018-06-18 11:46:41 +02:00
|
|
|
|
var serverVersions = new List<XenServerVersion>();
|
|
|
|
|
foreach (Host host in hosts)
|
|
|
|
|
{
|
|
|
|
|
var serverVersion = GetServerVersions(host, xenServerVersions);
|
|
|
|
|
serverVersions.AddRange(serverVersion);
|
|
|
|
|
}
|
|
|
|
|
serverVersions = serverVersions.Distinct().ToList();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
if (serverVersions.Count == 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
foreach (XenServerVersion xenServerVersion in serverVersions)
|
|
|
|
|
{
|
|
|
|
|
XenServerVersion version = xenServerVersion;
|
|
|
|
|
List<XenServerPatch> patches = xenServerPatches.FindAll(patch => version.Patches.Contains(patch));
|
|
|
|
|
|
|
|
|
|
if (patches.Count == 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
foreach (XenServerPatch xenServerPatch in patches)
|
|
|
|
|
{
|
2017-03-20 11:17:35 +01:00
|
|
|
|
XenServerVersion newServerVersion = xenServerVersionsAsUpdates.FirstOrDefault(newVersion => newVersion.PatchUuid.Equals(xenServerPatch.Uuid, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
|
|
var alert = new XenServerPatchAlert(xenServerPatch, newServerVersion);
|
2014-01-08 14:17:02 +01:00
|
|
|
|
var existingAlert = alerts.Find(al => al.Equals(alert));
|
|
|
|
|
|
|
|
|
|
if (existingAlert != null)
|
|
|
|
|
alert = existingAlert;
|
|
|
|
|
else
|
|
|
|
|
alerts.Add(alert);
|
|
|
|
|
|
|
|
|
|
if (!xenConnection.IsConnected)
|
|
|
|
|
continue;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
XenServerPatch serverPatch = xenServerPatch;
|
2014-02-17 10:31:57 +01:00
|
|
|
|
|
2019-05-17 13:13:49 +02:00
|
|
|
|
var noPatchHosts = hosts.Where(host => PatchCanBeInstalledOnHost(serverPatch, host)).ToList();
|
2017-03-20 11:44:33 +01:00
|
|
|
|
|
2020-01-03 10:45:43 +01:00
|
|
|
|
if (noPatchHosts.Count == hosts.Count)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
alert.IncludeConnection(xenConnection);
|
|
|
|
|
else
|
|
|
|
|
alert.IncludeHosts(noPatchHosts);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return alerts;
|
|
|
|
|
}
|
2017-03-20 11:44:33 +01:00
|
|
|
|
|
2019-05-17 13:13:49 +02:00
|
|
|
|
private static bool PatchCanBeInstalledOnHost(XenServerPatch serverPatch, Host host)
|
2017-03-20 11:44:33 +01:00
|
|
|
|
{
|
|
|
|
|
Debug.Assert(serverPatch != null);
|
|
|
|
|
Debug.Assert(host != null);
|
2018-06-18 11:46:41 +02:00
|
|
|
|
|
2019-05-17 13:13:49 +02:00
|
|
|
|
// A patch is applicable to host if the patch is amongst the current version patches
|
|
|
|
|
var patchIsApplicable = GetServerVersions(host, XenServerVersions).Any(v => v.Patches.Contains(serverPatch));
|
|
|
|
|
if (!patchIsApplicable)
|
2018-06-18 11:46:41 +02:00
|
|
|
|
return false;
|
|
|
|
|
|
2017-03-20 11:44:33 +01:00
|
|
|
|
// A patch can be installed on a host if:
|
|
|
|
|
// 1. it is not already installed and
|
|
|
|
|
// 2. the host has all the required patches installed and
|
|
|
|
|
// 3. the host doesn't have any of the conflicting patches installed
|
|
|
|
|
|
|
|
|
|
bool elyOrGreater = Helpers.ElyOrGreater(host);
|
|
|
|
|
var appliedUpdates = host.AppliedUpdates();
|
|
|
|
|
var appliedPatches = host.AppliedPatches();
|
|
|
|
|
|
|
|
|
|
// 1. patch is not already installed
|
|
|
|
|
if (elyOrGreater && appliedUpdates.Any(update => string.Equals(update.uuid, serverPatch.Uuid, StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
return false;
|
|
|
|
|
if (!elyOrGreater && appliedPatches.Any(patch => string.Equals(patch.uuid, serverPatch.Uuid, StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// 2. the host has all the required patches installed
|
|
|
|
|
if (serverPatch.RequiredPatches != null && serverPatch.RequiredPatches.Count > 0 &&
|
|
|
|
|
!serverPatch.RequiredPatches
|
|
|
|
|
.All(requiredPatchUuid =>
|
|
|
|
|
elyOrGreater && appliedUpdates.Any(update => string.Equals(update.uuid, requiredPatchUuid, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|| !elyOrGreater && appliedPatches.Any(patch => string.Equals(patch.uuid, requiredPatchUuid, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// 3. the host doesn't have any of the conflicting patches installed
|
|
|
|
|
if (serverPatch.ConflictingPatches != null && serverPatch.ConflictingPatches.Count > 0 &&
|
|
|
|
|
serverPatch.ConflictingPatches
|
|
|
|
|
.Any(conflictingPatchUuid =>
|
|
|
|
|
elyOrGreater && appliedUpdates.Any(update => string.Equals(update.uuid, conflictingPatchUuid, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|| !elyOrGreater && appliedPatches.Any(patch => string.Equals(patch.uuid, conflictingPatchUuid, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-03-22 11:59:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-03-29 12:13:13 +02:00
|
|
|
|
/// If parameter is null, it returns latestcr XenCenter version if it is greater than current XC version,
|
|
|
|
|
/// or null, if the current XC version is latestcr.
|
|
|
|
|
/// If parameter is not null, it returns the minimum XenCenter version if it is greater than the current XC version,
|
|
|
|
|
/// or null, if the minimum XC version couldn't be found or the current XC version is enough.
|
2017-03-22 11:59:32 +01:00
|
|
|
|
/// </summary>
|
2021-06-04 17:35:52 +02:00
|
|
|
|
public static ClientVersion GetRequiredClientVersion(XenServerVersion serverVersion)
|
2017-03-22 11:59:32 +01:00
|
|
|
|
{
|
2021-06-04 17:35:52 +02:00
|
|
|
|
if (ClientVersions.Count == 0)
|
2017-03-22 11:59:32 +01:00
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
var currentProgramVersion = Program.Version;
|
|
|
|
|
if (currentProgramVersion == new Version(0, 0, 0, 0))
|
|
|
|
|
return null;
|
|
|
|
|
|
2018-03-29 12:13:13 +02:00
|
|
|
|
if (serverVersion == null)
|
2021-06-04 17:35:52 +02:00
|
|
|
|
return ClientVersions.FirstOrDefault(xcv => xcv.LatestCr && xcv.Version > currentProgramVersion);
|
2017-03-22 11:59:32 +01:00
|
|
|
|
|
2018-03-29 12:13:13 +02:00
|
|
|
|
var minXcVersion = serverVersion.MinimumXcVersion;
|
|
|
|
|
if (minXcVersion == null)
|
|
|
|
|
return null;
|
2017-03-22 11:59:32 +01:00
|
|
|
|
|
2021-06-04 17:35:52 +02:00
|
|
|
|
var minimumXcVersion = ClientVersions.FirstOrDefault(xcv => xcv.Version == minXcVersion);
|
2018-03-29 12:13:13 +02:00
|
|
|
|
return minimumXcVersion != null && minimumXcVersion.Version > currentProgramVersion
|
|
|
|
|
? minimumXcVersion
|
|
|
|
|
: null;
|
2017-03-22 11:59:32 +01:00
|
|
|
|
}
|
2016-02-02 20:12:38 +01:00
|
|
|
|
|
2016-06-08 14:34:59 +02:00
|
|
|
|
/// <summary>
|
2020-01-03 10:45:43 +01:00
|
|
|
|
/// This method returns the minimal set of patches for a host if this class already has information about them.
|
|
|
|
|
/// Otherwise it returns empty list.
|
2016-06-08 14:34:59 +02:00
|
|
|
|
/// Calling this function will not initiate a download or update.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static List<XenServerPatch> RecommendedPatchesForHost(Host host)
|
|
|
|
|
{
|
|
|
|
|
var recommendedPatches = new List<XenServerPatch>();
|
|
|
|
|
|
|
|
|
|
if (XenServerVersions == null)
|
2017-08-24 12:54:16 +02:00
|
|
|
|
return null;
|
2016-06-08 14:34:59 +02:00
|
|
|
|
|
2017-03-20 11:44:33 +01:00
|
|
|
|
var serverVersions = GetServerVersions(host, XenServerVersions);
|
2016-06-08 14:34:59 +02:00
|
|
|
|
|
|
|
|
|
if (serverVersions.Count != 0)
|
|
|
|
|
{
|
2016-08-10 11:48:22 +02:00
|
|
|
|
var minimumPatches = serverVersions[0].MinimalPatches;
|
2016-06-08 14:34:59 +02:00
|
|
|
|
|
2016-08-08 19:30:54 +02:00
|
|
|
|
if (minimumPatches == null) //unknown
|
2017-08-24 12:54:16 +02:00
|
|
|
|
return null;
|
2016-08-08 19:30:54 +02:00
|
|
|
|
|
2016-10-05 13:55:34 +02:00
|
|
|
|
bool elyOrGreater = Helpers.ElyOrGreater(host);
|
|
|
|
|
|
2016-06-08 14:34:59 +02:00
|
|
|
|
var appliedPatches = host.AppliedPatches();
|
2016-10-05 13:55:34 +02:00
|
|
|
|
var appliedUpdates = host.AppliedUpdates();
|
|
|
|
|
|
|
|
|
|
if (elyOrGreater)
|
|
|
|
|
{
|
|
|
|
|
recommendedPatches = minimumPatches.FindAll(p => !appliedUpdates.Any(au => string.Equals(au.uuid, p.Uuid, StringComparison.OrdinalIgnoreCase)));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
recommendedPatches = minimumPatches.FindAll(p => !appliedPatches.Any(ap => string.Equals(ap.uuid, p.Uuid, StringComparison.OrdinalIgnoreCase)));
|
|
|
|
|
}
|
2016-06-08 14:34:59 +02:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return recommendedPatches;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-05 12:50:34 +02:00
|
|
|
|
public static List<XenServerPatch> GetMinimalPatches(IXenConnection conn)
|
2016-02-02 20:12:38 +01:00
|
|
|
|
{
|
2018-06-04 16:18:29 +02:00
|
|
|
|
var version = GetCommonServerVersionOfHostsInAConnection(conn, XenServerVersions);
|
2018-06-25 11:37:28 +02:00
|
|
|
|
return GetMinimalPatches(version);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<XenServerPatch> GetMinimalPatches(Host host)
|
|
|
|
|
{
|
|
|
|
|
if (host == null || host.Connection == null || XenServerVersions== null)
|
|
|
|
|
return null;
|
|
|
|
|
var hostVersions = GetServerVersions(host, XenServerVersions);
|
|
|
|
|
return GetMinimalPatches(hostVersions.FirstOrDefault());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static List<XenServerPatch> GetMinimalPatches(XenServerVersion version)
|
|
|
|
|
{
|
2018-06-05 12:50:34 +02:00
|
|
|
|
if (version == null || version.MinimalPatches == null)
|
2016-02-02 20:12:38 +01:00
|
|
|
|
return null;
|
|
|
|
|
|
2018-06-05 12:50:34 +02:00
|
|
|
|
var minimalPatches = new List<XenServerPatch>(version.MinimalPatches);
|
2017-03-14 16:25:49 +01:00
|
|
|
|
|
2018-06-04 16:18:29 +02:00
|
|
|
|
// if there is a "new version" update in the update sequence, also add the minimal patches of this new version
|
2018-06-05 12:50:34 +02:00
|
|
|
|
if (minimalPatches.Count > 0)
|
2016-02-02 20:12:38 +01:00
|
|
|
|
{
|
2018-06-04 16:18:29 +02:00
|
|
|
|
// assuming that the new version update (if there is one) is the last one in the minimal patches list
|
2018-06-05 12:50:34 +02:00
|
|
|
|
var lastUpdate = minimalPatches[minimalPatches.Count - 1];
|
2017-08-29 17:59:49 +02:00
|
|
|
|
|
2018-06-04 16:18:29 +02:00
|
|
|
|
var newServerVersion = XenServerVersions.FirstOrDefault(
|
|
|
|
|
v => v.IsVersionAvailableAsAnUpdate && v.PatchUuid.Equals(lastUpdate.Uuid, StringComparison.OrdinalIgnoreCase));
|
2017-08-29 17:59:49 +02:00
|
|
|
|
|
2018-06-04 16:18:29 +02:00
|
|
|
|
if (newServerVersion != null && newServerVersion.MinimalPatches != null)
|
2018-06-05 12:50:34 +02:00
|
|
|
|
minimalPatches.AddRange(newServerVersion.MinimalPatches);
|
2016-08-08 19:30:54 +02:00
|
|
|
|
}
|
2018-06-04 16:18:29 +02:00
|
|
|
|
|
2018-06-05 12:50:34 +02:00
|
|
|
|
return minimalPatches;
|
2016-02-02 20:27:08 +01:00
|
|
|
|
}
|
2016-02-02 20:12:38 +01:00
|
|
|
|
|
2017-03-24 15:11:06 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets an upgrade sequence that contains a version upgrade, optionally followed by the minimal patches for the new version
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="alert">The alert that refers the version-update</param>
|
|
|
|
|
/// <param name="updateTheNewVersion">Also add the minimum patches for the new version (true) or not (false).</param>
|
2018-08-03 17:11:06 +02:00
|
|
|
|
public static List<XenServerPatch> GetMinimalPatches(XenServerPatchAlert alert, bool updateTheNewVersion)
|
2017-03-24 12:58:03 +01:00
|
|
|
|
{
|
2017-03-24 15:11:06 +01:00
|
|
|
|
Debug.Assert(alert != null);
|
|
|
|
|
|
2018-06-05 12:50:34 +02:00
|
|
|
|
var minimalPatches = new List<XenServerPatch> {alert.Patch};
|
2017-03-24 12:58:03 +01:00
|
|
|
|
|
2020-01-03 10:45:43 +01:00
|
|
|
|
// if it's a version upgrade the min sequence will be this patch (the upgrade) and the min patches for the new version
|
2018-06-04 16:18:29 +02:00
|
|
|
|
if (updateTheNewVersion && alert.NewServerVersion != null && alert.NewServerVersion.MinimalPatches != null)
|
2017-03-24 12:58:03 +01:00
|
|
|
|
{
|
2018-06-05 12:50:34 +02:00
|
|
|
|
minimalPatches.AddRange(alert.NewServerVersion.MinimalPatches);
|
2017-03-24 12:58:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-05 12:50:34 +02:00
|
|
|
|
return minimalPatches;
|
2017-03-24 12:58:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-03 17:11:06 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets all the patches for the given connection
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static List<XenServerPatch> GetAllPatches(IXenConnection conn)
|
|
|
|
|
{
|
|
|
|
|
var version = GetCommonServerVersionOfHostsInAConnection(conn, XenServerVersions);
|
|
|
|
|
return GetAllPatches(version);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets an upgrade sequence that contains a version upgrade, optionally followed by all the patches for the new version
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static List<XenServerPatch> GetAllPatches(XenServerPatchAlert alert, bool updateTheNewVersion)
|
|
|
|
|
{
|
|
|
|
|
Debug.Assert(alert != null);
|
|
|
|
|
|
|
|
|
|
var allPatches = new List<XenServerPatch> { alert.Patch };
|
|
|
|
|
|
2020-01-03 10:45:43 +01:00
|
|
|
|
// if it's a version upgrade the update sequence will be this patch (the upgrade) and the patches for the new version
|
2018-08-03 17:11:06 +02:00
|
|
|
|
if (updateTheNewVersion && alert.NewServerVersion != null)
|
|
|
|
|
{
|
|
|
|
|
var newVersionPatches = GetAllPatches(alert.NewServerVersion);
|
|
|
|
|
if (newVersionPatches != null)
|
|
|
|
|
allPatches.AddRange(newVersionPatches);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return allPatches;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets all the patches for the given server version, including the cumulative updates and the patches on those
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static List<XenServerPatch> GetAllPatches(XenServerVersion version)
|
|
|
|
|
{
|
|
|
|
|
if (version == null || version.Patches == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
// exclude patches that are new versions (we will include the cumulative updates later)
|
|
|
|
|
var excludedUuids = XenServerVersions.Where(v => v.IsVersionAvailableAsAnUpdate).Select(v => v.PatchUuid);
|
|
|
|
|
|
|
|
|
|
var allPatches = new List<XenServerPatch>(version.Patches.Where(p => !excludedUuids.Contains(p.Uuid)));
|
|
|
|
|
|
|
|
|
|
// if there is a "new version" update in the minimal patches (e.g. a cumulative update), also add this new version update and all the patches on it
|
|
|
|
|
if (version.MinimalPatches != null && version.MinimalPatches.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
// assuming that the new version update (if there is one) is the last one in the minimal patches list
|
|
|
|
|
var lastUpdate = version.MinimalPatches[version.MinimalPatches.Count - 1];
|
|
|
|
|
|
|
|
|
|
var newServerVersion = XenServerVersions.FirstOrDefault(
|
|
|
|
|
v => v.IsVersionAvailableAsAnUpdate && v.PatchUuid.Equals(lastUpdate.Uuid, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
|
|
if (newServerVersion != null)
|
|
|
|
|
{
|
|
|
|
|
allPatches.Add(lastUpdate);
|
|
|
|
|
if (newServerVersion.Patches != null)
|
|
|
|
|
allPatches.AddRange(newServerVersion.Patches);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return allPatches;
|
|
|
|
|
}
|
2017-03-24 12:58:03 +01:00
|
|
|
|
|
2016-08-10 11:48:22 +02:00
|
|
|
|
/// <summary>
|
2016-08-11 12:14:32 +02:00
|
|
|
|
/// Returns a XenServerVersion if all hosts of the pool have the same version
|
2016-08-10 11:48:22 +02:00
|
|
|
|
/// Returns null if it is unknown or they don't match
|
|
|
|
|
/// </summary>
|
2016-08-10 13:50:45 +02:00
|
|
|
|
private static XenServerVersion GetCommonServerVersionOfHostsInAConnection(IXenConnection connection, List<XenServerVersion> xsVersions)
|
2016-08-10 11:48:22 +02:00
|
|
|
|
{
|
2018-06-04 16:18:29 +02:00
|
|
|
|
if (connection == null || xsVersions == null)
|
2016-08-10 11:48:22 +02:00
|
|
|
|
return null;
|
2018-06-04 16:18:29 +02:00
|
|
|
|
|
|
|
|
|
XenServerVersion commonXenServerVersion = null;
|
2016-08-10 11:48:22 +02:00
|
|
|
|
List<Host> hosts = connection.Cache.Hosts.ToList();
|
|
|
|
|
|
|
|
|
|
foreach (Host host in hosts)
|
|
|
|
|
{
|
2017-03-20 11:44:33 +01:00
|
|
|
|
var hostVersions = GetServerVersions(host, xsVersions);
|
2016-08-10 11:48:22 +02:00
|
|
|
|
|
|
|
|
|
var foundVersion = hostVersions.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (foundVersion == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-08-10 13:50:45 +02:00
|
|
|
|
if (commonXenServerVersion == null)
|
2016-08-10 11:48:22 +02:00
|
|
|
|
{
|
2016-08-10 13:50:45 +02:00
|
|
|
|
commonXenServerVersion = foundVersion;
|
2016-08-10 11:48:22 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-08-10 13:50:45 +02:00
|
|
|
|
if (commonXenServerVersion != foundVersion)
|
2016-08-10 11:48:22 +02:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-10 13:50:45 +02:00
|
|
|
|
return commonXenServerVersion;
|
2016-08-10 11:48:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-05 12:50:34 +02:00
|
|
|
|
public static List<XenServerPatch> GetPatchSequenceForHost(Host h, List<XenServerPatch> minimalPatches)
|
2016-02-02 20:27:08 +01:00
|
|
|
|
{
|
2018-06-05 12:50:34 +02:00
|
|
|
|
if (minimalPatches == null)
|
|
|
|
|
return null;
|
2016-10-05 13:55:34 +02:00
|
|
|
|
|
2018-06-05 12:50:34 +02:00
|
|
|
|
var appliedUpdateUuids = Helpers.ElyOrGreater(h)
|
|
|
|
|
? h.AppliedUpdates().Select(u => u.uuid).ToList()
|
|
|
|
|
: h.AppliedPatches().Select(p => p.uuid).ToList();
|
2016-10-05 13:55:34 +02:00
|
|
|
|
|
2018-06-05 12:50:34 +02:00
|
|
|
|
var neededPatches = new List<XenServerPatch>(minimalPatches);
|
|
|
|
|
var sequence = new List<XenServerPatch>();
|
|
|
|
|
|
|
|
|
|
//Iterate through minimalPatches once; in each iteration, move the first item from L0
|
|
|
|
|
//that has its dependencies met to the end of the update schedule
|
|
|
|
|
for (int i = 0; i < neededPatches.Count; i++)
|
2016-10-05 13:55:34 +02:00
|
|
|
|
{
|
2018-06-05 12:50:34 +02:00
|
|
|
|
var p = neededPatches[i];
|
2016-02-02 20:27:08 +01:00
|
|
|
|
|
2018-06-05 12:50:34 +02:00
|
|
|
|
if (appliedUpdateUuids.Any(apu => string.Equals(apu, p.Uuid, StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
continue; //the patch has been applied
|
2016-02-02 20:27:08 +01:00
|
|
|
|
|
2018-06-05 12:50:34 +02:00
|
|
|
|
if (p.RequiredPatches == null || p.RequiredPatches.Count == 0 // no requirements
|
|
|
|
|
|| p.RequiredPatches.All(rp => //all the required patches are already in the sequence or have already been applied
|
|
|
|
|
sequence.Any(useqp => string.Equals(useqp.Uuid, rp, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|| appliedUpdateUuids.Any(apu => string.Equals(apu, rp, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
)
|
|
|
|
|
)
|
2016-02-02 20:27:08 +01:00
|
|
|
|
{
|
|
|
|
|
// this patch can be added to the upgrade sequence now
|
2016-03-16 14:41:10 +01:00
|
|
|
|
sequence.Add(p);
|
2016-02-02 20:27:08 +01:00
|
|
|
|
|
|
|
|
|
// by now the patch has either been added to the upgrade sequence or something already contains it among the installed patches
|
2018-06-05 12:50:34 +02:00
|
|
|
|
neededPatches.RemoveAt(i);
|
2016-02-02 20:27:08 +01:00
|
|
|
|
|
|
|
|
|
//resetting position - the loop will start on 0. item
|
2018-06-05 12:50:34 +02:00
|
|
|
|
i = -1;
|
2016-02-02 20:12:38 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-02 20:27:08 +01:00
|
|
|
|
return sequence;
|
2016-02-02 20:12:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-14 17:38:10 +01:00
|
|
|
|
public static List<XenServerVersionAlert> NewXenServerVersionAlerts(List<XenServerVersion> xenServerVersions)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
if (Helpers.CommonCriteriaCertificationRelease)
|
2020-07-26 15:54:52 +02:00
|
|
|
|
return new List<XenServerVersionAlert>();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2013-12-05 13:03:34 +01:00
|
|
|
|
var latestVersion = xenServerVersions.FindAll(item => item.Latest).OrderByDescending(v => v.Version).FirstOrDefault();
|
2017-03-14 17:38:10 +01:00
|
|
|
|
var latestCrVersion = xenServerVersions.FindAll(item => item.LatestCr).OrderByDescending(v => v.Version).FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
List<XenServerVersionAlert> alerts = new List<XenServerVersionAlert>();
|
|
|
|
|
|
|
|
|
|
if (latestVersion != null)
|
|
|
|
|
alerts.Add(CreateAlertForXenServerVersion(latestVersion));
|
2014-01-03 09:37:45 +01:00
|
|
|
|
|
2017-03-14 17:38:10 +01:00
|
|
|
|
if (latestCrVersion != null && latestCrVersion != latestVersion)
|
|
|
|
|
alerts.Add(CreateAlertForXenServerVersion(latestCrVersion));
|
|
|
|
|
|
|
|
|
|
return alerts;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static XenServerVersionAlert CreateAlertForXenServerVersion(XenServerVersion version)
|
|
|
|
|
{
|
|
|
|
|
var alert = new XenServerVersionAlert(version);
|
2014-01-03 09:37:45 +01:00
|
|
|
|
|
2017-03-20 11:44:33 +01:00
|
|
|
|
// the patch that installs this version, if any
|
|
|
|
|
var patch = XenServerPatches.FirstOrDefault(p => p.Uuid.Equals(version.PatchUuid, StringComparison.OrdinalIgnoreCase));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
foreach (IXenConnection xc in ConnectionsManager.XenConnectionsCopy)
|
|
|
|
|
{
|
2014-01-08 14:17:02 +01:00
|
|
|
|
if (!xc.IsConnected)
|
|
|
|
|
continue;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
Host coordinator = Helpers.GetCoordinator(xc);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
Pool pool = Helpers.GetPoolOfOne(xc);
|
|
|
|
|
List<Host> hosts = xc.Cache.Hosts.ToList();
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (coordinator == null || pool == null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
continue;
|
|
|
|
|
|
2017-03-20 11:44:33 +01:00
|
|
|
|
// Show the Upgrade alert for a host if:
|
|
|
|
|
// - the host version is older than this version AND
|
|
|
|
|
// - there is no patch (amongst the current version patches) that can update to this version OR, if there is a patch, the patch cannot be installed
|
2019-05-17 13:13:49 +02:00
|
|
|
|
|
2017-03-20 11:44:33 +01:00
|
|
|
|
var outOfDateHosts = hosts.Where(host => new Version(Helpers.HostProductVersion(host)) < version.Version
|
2019-05-17 13:13:49 +02:00
|
|
|
|
&& (patch == null || !PatchCanBeInstalledOnHost(patch, host))).ToList();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-01-03 10:45:43 +01:00
|
|
|
|
if (outOfDateHosts.Count == hosts.Count)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
alert.IncludeConnection(xc);
|
|
|
|
|
else
|
|
|
|
|
alert.IncludeHosts(outOfDateHosts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return alert;
|
|
|
|
|
}
|
2013-12-05 13:46:39 +01:00
|
|
|
|
|
2017-10-03 16:32:57 +02:00
|
|
|
|
public static List<XenServerVersion> GetServerVersions(Host host, List<XenServerVersion> xenServerVersions)
|
2017-03-20 11:44:33 +01:00
|
|
|
|
{
|
|
|
|
|
var serverVersions = xenServerVersions.FindAll(version =>
|
|
|
|
|
{
|
|
|
|
|
if (version.BuildNumber != string.Empty)
|
2017-09-29 12:56:46 +02:00
|
|
|
|
return (host.BuildNumberRaw() == version.BuildNumber);
|
2017-03-20 11:44:33 +01:00
|
|
|
|
|
2018-10-22 15:34:31 +02:00
|
|
|
|
return Helpers.HostProductVersion(host) == version.Version.ToString();
|
2017-03-20 11:44:33 +01:00
|
|
|
|
});
|
|
|
|
|
return serverVersions;
|
|
|
|
|
}
|
2014-01-08 14:17:02 +01:00
|
|
|
|
|
2020-07-26 15:54:52 +02:00
|
|
|
|
public static void RefreshUpdateAlerts(UpdateType flags)
|
2013-12-05 13:46:39 +01:00
|
|
|
|
{
|
2020-07-26 15:54:52 +02:00
|
|
|
|
var alerts = new List<XenServerUpdateAlert>();
|
2013-12-05 13:46:39 +01:00
|
|
|
|
|
2020-07-26 15:54:52 +02:00
|
|
|
|
if (flags.HasFlag(UpdateType.ServerVersion))
|
|
|
|
|
alerts.AddRange(NewXenServerVersionAlerts(XenServerVersionsForAutoCheck));
|
2013-12-05 13:46:39 +01:00
|
|
|
|
|
2020-07-26 15:54:52 +02:00
|
|
|
|
if (flags.HasFlag(UpdateType.ServerPatches))
|
|
|
|
|
alerts.AddRange(NewXenServerPatchAlerts(XenServerVersions, XenServerPatches));
|
2013-12-05 13:46:39 +01:00
|
|
|
|
|
2020-07-26 15:54:52 +02:00
|
|
|
|
bool changed = false;
|
2014-01-08 14:17:02 +01:00
|
|
|
|
|
2020-07-26 15:54:52 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
lock (updateAlertsLock)
|
|
|
|
|
{
|
|
|
|
|
foreach (var alert in alerts)
|
|
|
|
|
{
|
|
|
|
|
var existingAlert = updateAlerts.FirstOrDefault(a => a.Equals(alert));
|
|
|
|
|
|
|
|
|
|
if (existingAlert != null && alert.CanIgnore)
|
|
|
|
|
{
|
|
|
|
|
updateAlerts.Remove(existingAlert);
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
else if (existingAlert is XenServerUpdateAlert updAlert)
|
|
|
|
|
{
|
|
|
|
|
updateAlerts.Remove(updAlert);
|
|
|
|
|
updAlert.CopyConnectionsAndHosts(alert);
|
|
|
|
|
if (!updateAlerts.Contains(updAlert))
|
|
|
|
|
updateAlerts.Add(updAlert);
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
else if (!alert.CanIgnore && !updateAlerts.Contains(alert))
|
|
|
|
|
{
|
|
|
|
|
updateAlerts.Add(alert);
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-08 14:17:02 +01:00
|
|
|
|
|
2020-07-26 15:54:52 +02:00
|
|
|
|
if (changed)
|
|
|
|
|
UpdateAlertCollectionChanged?.Invoke(new CollectionChangeEventArgs(CollectionChangeAction.Refresh, UpdateAlerts));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
2020-01-03 11:04:00 +01:00
|
|
|
|
{
|
2020-07-26 15:54:52 +02:00
|
|
|
|
log.Error("Failed to refresh the updates", e);
|
2020-01-03 11:04:00 +01:00
|
|
|
|
}
|
2013-12-05 13:46:39 +01:00
|
|
|
|
}
|
2015-07-23 14:37:14 +02:00
|
|
|
|
|
2018-03-14 13:12:18 +01:00
|
|
|
|
private static XenServerPatchAlert FindPatchAlert(Predicate<XenServerPatch> predicate)
|
|
|
|
|
{
|
2020-07-26 15:54:52 +02:00
|
|
|
|
var existingAlert = UpdateAlerts.FirstOrDefault(a => a is XenServerPatchAlert patchAlert && predicate(patchAlert.Patch));
|
2018-03-14 13:12:18 +01:00
|
|
|
|
if (existingAlert != null)
|
|
|
|
|
return existingAlert as XenServerPatchAlert;
|
|
|
|
|
|
|
|
|
|
if (XenServerPatches.Count == 0)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
var xenServerPatch = XenServerPatches.FirstOrDefault(p => predicate(p));
|
|
|
|
|
if (xenServerPatch == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
var newServerVersion = XenServerVersions.FirstOrDefault(v => v.IsVersionAvailableAsAnUpdate &&
|
|
|
|
|
v.PatchUuid.Equals(xenServerPatch.Uuid, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
|
|
return new XenServerPatchAlert(xenServerPatch, newServerVersion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static XenServerPatchAlert FindPatchAlertByUuid(string uuid)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(uuid))
|
|
|
|
|
return null;
|
|
|
|
|
return FindPatchAlert(p => p.Uuid.Equals(uuid, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static XenServerPatchAlert FindPatchAlertByName(string patchName)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(patchName))
|
|
|
|
|
return null;
|
|
|
|
|
return FindPatchAlert(p => p.Name.Equals(patchName, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
}
|
2019-08-21 12:43:11 +02:00
|
|
|
|
|
|
|
|
|
public static hotfix_eligibility HotfixEligibility(Host host, out XenServerVersion xenServerVersion)
|
|
|
|
|
{
|
|
|
|
|
xenServerVersion = null;
|
|
|
|
|
if (XenServerVersions == null)
|
|
|
|
|
return hotfix_eligibility.all;
|
|
|
|
|
|
|
|
|
|
xenServerVersion = GetServerVersions(host, XenServerVersions).FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
return xenServerVersion?.HotfixEligibility ?? hotfix_eligibility.all;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void CheckHotfixEligibility(IXenConnection connection)
|
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
var coordinator = Helpers.GetCoordinator(connection);
|
|
|
|
|
if (coordinator == null)
|
2019-08-21 12:43:11 +02:00
|
|
|
|
return;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
var hotfixEligibility = HotfixEligibility(coordinator, out var xenServerVersion);
|
2019-08-21 12:43:11 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (!HotfixEligibilityAlert.IsAlertNeeded(hotfixEligibility, xenServerVersion, !coordinator.IsFreeLicenseOrExpired()))
|
2019-08-21 12:43:11 +02:00
|
|
|
|
{
|
2019-08-30 11:00:01 +02:00
|
|
|
|
Alert.RemoveAlert(a => a is HotfixEligibilityAlert && connection.Equals(a.Connection));
|
2019-08-21 12:43:11 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-30 11:00:01 +02:00
|
|
|
|
var alertIndex = Alert.FindAlertIndex(a => a is HotfixEligibilityAlert alert && connection.Equals(alert.Connection) && xenServerVersion == alert.Version);
|
|
|
|
|
if (alertIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
Alert.RemoveAlert(a => a is HotfixEligibilityAlert && connection.Equals(a.Connection)); // ensure that there is no other alert for this connection
|
|
|
|
|
Alert.AddAlert(new HotfixEligibilityAlert(connection, xenServerVersion));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
Alert.RefreshAlertAt(alertIndex);
|
2019-08-21 12:43:11 +02:00
|
|
|
|
}
|
2019-09-04 14:21:57 +02:00
|
|
|
|
|
|
|
|
|
public static void CheckHotfixEligibility()
|
|
|
|
|
{
|
|
|
|
|
var alerts = new List<HotfixEligibilityAlert>();
|
|
|
|
|
|
|
|
|
|
foreach (var connection in ConnectionsManager.XenConnectionsCopy)
|
|
|
|
|
{
|
|
|
|
|
if (!connection.IsConnected)
|
|
|
|
|
continue;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
var coordinator = Helpers.GetCoordinator(connection);
|
|
|
|
|
if (coordinator == null)
|
2019-09-04 14:21:57 +02:00
|
|
|
|
continue;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
var hotfixEligibility = HotfixEligibility(coordinator, out var xenServerVersion);
|
|
|
|
|
if (!HotfixEligibilityAlert.IsAlertNeeded(hotfixEligibility, xenServerVersion, !coordinator.IsFreeLicenseOrExpired()))
|
2019-09-04 14:21:57 +02:00
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
alerts.Add(new HotfixEligibilityAlert(connection, xenServerVersion));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Alert.RemoveAlert(a => a is HotfixEligibilityAlert);
|
|
|
|
|
Alert.AddAlertRange(alerts);
|
|
|
|
|
}
|
2020-07-26 15:54:52 +02:00
|
|
|
|
|
|
|
|
|
[Flags]
|
|
|
|
|
public enum UpdateType : short
|
|
|
|
|
{
|
|
|
|
|
None = 0,
|
|
|
|
|
ServerPatches = 1,
|
|
|
|
|
ServerVersion = 2,
|
|
|
|
|
XenCenterVersion = 4
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|