CP-18421: Use host.updates instead of host.patches

Signed-off-by: Gabor Apati-Nagy <gabor.apati-nagy@citrix.com>
This commit is contained in:
Gabor Apati-Nagy 2016-10-05 12:55:34 +01:00
parent 5cfce00e01
commit 37735febd1
7 changed files with 113 additions and 23 deletions

View File

@ -385,19 +385,34 @@ namespace XenAdmin.Core
var noPatchHosts = hosts.Where(host =>
{
bool elyOrGreater = Helpers.ElyOrGreater(host);
var appliedUpdates = host.AppliedUpdates();
var appliedPatches = host.AppliedPatches();
// 1. patch is not already installed
if (appliedPatches.Any(patch => string.Equals(patch.uuid, serverPatch.Uuid, StringComparison.OrdinalIgnoreCase)))
return false;
// 1. patch is not already installed
if (elyOrGreater && appliedUpdates.Any(update => string.Equals(update.uuid, serverPatch.Uuid, StringComparison.OrdinalIgnoreCase)))
return false;
else if (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 => appliedPatches.Any(patch => string.Equals(patch.uuid, requiredPatchUuid, StringComparison.OrdinalIgnoreCase))))
!serverPatch.RequiredPatches
.All(requiredPatchUuid =>
elyOrGreater && appliedUpdates.Any(update => string.Equals(update.uuid, requiredPatchUuid, StringComparison.OrdinalIgnoreCase))
|| 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 => appliedPatches.Any(patch => string.Equals(patch.uuid, conflictingPatchUuid, StringComparison.OrdinalIgnoreCase))))
serverPatch.ConflictingPatches
.Any(conflictingPatchUuid =>
elyOrGreater && appliedUpdates.Any(update => string.Equals(update.uuid, conflictingPatchUuid, StringComparison.OrdinalIgnoreCase))
|| appliedPatches.Any(patch => string.Equals(patch.uuid, conflictingPatchUuid, StringComparison.OrdinalIgnoreCase))
)
)
return false;
return true;
@ -444,8 +459,19 @@ namespace XenAdmin.Core
if (minimumPatches == null) //unknown
return recommendedPatches;
bool elyOrGreater = Helpers.ElyOrGreater(host);
var appliedPatches = host.AppliedPatches();
recommendedPatches = minimumPatches.FindAll(p => !appliedPatches.Any(ap => string.Equals(ap.uuid, p.Uuid, StringComparison.OrdinalIgnoreCase)));
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)));
}
}
@ -543,7 +569,18 @@ namespace XenAdmin.Core
private static List<XenServerPatch> GetUpgradeSequenceForHost(Host h, List<XenServerPatch> latestPatches)
{
var sequence = new List<XenServerPatch>();
var appliedPatches = h.AppliedPatches();
var appliedUpdateUuids = new List<string>();
bool elyOrGreater = Helpers.ElyOrGreater(h);
if (elyOrGreater)
{
appliedUpdateUuids = h.AppliedUpdates().Select(u => u.uuid).ToList();
}
else
{
appliedUpdateUuids = h.AppliedPatches().Select(p => p.uuid).ToList();
}
var neededPatches = new List<XenServerPatch>(latestPatches);
@ -554,7 +591,7 @@ namespace XenAdmin.Core
//checking requirements
if (//not applied yet
!appliedPatches.Any(ap => string.Equals(ap.uuid, p.Uuid, StringComparison.OrdinalIgnoreCase))
!appliedUpdateUuids.Any(apu => string.Equals(apu, p.Uuid, StringComparison.OrdinalIgnoreCase))
// and either no requirements or they are meet
&& (p.RequiredPatches == null
|| p.RequiredPatches.Count == 0
@ -565,7 +602,7 @@ namespace XenAdmin.Core
(sequence.Count != 0 && sequence.Any(useqp => string.Equals(useqp.Uuid, rp, StringComparison.OrdinalIgnoreCase)))
//the required-patch has already been applied
|| (appliedPatches.Count != 0 && appliedPatches.Any(ap => string.Equals(ap.uuid, rp, StringComparison.OrdinalIgnoreCase)))
|| (appliedUpdateUuids.Count != 0 && appliedUpdateUuids.Any(apu => string.Equals(apu, rp, StringComparison.OrdinalIgnoreCase)))
)
))
{

View File

@ -287,6 +287,7 @@ namespace XenAdmin.TabPages
else if (xenObject is Pool)
{
xenObject.Connection.Cache.DeregisterBatchCollectionChanged<Pool_patch>(Pool_patch_BatchCollectionChanged);
xenObject.Connection.Cache.DeregisterBatchCollectionChanged<Pool_update>(Pool_update_BatchCollectionChanged);
}
}
@ -329,6 +330,7 @@ namespace XenAdmin.TabPages
else if (xenObject is Pool)
{
xenObject.Connection.Cache.RegisterBatchCollectionChanged<Pool_patch>(Pool_patch_BatchCollectionChanged);
xenObject.Connection.Cache.RegisterBatchCollectionChanged<Pool_update>(Pool_update_BatchCollectionChanged);
}
}
@ -337,6 +339,11 @@ namespace XenAdmin.TabPages
Program.BeginInvoke(this, BuildList);
}
void Pool_update_BatchCollectionChanged(object sender, EventArgs e)
{
Program.BeginInvoke(this, BuildList);
}
void OtherConfigAndTagsWatcher_TagsChanged(object sender, EventArgs e)
{
BuildList();
@ -664,7 +671,9 @@ namespace XenAdmin.TabPages
PDSection s = pdSectionUpdates;
List<KeyValuePair<String, String>> messages;
if (Helpers.ElyOrGreater(host))
bool elyOrGreater = Helpers.ElyOrGreater(host);
if (elyOrGreater)
{
// As of Ely we use host.patches_requiring_reboot to generate the list of reboot required messages
messages = CheckHostPatchesRequiringReboot(host);
@ -1697,18 +1706,26 @@ namespace XenAdmin.TabPages
private string poolAppliedPatches()
{
return poolPatchString(patch => patch.host_patches.Count == xenObject.Connection.Cache.HostCount);
return
Helpers.ElyOrGreater(xenObject.Connection)
? poolUpdateString(update => update.AppliedOnHosts.Count == xenObject.Connection.Cache.HostCount)
: poolPatchString(patch => patch.host_patches.Count == xenObject.Connection.Cache.HostCount);
}
private string poolPartialPatches()
{
return poolPatchString(patch => patch.host_patches.Count > 0 &&
patch.host_patches.Count != xenObject.Connection.Cache.HostCount);
return
Helpers.ElyOrGreater(xenObject.Connection)
? poolUpdateString(update => update.AppliedOnHosts.Count > 0 && update.AppliedOnHosts.Count != xenObject.Connection.Cache.HostCount)
: poolPatchString(patch => patch.host_patches.Count > 0 && patch.host_patches.Count != xenObject.Connection.Cache.HostCount);
}
private string poolNotAppliedPatches()
{
return poolPatchString(patch => patch.host_patches.Count == 0);
return
Helpers.ElyOrGreater(xenObject.Connection)
? poolUpdateString(update => update.AppliedOnHosts.Count == 0)
: poolPatchString(patch => patch.host_patches.Count == 0);
}
private string poolPatchString(Predicate<Pool_patch> predicate)
@ -1726,6 +1743,21 @@ namespace XenAdmin.TabPages
return String.Join(",", output.ToArray());
}
private string poolUpdateString(Predicate<Pool_update> predicate)
{
Pool_update[] updates = xenObject.Connection.Cache.Pool_updates;
List<String> output = new List<String>();
foreach (var update in updates)
if (predicate(update))
output.Add(update.name_label);
output.Sort(StringUtility.NaturalCompare);
return String.Join(",", output.ToArray());
}
#endregion
/// <summary>

View File

@ -262,6 +262,10 @@ namespace XenAdmin.Wizards.PatchingWizard
row.Enabled = false;
row.Cells[3].ToolTipText = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_CANNOT_INSTALL_SUPP_PACKS;
}
if (Helpers.ElyOrGreater(host) && selectedHosts != null)
{
disableNotApplicableHosts(row, selectedHosts, host);
}
break;
}
}
@ -270,19 +274,19 @@ namespace XenAdmin.Wizards.PatchingWizard
{
if (selectedHosts != null && !selectedHosts.Contains(host))
{
string alertUuid = null;
if (SelectedUpdateAlert != null)
string patchUuidFromAlert = null;
if (SelectedUpdateAlert != null && SelectedUpdateAlert.Patch != null)
{
alertUuid = SelectedUpdateAlert.uuid;
patchUuidFromAlert = SelectedUpdateAlert.Patch.Uuid;
}
else if (FileFromDiskAlert != null)
{
alertUuid = FileFromDiskAlert.uuid;
patchUuidFromAlert = FileFromDiskAlert.Patch.Uuid;
}
if (alertUuid != null)
if (string.IsNullOrEmpty(patchUuidFromAlert))
{
if (isPatchApplied(alertUuid, host))
if (isPatchApplied(patchUuidFromAlert, host))
{
row.Cells[3].ToolTipText = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_PATCH_ALREADY_APPLIED;
}

View File

@ -105,7 +105,9 @@ namespace XenAdmin.Wizards.PatchingWizard
Uri address = new Uri(patchUri);
string tempFile = Path.GetTempFileName();
downloadAction = new DownloadAndUnzipXenServerPatchAction(SelectedUpdateAlert.Name, address, tempFile, Branding.Update);
bool isIso = patchUri.ToLowerInvariant().EndsWith("iso");
downloadAction = new DownloadAndUnzipXenServerPatchAction(SelectedUpdateAlert.Name, address, tempFile, isIso ? "iso" : Branding.Update);
if (downloadAction != null)
{
@ -434,6 +436,8 @@ namespace XenAdmin.Wizards.PatchingWizard
if (action is UploadSupplementalPackAction)
{
_patch = null;
foreach (var vdiRef in (action as UploadSupplementalPackAction).VdiRefs)
SuppPackVdis[vdiRef.Key] = action.Connection.Resolve(vdiRef.Value);

View File

@ -89,7 +89,9 @@ namespace XenAdmin.Wizards.PatchingWizard.PlanActions
Uri address = new Uri(patchUri);
tempFileName = Path.GetTempFileName();
var downloadAction = new DownloadAndUnzipXenServerPatchAction(patch.Name, address, tempFileName, Branding.Update);
bool isIso = patchUri.ToLowerInvariant().EndsWith("iso");
var downloadAction = new DownloadAndUnzipXenServerPatchAction(patch.Name, address, tempFileName, isIso ? "iso" : Branding.Update);
if (downloadAction != null)
{

View File

@ -142,7 +142,9 @@ namespace XenAdmin.Wizards.PatchingWizard.PlanActions
Uri address = new Uri(patchUri);
tempFileName = Path.GetTempFileName();
var downloadAction = new DownloadAndUnzipXenServerPatchAction(patch.Name, address, tempFileName, Branding.Update);
bool isIso = patchUri.ToLowerInvariant().EndsWith("iso");
var downloadAction = new DownloadAndUnzipXenServerPatchAction(patch.Name, address, tempFileName, isIso ? "iso" : Branding.Update);
if (downloadAction != null)
{

View File

@ -34,6 +34,7 @@ using System.Collections.Generic;
using XenAdmin;
using XenAdmin.Core;
using XenAdmin.Network;
using System.Linq;
namespace XenAPI
{
@ -65,5 +66,13 @@ namespace XenAPI
return false;
}
public List<Host> AppliedOnHosts
{
get
{
return
this.Connection.Cache.Hosts.Where(h => this.AppliedOn(h)).ToList();
}
}
}
}