/// <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); }
/// <summary> /// 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. /// </summary> /// <param name="serverVersion"></param> /// <returns></returns> public static XenCenterVersion GetRequiredXenCenterVersion(XenServerVersion serverVersion) { if (XenCenterVersions.Count == 0) { return(null); } var currentProgramVersion = Program.Version; if (currentProgramVersion == new Version(0, 0, 0, 0)) { return(null); } if (serverVersion == null) { return(XenCenterVersions.FirstOrDefault(xcv => xcv.LatestCr && xcv.Version > currentProgramVersion)); } var minXcVersion = serverVersion.MinimumXcVersion; if (minXcVersion == null) { return(null); } var minimumXcVersion = XenCenterVersions.FirstOrDefault(xcv => xcv.Version == minXcVersion); return(minimumXcVersion != null && minimumXcVersion.Version > currentProgramVersion ? minimumXcVersion : null); }
private static List <XenServerPatch> GetMinimalPatches(XenServerVersion version) { if (version == null || version.MinimalPatches == null) { return(null); } var minimalPatches = new List <XenServerPatch>(version.MinimalPatches); // if there is a "new version" update in the update sequence, also add the minimal patches of this new version if (minimalPatches.Count > 0) { // assuming that the new version update (if there is one) is the last one in the minimal patches list var lastUpdate = minimalPatches[minimalPatches.Count - 1]; var newServerVersion = XenServerVersions.FirstOrDefault( v => v.IsVersionAvailableAsAnUpdate && v.PatchUuid.Equals(lastUpdate.Uuid, StringComparison.OrdinalIgnoreCase)); if (newServerVersion != null && newServerVersion.MinimalPatches != null) { minimalPatches.AddRange(newServerVersion.MinimalPatches); } } return(minimalPatches); }
/// <summary> /// Returns the latest XenCenter version or null, if the current version is the latest. /// If a server version is provided, it returns the XenCenter version that is required to work with that server. /// If no server version is provided it will return the latestCr XenCenter. /// </summary> /// <param name="serverVersion"></param> /// <returns></returns> public static XenCenterVersion GetRequiredXenCenterVersion(XenServerVersion serverVersion) { if (XenCenterVersions.Count == 0) { return(null); } var currentProgramVersion = Program.Version; if (currentProgramVersion == new Version(0, 0, 0, 0)) { return(null); } var latestVersions = from v in XenCenterVersions where v.Latest select v; var latest = latestVersions.FirstOrDefault(xcv => xcv.Lang == Program.CurrentLanguage) ?? latestVersions.FirstOrDefault(xcv => string.IsNullOrEmpty(xcv.Lang)); var latestCrVersions = from v in XenCenterVersions where v.LatestCr select v; var latestCr = latestCrVersions.FirstOrDefault(xcv => xcv.Lang == Program.CurrentLanguage) ?? latestCrVersions.FirstOrDefault(xcv => string.IsNullOrEmpty(xcv.Lang)); if (serverVersion != null && serverVersion.Latest && latest != null) { return(latest.Version > currentProgramVersion ? latest : null); } return(latestCr != null && latestCr.Version > currentProgramVersion ? latestCr : null); }
public void TestAlertWithConnectionAndHosts() { XenServerVersion ver = new XenServerVersion("1.2.3", "name", true, "http://url", new List<XenServerPatch>(), new DateTime(2011,4,1).ToString(), "123"); XenServerUpdateAlert alert = new XenServerUpdateAlert(ver); alert.IncludeConnection(connA.Object); alert.IncludeConnection(connB.Object); alert.IncludeHosts(new List<Host>() { hostA.Object, hostB.Object }); IUnitTestVerifier validator = new VerifyGetters(alert); validator.Verify(new AlertClassUnitTestData { AppliesTo = "HostAName, HostBName, ConnAName, ConnBName", FixLinkText = "&Go to Web Page...", HelpID = "XenServerUpdateAlert", Description = "name is now available. Download the latest at the Citrix website (April 1, 2011)", HelpLinkText = "&Help on this alert...", Title = "name is now available", Priority = "Priority5" }); Assert.IsFalse(alert.CanIgnore); VerifyConnExpectations(Times.Once); VerifyHostsExpectations(Times.Once); }
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); }
/// <summary> /// Returns a XenServerVersion if all hosts of the pool have the same version /// Returns null if it is unknown or they don't match /// </summary> /// <returns></returns> private static XenServerVersion GetCommonServerVersionOfHostsInAConnection(IXenConnection connection, List <XenServerVersion> xsVersions) { XenServerVersion commonXenServerVersion = null; if (connection == null) { return(null); } List <Host> hosts = connection.Cache.Hosts.ToList(); foreach (Host host in hosts) { var hostVersions = xsVersions.FindAll(version => { if (version.BuildNumber != string.Empty) { return(host.BuildNumberRaw == version.BuildNumber); } return(Helpers.HostProductVersionWithOEM(host) == version.VersionAndOEM || (version.Oem != null && Helpers.OEMName(host).StartsWith(version.Oem) && Helpers.HostProductVersion(host) == version.Version.ToString())); }); var foundVersion = hostVersions.FirstOrDefault(); if (foundVersion == null) { return(null); } else { if (commonXenServerVersion == null) { commonXenServerVersion = foundVersion; } else { if (commonXenServerVersion != foundVersion) { return(null); } } } } return(commonXenServerVersion); }
private static XenServerVersionAlert CreateAlertForXenServerVersion(XenServerVersion version) { var alert = new XenServerVersionAlert(version); // the patch that installs this version, if any var patch = XenServerPatches.FirstOrDefault(p => p.Uuid.Equals(version.PatchUuid, StringComparison.OrdinalIgnoreCase)); foreach (IXenConnection xc in ConnectionsManager.XenConnectionsCopy) { if (!xc.IsConnected) { continue; } Host master = Helpers.GetMaster(xc); Pool pool = Helpers.GetPoolOfOne(xc); List <Host> hosts = xc.Cache.Hosts.ToList(); if (master == null || pool == null) { continue; } // 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 var patchApplicable = patch != null && GetServerVersions(master, XenServerVersions).Any(v => v.Patches.Contains(patch)); var outOfDateHosts = hosts.Where(host => new Version(Helpers.HostProductVersion(host)) < version.Version && (!patchApplicable || !PatchCanBeInstalledOnHost(patch, host, version))); if (outOfDateHosts.Count() == hosts.Count) { alert.IncludeConnection(xc); } else { alert.IncludeHosts(outOfDateHosts); } } return(alert); }
/// <summary> /// Returns a XenServerVersion if all hosts of the pool have the same version /// Returns null if it is unknown or they don't match /// </summary> /// <returns></returns> private static XenServerVersion GetCommonServerVersionOfHostsInAConnection(IXenConnection connection, List <XenServerVersion> xsVersions) { XenServerVersion commonXenServerVersion = null; if (connection == null) { return(null); } List <Host> hosts = connection.Cache.Hosts.ToList(); foreach (Host host in hosts) { var hostVersions = GetServerVersions(host, xsVersions); var foundVersion = hostVersions.FirstOrDefault(); if (foundVersion == null) { return(null); } else { if (commonXenServerVersion == null) { commonXenServerVersion = foundVersion; } else { if (commonXenServerVersion != foundVersion) { return(null); } } } } return(commonXenServerVersion); }
public void TestAlertWithHostsAndNoConnection() { XenServerVersion ver = new XenServerVersion("1.2.3", "name", true, "http://url", new List<XenServerPatch>(), new DateTime(2011, 4, 1).ToString(), "123"); var alert = new XenServerVersionAlert(ver); alert.IncludeHosts(new List<Host> { hostA.Object, hostB.Object }); IUnitTestVerifier validator = new VerifyGetters(alert); validator.Verify(new AlertClassUnitTestData { AppliesTo = "HostAName, HostBName", FixLinkText = "Go to Web Page", HelpID = "XenServerUpdateAlert", Description = "name is now available. Download the latest at the " + XenAdmin.Branding.COMPANY_NAME_SHORT + " website.", HelpLinkText = "Help", Title = "name is now available", Priority = "Priority5" }); Assert.IsFalse(alert.CanIgnore); VerifyConnExpectations(Times.Never); VerifyHostsExpectations(Times.Once); }
private static List<XenServerVersion> GetAVersionWithGivenNumberOfPatches(int numberOfPatches) { var serverVersions = new List<XenServerVersion>(); var version = new XenServerVersion("7.0.0", "XenServer Test 7", true, "", new List<XenServerPatch>(), new List<XenServerPatch>(), DateTime.MinValue.ToString(), "buildNo"); for (int ii = 0; ii < numberOfPatches; ii++) { var patch = new XenServerPatch("patch_uuid_" + ii, "patch name " + ii, "patch description" + ii, "", "", "1.0", "", "", "1970-01-01T00:00:00Z", "", "1000"); version.Patches.Add(patch); version.MinimalPatches.Add(patch); } serverVersions.Add(version); return serverVersions; }
public static XenServerUpdateAlert NewServerVersionAlert(List <XenServerVersion> xenServerVersions, bool checkAlertIsAlreadyDismissed) { if (Helpers.CommonCriteriaCertificationRelease) { return(null); } List <XenServerVersion> latestVersions = xenServerVersions.FindAll(item => item.Latest); if (latestVersions.Count == 0) { return(null); } XenServerVersion latestVersion = latestVersions[0]; for (int i = 1; i < latestVersions.Count; i++) { XenServerVersion version = latestVersions[i]; if (version.Version > latestVersion.Version) { latestVersion = version; } } XenServerUpdateAlert alert = new XenServerUpdateAlert(latestVersion); foreach (IXenConnection xc in ConnectionsManager.XenConnectionsCopy) { Host master = Helpers.GetMaster(xc); Pool pool = Helpers.GetPoolOfOne(xc); List <Host> hosts = xc.Cache.Hosts.ToList(); if (master == null || pool == null) { continue; } //check if the latest version has been already dismissed if (checkAlertIsAlreadyDismissed && GetLatestSeenVersion(pool).Contains(latestVersion.VersionAndOEM)) { return(null); } List <Host> outOfDateHosts = hosts.Where(host => new Version(Helpers.HostProductVersion(host)) < latestVersion.Version).ToList(); if (outOfDateHosts.Count == hosts.Count) { alert.IncludeConnection(xc); } else { alert.IncludeHosts(outOfDateHosts); } } if (alert.CanIgnore) { return(null); } return(alert); }
public static List <XenServerPatchAlert> NewXenServerPatchAlerts(List <XenServerVersion> xenServerVersions, List <XenServerPatch> xenServerPatches) { if (Helpers.CommonCriteriaCertificationRelease) { return(null); } var alerts = new List <XenServerPatchAlert>(); foreach (IXenConnection xenConnection in ConnectionsManager.XenConnectionsCopy) { Host master = Helpers.GetMaster(xenConnection); Pool pool = Helpers.GetPoolOfOne(xenConnection); List <Host> hosts = xenConnection.Cache.Hosts.ToList(); if (master == null || pool == null) { continue; } var serverVersions = xenServerVersions.FindAll(version => { if (version.BuildNumber != string.Empty) { return(master.BuildNumberRaw == version.BuildNumber); } return(Helpers.HostProductVersionWithOEM(master) == version.VersionAndOEM || (version.Oem != null && Helpers.OEMName(master).StartsWith(version.Oem) && Helpers.HostProductVersion(master) == version.Version.ToString())); }); 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) { var alert = new XenServerPatchAlert(xenServerPatch); var existingAlert = alerts.Find(al => al.Equals(alert)); if (existingAlert != null) { alert = existingAlert; } else { alerts.Add(alert); } if (!xenConnection.IsConnected) { continue; } XenServerPatch serverPatch = xenServerPatch; // 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 var noPatchHosts = hosts.Where(host => { var appliedPatches = host.AppliedPatches(); // 1. patch is not already installed if (appliedPatches.Any(patch => patch.uuid == serverPatch.Uuid)) { 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 => patch.uuid == requiredPatchUuid))) { 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 => patch.uuid == conflictingPatchUuid))) { return(false); } return(true); }); if (noPatchHosts.Count() == hosts.Count) { alert.IncludeConnection(xenConnection); } else { alert.IncludeHosts(noPatchHosts); } } } } return(alerts); }
public static List <XenServerPatchAlert> NewXenServerPatchAlerts(List <XenServerVersion> xenServerVersions, List <XenServerPatch> xenServerPatches) { if (Helpers.CommonCriteriaCertificationRelease) { return(null); } var alerts = new List <XenServerPatchAlert>(); var xenServerVersionsAsUpdates = xenServerVersions.Where(v => v.IsVersionAvailableAsAnUpdate); foreach (IXenConnection xenConnection in ConnectionsManager.XenConnectionsCopy) { Host master = Helpers.GetMaster(xenConnection); Pool pool = Helpers.GetPoolOfOne(xenConnection); List <Host> hosts = xenConnection.Cache.Hosts.ToList(); if (master == null || pool == null) { continue; } var serverVersions = new List <XenServerVersion>(); foreach (Host host in hosts) { var serverVersion = GetServerVersions(host, xenServerVersions); serverVersions.AddRange(serverVersion); } serverVersions = serverVersions.Distinct().ToList(); 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) { XenServerVersion newServerVersion = xenServerVersionsAsUpdates.FirstOrDefault(newVersion => newVersion.PatchUuid.Equals(xenServerPatch.Uuid, StringComparison.OrdinalIgnoreCase)); var alert = new XenServerPatchAlert(xenServerPatch, newServerVersion); var existingAlert = alerts.Find(al => al.Equals(alert)); if (existingAlert != null) { alert = existingAlert; } else { alerts.Add(alert); } if (!xenConnection.IsConnected) { continue; } XenServerPatch serverPatch = xenServerPatch; var noPatchHosts = hosts.Where(host => PatchCanBeInstalledOnHost(serverPatch, host, version)); if (noPatchHosts.Count() == hosts.Count) { alert.IncludeConnection(xenConnection); } else { alert.IncludeHosts(noPatchHosts); } } } } return(alerts); }
private static bool PatchCanBeInstalledOnHost(XenServerPatch serverPatch, Host host, XenServerVersion patchApplicableVersion) { Debug.Assert(serverPatch != null); Debug.Assert(host != null); if (Helpers.productVersionCompare(patchApplicableVersion.Version.ToString(), host.ProductVersion()) != 0) { return(false); } // 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); }
public void TestAlertWithNoConnectionAndNoHosts() { XenServerVersion ver = new XenServerVersion("1.2.3", "name", true, "http://url", new List<XenServerPatch>(), new DateTime(2011, 4, 1).ToString(), "123"); XenServerUpdateAlert alert = new XenServerUpdateAlert(ver); IUnitTestVerifier validator = new VerifyGetters(alert); validator.Verify(new AlertClassUnitTestData { AppliesTo = string.Empty, FixLinkText = "&Go to Web Page...", HelpID = "XenServerUpdateAlert", Description = "name is now available. Download the latest at the Citrix website.", HelpLinkText = "&Help on this alert...", Title = "name is now available", Priority = "Priority5" }); Assert.IsTrue(alert.CanIgnore); VerifyConnExpectations(Times.Never); VerifyHostsExpectations(Times.Never); }
public XenServerVersionAlert(XenServerVersion version) { Version = version; _timestamp = version.TimeStamp; }
public XenServerUpdateAlert(XenServerVersion version) { Version = version; _timestamp = version.TimeStamp; canIgnore = true; }
public IgnoreServerAction(IXenConnection connection, XenServerVersion version) : base(connection, "ignore_patch", "ignore_patch", true) { Version = version; }
private static List <XenServerPatchAlert> GetServerPatchesAlerts(List <XenServerVersion> xenServerVersions, List <XenServerPatch> xenServerPatches, bool checkAlertIsAlreadyDismissed) { List <XenServerPatchAlert> alerts = new List <XenServerPatchAlert>(); foreach (IXenConnection xenConnection in ConnectionsManager.XenConnectionsCopy) { Host master = Helpers.GetMaster(xenConnection); Pool pool = Helpers.GetPoolOfOne(xenConnection); List <Host> hosts = xenConnection.Cache.Hosts.ToList(); if (master == null || pool == null) { continue; } List <XenServerVersion> serverVersions = xenServerVersions.FindAll(version => { if (version.BuildNumber != string.Empty) { return(master.BuildNumberRaw == version.BuildNumber); } return(Helpers.HostProductVersionWithOEM(master) == version.VersionAndOEM || (version.Oem != null && Helpers.OEMName(master).StartsWith(version.Oem) && Helpers.HostProductVersion(master) == version.Version.ToString())); }); 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) { XenServerPatchAlert alert = GetServerPatchAlert(alerts, xenServerPatch); if (checkAlertIsAlreadyDismissed && pool.other_config.ContainsKey(IgnorePatchAction.IgnorePatchKey)) { List <string> ignorelist = new List <string>(pool.other_config[IgnorePatchAction.IgnorePatchKey].Split(',')); if (ignorelist.Contains(xenServerPatch.Uuid)) { // we dont want to show the alert continue; } } XenServerPatch serverPatch = xenServerPatch; List <Host> noPatchHosts = hosts.Where(host => !host.AppliedPatches().Any(patch => patch.uuid == serverPatch.Uuid)).ToList(); if (noPatchHosts.Count == hosts.Count) { alert.IncludeConnection(xenConnection); } else { alert.IncludeHosts(noPatchHosts); } } } } return(alerts); }