예제 #1
0
        private static bool PatchCanBeInstalledOnHost(XenServerPatch serverPatch, Host host)
        {
            Debug.Assert(serverPatch != null);
            Debug.Assert(host != null);

            // 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)
            {
                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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        private static XenServerPatchAlert GetServerPatchAlert(List <XenServerPatchAlert> alerts, XenServerPatch patch)
        {
            XenServerPatchAlert alert         = new XenServerPatchAlert(patch);
            XenServerPatchAlert existingAlert = alerts.Find(al => al.Equals(alert));

            if (existingAlert != null)
            {
                alert = existingAlert;
            }
            else
            {
                alerts.Add(alert);
            }

            return(alert);
        }