Esempio n. 1
0
        private List <PlanAction> CompilePoolUpdateActionList(Host host, Pool_update poolUpdate)
        {
            var hostRebootRequired = WizardHelpers.IsHostRebootRequiredForUpdate(host, poolUpdate, LivePatchCodesByHost);

            var actions = new List <PlanAction> {
                new ApplyPoolUpdatePlanAction(host, poolUpdate, hostRebootRequired)
            };

            if (hostRebootRequired)
            {
                actions.Add(new RestartHostPlanAction(host, host.GetRunningVMs()));
            }

            if (poolUpdate.after_apply_guidance.Contains(update_after_apply_guidance.restartXAPI))
            {
                actions.Add(new RestartAgentPlanAction(host));
            }

            if (poolUpdate.after_apply_guidance.Contains(update_after_apply_guidance.restartHVM))
            {
                actions.Add(new RebootVMsPlanAction(host, host.GetRunningHvmVMs()));
            }

            if (poolUpdate.after_apply_guidance.Contains(update_after_apply_guidance.restartPV))
            {
                actions.Add(new RebootVMsPlanAction(host, host.GetRunningPvVMs()));
            }

            return(actions);
        }
Esempio n. 2
0
 protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
 {
     if (direction == PageLoadedDirection.Forward && ApplySuppPackAfterUpgrade && !string.IsNullOrEmpty(FilePath))
     {
         SelectedSuppPack = WizardHelpers.ParseSuppPackFile(FilePath, this, ref cancel);
     }
 }
        public override bool EnableNext()
        {
            if (CheckForUpdatesInProgress)
            {
                return(false);
            }

            if (IsInAutomatedUpdatesMode)
            {
                return(true);
            }

            if (downloadUpdateRadioButton.Checked)
            {
                if (dataGridViewPatches.SelectedRows.Count == 1)
                {
                    DataGridViewExRow row = (DataGridViewExRow)dataGridViewPatches.SelectedRows[0];
                    if (row.Enabled)
                    {
                        return(true);
                    }
                }
            }
            else if (selectFromDiskRadioButton.Checked)
            {
                if (WizardHelpers.IsValidFile(FilePath, out _))
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 4
0
        public override bool EnableNext()
        {
            if (ApplySuppPackAfterUpgrade && !WizardHelpers.IsValidFile(FilePath, out _))
            {
                return(false);
            }

            return(true);
        }
        public override bool EnableNext()
        {
            if (ApplySuppPackAfterUpgrade && !WizardHelpers.IsValidFile(FilePath, out _))
            {
                return(false);
            }

            return(pictureBox1.Visible && pictureBox1.Image == testOK);
        }
Esempio n. 6
0
        private void BrowseButton_Click(object sender, EventArgs e)
        {
            checkBoxInstallSuppPack.Checked = true;
            var suppPack = WizardHelpers.GetSuppPackFromDisk(this);

            if (!string.IsNullOrEmpty(suppPack))
            {
                FilePath = suppPack;
            }
            OnPageUpdated();
        }
        private void PrecheckSuppPack(Pool_update update, string suppPack, out bool alreadyApplied, out bool updateRequiresHostEvacuation)
        {
            alreadyApplied = false;
            if (Cancelling)
            {
                throw new CancelledException();
            }

            var livePatchStatus = new Dictionary <string, livepatch_status>();

            try
            {
                AddProgressStep(string.Format(Messages.UPDATES_WIZARD_RUNNING_PRECHECK, suppPack, host.Name()));


                PatchPrecheckCheck check = new PatchPrecheckCheck(host, update, livePatchStatus);
                var problems             = check.RunAllChecks();
                updateRequiresHostEvacuation = WizardHelpers.IsHostRebootRequiredForUpdate(host, update, livePatchStatus);
                if (problems != null && problems.Count > 0)
                {
                    if (problems[0] is PatchAlreadyApplied)
                    {
                        log.InfoFormat("The update {0} is already applied on {1}. Ignore it.", suppPack, host.Name());
                        ReplaceProgressStep(string.Format(Messages.UPDATES_WIZARD_SKIPPING_UPDATE, suppPack, host.Name()));
                        alreadyApplied = true;
                    }
                    else
                    {
                        throw new Exception(problems[0].Description);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(string.Format("Precheck failed on host {0}", host.Name()), ex);
                throw;
            }

            if (livePatchStatus.ContainsKey(host.uuid) &&
                livePatchStatus[host.uuid] != livepatch_status.ok_livepatch_complete &&
                !hostsThatWillRequireReboot.Contains(host.uuid))
            {
                hostsThatWillRequireReboot.Add(host.uuid);
            }
        }
Esempio n. 8
0
        public void LinkPointReprs()
        {
            List <Point> points = GetPoints(source);

            Point invalidPoint = points.Find(p => p.repr == null);

            if (invalidPoint != null)
            {
                Debug.LogError("There are points, like " + invalidPoint.tsf.name + ", that have no ReprModel. ReprModels may have not been generated.");
                return;
            }

            if (source is BodySearchEngine)
            {
                WizardHelpers.LinkBodyPointReprs(source as BodySearchEngine, body, false);
            }
            else if (source is HandSearchEngine)
            {
                WizardHelpers.LinkHandPointReprs(source as HandSearchEngine, body, true, requiresCorrected);
            }
        }
        protected override void RunWithSession(ref Session session)
        {
            var master = Helpers.GetMaster(Connection);

            var mapping = (from HostUpdateMapping hum in mappings
                           let xpm = hum as XenServerPatchMapping
                                     where xpm != null && xpm.Matches(master, xenServerPatch)
                                     select xpm).FirstOrDefault();

            if (mapping == null || !mapping.IsValid)
            {
                return;
            }

            var livePatchStatus = new Dictionary <string, livepatch_status>();

            if (Cancelling)
            {
                throw new CancelledException();
            }

            var updateRequiresHostReboot = false;

            try
            {
                AddProgressStep(string.Format(Messages.UPDATES_WIZARD_RUNNING_PRECHECK, xenServerPatch.Name, host.Name()));

                RefreshUpdate(host, mapping, session);

                List <Problem> problems = null;

                if (mapping is PoolPatchMapping patchMapping)
                {
                    log.InfoFormat("Running patch precheck on '{0}'. Patch = '{1}' (uuid = '{2}'; opaque_ref = '{3}')", host.Name(), patchMapping.Pool_patch.Name(), patchMapping.Pool_patch.uuid, patchMapping.Pool_patch.opaque_ref);
                    problems = new PatchPrecheckCheck(host, patchMapping.Pool_patch, livePatchStatus).RunAllChecks();
                    updateRequiresHostReboot = WizardHelpers.IsHostRebootRequiredForUpdate(host, patchMapping.Pool_patch, livePatchStatus);
                }
                else if (mapping is PoolUpdateMapping updateMapping)
                {
                    log.InfoFormat("Running update precheck on '{0}'. Update = '{1}' (uuid = '{2}'; opaque_ref = '{3}'", host.Name(), updateMapping.Pool_update.Name(), updateMapping.Pool_update.uuid, updateMapping.Pool_update.opaque_ref);
                    problems = new PatchPrecheckCheck(host, updateMapping.Pool_update, livePatchStatus).RunAllChecks();
                    updateRequiresHostReboot = WizardHelpers.IsHostRebootRequiredForUpdate(host, updateMapping.Pool_update, livePatchStatus);
                }

                Problem problem = null;

                if (problems != null && problems.Count > 0)
                {
                    problem = problems[0];
                }

                if (problem != null)
                {
                    throw new Exception(problem.Description);
                }
            }
            catch (Exception ex)
            {
                log.Error(string.Format("Precheck failed on host {0}", host.Name()), ex);
                throw;
            }

            if (updateRequiresHostReboot && !hostsThatWillRequireReboot.Contains(host.uuid))
            {
                hostsThatWillRequireReboot.Add(host.uuid);
            }
            if (updateRequiresHostReboot && !mapping.HostsThatNeedEvacuated.Contains(host.uuid))
            {
                mapping.HostsThatNeedEvacuated.Add(host.uuid);
            }
            if (livePatchStatus.ContainsKey(host.uuid) && livePatchStatus[host.uuid] == livepatch_status.ok_livepatch_complete)
            {
                if (!livePatchAttempts.ContainsKey(host.uuid) || livePatchAttempts[host.uuid] == null)
                {
                    livePatchAttempts[host.uuid] = new List <string>();
                }
                livePatchAttempts[host.uuid].Add(xenServerPatch.Uuid);
            }
        }
Esempio n. 10
0
        private List <HostPlan> CompileManualHostPlan(Pool pool, out List <Host> applicableHosts)
        {
            var poolHosts = pool.Connection.Cache.Hosts.ToList();

            SelectedServers.Sort(); //master first and then the slaves
            var hostplans = new List <HostPlan>();

            if (SelectedUpdateType == UpdateType.ISO)
            {
                if (PoolUpdate != null) //ely or greater
                {
                    foreach (var server in SelectedServers)
                    {
                        if (poolHosts.Contains(server))
                        {
                            var hostRebootRequired = WizardHelpers.IsHostRebootRequiredForUpdate(server, PoolUpdate, LivePatchCodesByHost);

                            var updateActions = new List <PlanAction> {
                                new ApplyPoolUpdatePlanAction(server, PoolUpdate, hostRebootRequired)
                            };
                            hostplans.Add(new HostPlan(server, null, updateActions, null));
                        }
                    }
                }
                else if (SuppPackVdis != null) //supp pack
                {
                    foreach (var server in SelectedServers)
                    {
                        if (SuppPackVdis.ContainsKey(server) && poolHosts.Contains(server))
                        {
                            var updateActions = new List <PlanAction> {
                                new InstallSupplementalPackPlanAction(server, SuppPackVdis[server])
                            };
                            hostplans.Add(new HostPlan(server, null, updateActions, null));
                        }
                    }
                }
            }
            else // legacy
            {
                foreach (var server in SelectedServers)
                {
                    if (poolHosts.Contains(server))
                    {
                        var hostRebootRequired = WizardHelpers.IsHostRebootRequiredForUpdate(server, Patch, LivePatchCodesByHost);

                        var updateActions = new List <PlanAction> {
                            new ApplyPatchPlanAction(server, Patch, hostRebootRequired)
                        };
                        hostplans.Add(new HostPlan(server, null, updateActions, null));
                    }
                }

                if (RemoveUpdateFile && hostplans.Count > 0)
                {
                    hostplans[hostplans.Count - 1].UpdatesPlanActions.Add(new RemoveUpdateFile(pool, Patch));
                }
            }

            applicableHosts = hostplans.Select(h => h.Host).ToList();
            return(hostplans);
        }
        protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
        {
            if (direction == PageLoadedDirection.Forward)
            {
                if (IsInAutomatedUpdatesMode)
                {
                    var succeed = Updates.CheckForUpdatesSync(this.Parent);
                    cancel = !succeed;
                }
                else if (downloadUpdateRadioButton.Checked)
                {
                    UpdateAlertFromWeb = dataGridViewPatches.SelectedRows.Count > 0
                        ? ((PatchGridViewRow)dataGridViewPatches.SelectedRows[0]).UpdateAlert
                        : null;

                    var distinctHosts = UpdateAlertFromWeb != null ? UpdateAlertFromWeb.DistinctHosts : null;
                    SelectedUpdateType = distinctHosts != null && distinctHosts.Any(Helpers.ElyOrGreater)
                        ? UpdateType.ISO
                        : UpdateType.Legacy;

                    AlertFromFileOnDisk      = null;
                    FileFromDiskHasUpdateXml = false;
                    unzippedUpdateFilePath   = null;
                    SelectedPatchFilePath    = null;
                    PatchFromDisk            = new KeyValuePair <XenServerPatch, string>(null, null);
                }
                else
                {
                    UpdateAlertFromWeb    = null;
                    SelectedPatchFilePath = null;

                    if (!WizardHelpers.IsValidFile(FilePath, out var pathFailure))
                    {
                        using (var dlg = new ThreeButtonDialog(new ThreeButtonDialog.Details(
                                                                   SystemIcons.Error, pathFailure, Messages.UPDATES)))
                        {
                            cancel = true;
                            dlg.ShowDialog();
                            return;
                        }
                    }

                    SelectedPatchFilePath = FilePath;

                    if (Path.GetExtension(FilePath).ToLowerInvariant().Equals(".zip"))
                    {
                        //check if we are installing the update the user sees in the textbox
                        if (unzippedUpdateFilePath == null || !File.Exists(unzippedUpdateFilePath) ||
                            Path.GetFileNameWithoutExtension(unzippedUpdateFilePath) != Path.GetFileNameWithoutExtension(FilePath))
                        {
                            unzippedUpdateFilePath = WizardHelpers.ExtractUpdate(FilePath, this);
                        }

                        if (!WizardHelpers.IsValidFile(unzippedUpdateFilePath, out var zipFailure))
                        {
                            using (var dlg = new ThreeButtonDialog(new ThreeButtonDialog.Details(
                                                                       SystemIcons.Error, zipFailure, Messages.UPDATES)))
                            {
                                cancel = true;
                                dlg.ShowDialog();
                                return;
                            }
                        }

                        if (!unzippedFiles.Contains(unzippedUpdateFilePath))
                        {
                            unzippedFiles.Add(unzippedUpdateFilePath);
                        }

                        SelectedPatchFilePath = unzippedUpdateFilePath;
                    }
                    else
                    {
                        unzippedUpdateFilePath = null;
                    }

                    if (SelectedPatchFilePath.EndsWith("." + Branding.Update))
                    {
                        SelectedUpdateType = UpdateType.Legacy;
                    }
                    else if (SelectedPatchFilePath.EndsWith("." + Branding.UpdateIso))
                    {
                        SelectedUpdateType = UpdateType.ISO;
                    }

                    AlertFromFileOnDisk      = GetAlertFromFile(SelectedPatchFilePath, out var hasUpdateXml);
                    FileFromDiskHasUpdateXml = hasUpdateXml;
                    PatchFromDisk            = AlertFromFileOnDisk == null
                        ? new KeyValuePair <XenServerPatch, string>(null, null)
                        : new KeyValuePair <XenServerPatch, string>(AlertFromFileOnDisk.Patch, SelectedPatchFilePath);
                }
            }

            if (!cancel) //unsubscribe only if we are really leaving this page
            {
                Updates.RestoreDismissedUpdatesStarted -= Updates_RestoreDismissedUpdatesStarted;
                Updates.CheckForUpdatesStarted         -= CheckForUpdates_CheckForUpdatesStarted;
                Updates.CheckForUpdatesCompleted       -= CheckForUpdates_CheckForUpdatesCompleted;
            }
        }
Esempio n. 12
0
        protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
        {
            if (direction == PageLoadedDirection.Forward)
            {
                if (IsInAutomatedUpdatesMode)
                {
                    var succeed = Updates.CheckForUpdatesSync(this.Parent);
                    cancel = !succeed;
                }
                else if (downloadUpdateRadioButton.Checked)
                {
                    UpdateAlertFromWeb = dataGridViewPatches.SelectedRows.Count > 0
                        ? ((PatchGridViewRow)dataGridViewPatches.SelectedRows[0]).UpdateAlert
                        : null;

                    var distinctHosts = UpdateAlertFromWeb != null ? UpdateAlertFromWeb.DistinctHosts : null;
                    SelectedUpdateType = distinctHosts != null && distinctHosts.Any(Helpers.ElyOrGreater)
                        ? UpdateType.ISO
                        : UpdateType.Legacy;

                    AlertFromFileOnDisk      = null;
                    FileFromDiskHasUpdateXml = false;
                    unzippedUpdateFilePath   = null;
                    SelectedPatchFilePath    = null;
                    PatchFromDisk            = new KeyValuePair <XenServerPatch, string>(null, null);
                }
                else
                {
                    UpdateAlertFromWeb    = null;
                    SelectedPatchFilePath = null;

                    if (!WizardHelpers.IsValidFile(FilePath, out var pathFailure))
                    {
                        using (var dlg = new ErrorDialog(pathFailure)
                        {
                            WindowTitle = Messages.UPDATES
                        })
                        {
                            cancel = true;
                            dlg.ShowDialog();
                            return;
                        }
                    }

                    SelectedPatchFilePath = FilePath;

                    if (Path.GetExtension(FilePath).ToLowerInvariant().Equals(".zip"))
                    {
                        //check if we are installing the update the user sees in the textbox
                        if (unzippedUpdateFilePath == null || !File.Exists(unzippedUpdateFilePath) ||
                            Path.GetFileNameWithoutExtension(unzippedUpdateFilePath) != Path.GetFileNameWithoutExtension(FilePath))
                        {
                            unzippedUpdateFilePath = WizardHelpers.ExtractUpdate(FilePath, this);
                        }

                        if (!WizardHelpers.IsValidFile(unzippedUpdateFilePath, out var zipFailure))
                        {
                            using (var dlg = new ErrorDialog(zipFailure)
                            {
                                WindowTitle = Messages.UPDATES
                            })
                            {
                                cancel = true;
                                dlg.ShowDialog();
                                return;
                            }
                        }

                        if (!UnzippedUpdateFiles.Contains(unzippedUpdateFilePath))
                        {
                            UnzippedUpdateFiles.Add(unzippedUpdateFilePath);
                        }

                        SelectedPatchFilePath = unzippedUpdateFilePath;
                    }
                    else
                    {
                        unzippedUpdateFilePath = null;
                    }

                    if (SelectedPatchFilePath.EndsWith("." + BrandManager.ExtensionUpdate))
                    {
                        SelectedUpdateType = UpdateType.Legacy;
                    }
                    else if (SelectedPatchFilePath.EndsWith("." + InvisibleMessages.ISO_UPDATE))
                    {
                        SelectedUpdateType = UpdateType.ISO;
                    }

                    AlertFromFileOnDisk = GetAlertFromFile(SelectedPatchFilePath, out var hasUpdateXml, out var isUpgradeIso);

                    if (isUpgradeIso)
                    {
                        using (var dlg = new ErrorDialog(Messages.PATCHINGWIZARD_SELECTPATCHPAGE_ERROR_MAINISO))
                            dlg.ShowDialog(this);

                        cancel = true;
                        return;
                    }

                    FileFromDiskHasUpdateXml = hasUpdateXml;
                    PatchFromDisk            = AlertFromFileOnDisk == null
                        ? new KeyValuePair <XenServerPatch, string>(null, null)
                        : new KeyValuePair <XenServerPatch, string>(AlertFromFileOnDisk.Patch, SelectedPatchFilePath);
                }
            }

            if (!cancel) //unsubscribe only if we are really leaving this page
            {
                UnRegisterEvents();
            }
        }