예제 #1
0
        private void OpenDatabaseActionCompleted(ActionBase sender)
        {
            VdiOpenDatabaseAction senderAction = (VdiOpenDatabaseAction)sender;

            senderAction.Completed -= OpenDatabaseActionCompleted;

            log.DebugFormat("Metadata database open ({0}). Now start recovering", senderAction.Vdi.Name());

            metadataSession = senderAction.MetadataSession;
            if (metadataSession == null)
            {
                return;
            }

            // assign metadata session to all recover actions
            List <AsyncAction> recoverSubActions = new List <AsyncAction>();

            foreach (var action in actions[senderAction.Vdi])
            {
                if (action is DrRecoverAction)
                {
                    ((DrRecoverAction)action).MetadataSession = metadataSession;
                    recoverSubActions.Add(action);
                }
            }

            multipleRecoverAction = new MultipleAction(Connection,
                                                       String.Format(Messages.DR_WIZARD_RECOVERPAGE_RECOVER_FROM, senderAction.Vdi.Name()),
                                                       String.Format(Messages.DR_WIZARD_RECOVERPAGE_RECOVERING_FROM, senderAction.Vdi.Name()),
                                                       Messages.COMPLETED,
                                                       recoverSubActions);
            multipleRecoverAction.Completed += MultipleRecoverActionCompleted;
            multipleRecoverAction.RunAsync();
        }
예제 #2
0
        private void DoFinalCleanup()
        {
            if (cleanupExecuted)
            {
                return;
            }

            SummaryReport.AddLine("");

            // destroy DR tasks
            DestroyDrTasks();

            // dry-run clean-up
            if (WizardType == DRWizardType.Dryrun)
            {
                DoDryRunCleanup();
            }

            // revert pre-check resolved problems
            if (DRFailoverWizardPrecheckPage1.RevertActions.Count > 0)
            {
                SummaryReport.AddLine(Messages.REVERT_PRECHECK_ACTIONS);
                MultipleAction action = new MultipleAction(xenConnection, Messages.REVERT_PRECHECK_ACTIONS, "", "", DRFailoverWizardPrecheckPage1.RevertActions);
                new Dialogs.ActionProgressDialog(action, ProgressBarStyle.Blocks).ShowDialog();
                foreach (var subAction in DRFailoverWizardPrecheckPage1.RevertActions)
                {
                    SummaryReport.AddActionResult(subAction);
                }
            }
            cleanupExecuted = true;
        }
예제 #3
0
        private void DetachAndForgetSRs()
        {
            if (IntroducedSrs.Count == 0)
            {
                return;
            }

            List <SR> srs = Pool.Connection.ResolveAll(IntroducedSrs);

            List <AsyncAction> actions = new List <AsyncAction>();

            foreach (SR sr in srs)
            {
                actions.Add(new SrAction(SrActionKind.Forget, sr));
            }

            if (actions.Count == 0)
            {
                return;
            }

            var action = new MultipleAction(Pool.Connection, Messages.ACTION_SRS_FORGETTING, Messages.FORGETTING_SRS, Messages.SRS_FORGOTTEN, actions);

            new Dialogs.ActionProgressDialog(action, ProgressBarStyle.Blocks).ShowDialog();
            foreach (var subAction in actions)
            {
                SummaryReport.AddActionResult(subAction);
            }
        }
예제 #4
0
        public AsyncAction SaveSettings()
        {
            List <AsyncAction> actions = new List <AsyncAction>();

            if (HasVCPUChanged)
            {
                vm.VCPUWeight = Convert.ToInt32(_CurrentVCPUWeight);
                if (_OrigVCPUs != nudVCPUs.Value)
                {
                    actions.Add(new ChangeVCPUSettingsAction(vm, Convert.ToInt64(nudVCPUs.Value)));
                }
            }

            if (HasTopologyChanged)
            {
                vm.CoresPerSocket = comboBoxTopology.CoresPerSocket;
            }

            if (HasMemoryChanged)
            {
                if (MROrGreater)
                {
                    actions.Add(memoryAction);  // Calculated in ValidToSave
                }
                else
                {
                    vm.Memory = Convert.ToInt64(this.nudMemory.Value * Util.BINARY_MEGA);
                }
            }

            if (!Program.RunInAutomatedTestMode && vm.power_state != vm_power_state.Halted)
            {
                if (!HasMemoryChanged)
                {
                    new ThreeButtonDialog(new ThreeButtonDialog.Details(SystemIcons.Information, Messages.VM_VCPU_CHANGES_NOT_SUPPORTED_MESSAGE, Messages.VM_LIVE_CHANGES_NOT_SUPPORTED_TITLE)).ShowDialog();
                }
                else if (!MROrGreater)
                {
                    new ThreeButtonDialog(new ThreeButtonDialog.Details(SystemIcons.Information, Messages.VM_VCPU_CHANGES_NOT_SUPPORTED_MESSAGE, Messages.VM_LIVE_CHANGES_NOT_SUPPORTED_TITLE)).ShowDialog();
                }
                // If it is >= Midnight Ride, and memory has changed (which can only happen in the free version),
                // we have already given a message in ValidToSave that the VM will be forcibly rebooted, so no
                // further message is needed here.
            }

            if (actions.Count == 0)
            {
                return(null);
            }
            else if (actions.Count == 1)
            {
                return(actions[0]);
            }
            else
            {
                MultipleAction multipleAction = new MultipleAction(vm.Connection, "", "", "", actions, true);
                return(multipleAction);
            }
        }
예제 #5
0
 private void RunMultipleActions(string title, string startDescription, string endDescription,
                                 List <AsyncAction> subActions)
 {
     if (subActions != null && subActions.Count > 0)
     {
         using (MultipleAction multipleAction = new MultipleAction(xenConnection, title, startDescription,
                                                                   endDescription, subActions, false, true))
         {
             using (var dialog = new ActionProgressDialog(multipleAction, ProgressBarStyle.Blocks))
                 dialog.ShowDialog(Program.MainWindow);
         }
     }
 }
예제 #6
0
        private void RevertResolvedPreChecks()
        {
            var subActions = GetUnwindChangesActions(RollingUpgradeWizardPrecheckPage.PrecheckProblemsActuallyResolved);

            if (subActions.Count > 0)
            {
                using (MultipleAction multipleAction = new MultipleAction(xenConnection, Messages.REVERT_WIZARD_CHANGES,
                                                                          Messages.REVERTING_WIZARD_CHANGES,
                                                                          Messages.REVERTED_WIZARD_CHANGES,
                                                                          subActions, false, true))
                {
                    using (var dialog = new ActionProgressDialog(multipleAction, ProgressBarStyle.Blocks))
                        dialog.ShowDialog(Program.MainWindow);
                }
            }
        }
예제 #7
0
        private void RevertResolvedPreChecks()
        {
            List <AsyncAction> subActions = GetUnwindChangesActions();

            if (subActions.Count > 0)
            {
                using (MultipleAction multipleAction = new MultipleAction(xenConnection, Messages.REVERT_WIZARD_CHANGES,
                                                                          Messages.REVERTING_WIZARD_CHANGES,
                                                                          Messages.REVERTED_WIZARD_CHANGES,
                                                                          subActions, true))
                {
                    ActionProgressDialog dialog = new ActionProgressDialog(multipleAction, ProgressBarStyle.Blocks);
                    dialog.ShowDialog(Program.MainWindow);
                }
            }
        }
예제 #8
0
        private void okButton_Click(object sender, EventArgs e)
        {
            List <AsyncAction> actions = GetActions();

            if (actions.Count == 0)
            {
                return;
            }

            var multipleAction = new MultipleAction(
                connection,
                string.Format(Messages.UPDATE_PROPERTIES, Helpers.GetName(connection).Ellipsise(50)),
                Messages.UPDATING_PROPERTIES,
                Messages.UPDATED_PROPERTIES,
                actions, true);

            multipleAction.RunAsync();
        }
예제 #9
0
        private void StartUploading()
        {
            // reset progress bar and action progress description
            UpdateActionProgress(null);

            // start the upload
            var actions = uploadActions.Values.Where(a => a != null).ToList();

            if (actions.Count == 0)
            {
                return;
            }

            using (var multipleAction = new MultipleAction(Connection, Messages.UPLOAD_PATCH_TITLE, Messages.UPLOAD_PATCH_DESCRIPTION, Messages.UPLOAD_PATCH_END_DESCRIPTION, actions, true, true, true))
            {
                multipleAction.Completed += multipleAction_Completed;
                multipleAction.RunAsync();
            }
        }
예제 #10
0
        public AsyncAction SaveSettings()
        {
            List <AsyncAction> actions = new List <AsyncAction>();

            if (HasVCPUWeightChanged)
            {
                vm.VCPUWeight = Convert.ToInt32(_CurrentVCPUWeight);
            }
            if (HasCapChanged)
            {
                Dictionary <String, String> setCap = new Dictionary <String, String>();
                setCap.Add("cap", Convert.ToString(trackBar1.Value));
                XenAPI.VM.set_VCPUs_params(vm.Connection.Session, vm.opaque_ref, setCap);
            }
            if (HasVCPUChanged || HasVCPUsAtStartupChanged)
            {
                actions.Add(new ChangeVCPUSettingsAction(vm, SelectedVcpusMax, SelectedVcpusAtStartup));
            }

            if (HasTopologyChanged)
            {
                vm.CoresPerSocket = comboBoxTopology.CoresPerSocket;
            }

            if (HasMemoryChanged)
            {
                actions.Add(memoryAction);  // Calculated in ValidToSave
            }

            if (actions.Count == 0)
            {
                return(null);
            }
            else if (actions.Count == 1)
            {
                return(actions[0]);
            }
            else
            {
                MultipleAction multipleAction = new MultipleAction(vm.Connection, "", "", "", actions, true);
                return(multipleAction);
            }
        }
예제 #11
0
        private void MultipleRecoverActionCompleted(ActionBase sender)
        {
            MultipleAction senderAction = (MultipleAction)sender;

            senderAction.Completed -= MultipleRecoverActionCompleted;

            log.Debug("Finished recovery. Close metadata database");
            // logout from metadata session
            metadataSession.logout();

            Program.BeginInvoke(this, () =>
            {
                if (objectsToBeRecovered == 0) // finished recovering, now start VMs, if required
                {
                    switch (startActionAfterRecovery)
                    {
                    case StartActionAfterRecovery.Start:
                        StartRecoveredVMs(false);
                        break;

                    case StartActionAfterRecovery.StartPaused:
                        StartRecoveredVMs(true);
                        break;

                    default:
                        progressBar1.Value = 100;
                        OnPageUpdated();
                        if (ReportLineGot != null)
                        {
                            ReportLineGot(labelTitle.Text, 0, true);
                        }
                        break;
                    }
                }
                else // recover next pool
                {
                    RecoverNextPool();
                }
            });
        }
예제 #12
0
        private bool SaveChanges()
        {
            if (!HasChanged())
            {
                return(false);
            }

            var mem = memorySpinner.Value;

            DialogResult dialogResult;

            using (var dlg = new ThreeButtonDialog(
                       new ThreeButtonDialog.Details(SystemIcons.Warning, Messages.CONFIRM_CHANGE_CONTROL_DOMAIN_MEMORY, Messages.XENCENTER),
                       ThreeButtonDialog.ButtonYes,
                       ThreeButtonDialog.ButtonNo))
            {
                dialogResult = dlg.ShowDialog(this);
            }

            if (DialogResult.Yes != dialogResult)
            {
                return(false);
            }

            var actions = new List <AsyncAction>();
            var action  = new ChangeControlDomainMemoryAction(host, (long)mem, false);

            actions.Add(action);

            actions.Add(new RebootHostAction(host, AddHostToPoolCommand.NtolDialog));

            var multipleAction = new MultipleAction(connection,
                                                    string.Format(Messages.ACTION_CHANGE_CONTROL_DOMAIN_MEMORY, host.Name),
                                                    string.Format(Messages.ACTION_CHANGE_CONTROL_DOMAIN_MEMORY, host.Name),
                                                    Messages.COMPLETED, actions, true, false, true);

            multipleAction.RunAsync();
            return(true);
        }
예제 #13
0
        public AsyncAction SaveSettings()
        {
            List <AsyncAction> actions = new List <AsyncAction>();

            if (HasVCPUWeightChanged)
            {
                vm.VCPUWeight = Convert.ToInt32(_CurrentVCPUWeight);
            }

            if (HasVCPUChanged || HasVCPUsAtStartupChanged)
            {
                actions.Add(new ChangeVCPUSettingsAction(vm, SelectedVcpusMax, SelectedVcpusAtStartup));
            }

            if (HasTopologyChanged)
            {
                vm.CoresPerSocket = comboBoxTopology.CoresPerSocket;
            }

            if (HasMemoryChanged)
            {
                actions.Add(memoryAction);  // Calculated in ValidToSave
            }

            if (actions.Count == 0)
            {
                return(null);
            }
            else if (actions.Count == 1)
            {
                return(actions[0]);
            }
            else
            {
                MultipleAction multipleAction = new MultipleAction(vm.Connection, "", "", "", actions, true);
                return(multipleAction);
            }
        }
예제 #14
0
        public void RunCreate(SelectedItem selection)
        {
            //判断是否有足够空间创建输入数量的虚拟机
            VM                   temp   = selection.XenObject as VM;
            List <VBD>           vbds   = selection.Connection.ResolveAll <VBD>(temp.VBDs);
            List <VDI>           vdis   = new List <VDI>();
            Dictionary <VDI, SR> vdi_sr = new Dictionary <VDI, SR>();

            if (Number > 0)
            {
                //取所有的vdi
                foreach (VBD vbd in vbds)
                {
                    if (selection.Connection.Resolve <VDI>(vbd.VDI) != null)
                    {
                        vdis.Add(selection.Connection.Resolve <VDI>(vbd.VDI));
                    }
                }
                //用Dictionary保存每个vdi对应的sr,vdi-sr
                foreach (VDI vdi in vdis)
                {
                    vdi_sr.Add(vdi, selection.Connection.Resolve <SR>(vdi.SR));
                }
                //用List保存所有相同SR的vdi,计算出能创建的最多个数后保存到Dictionary中,然后清空List
                long                 allvdisize       = 0;
                long                 free_sr_size     = 0;
                long                 storage_overhead = 0;
                List <VDI>           samevdis         = new List <VDI>();
                Dictionary <SR, int> sr_vdinum        = new Dictionary <SR, int>();
                for (int i = 0; i < vdis.Count; i++)
                {
                    for (int j = i; j < vdis.Count; j++)
                    {
                        if (vdi_sr[vdis[i]] == vdi_sr[vdis[j]])
                        {
                            samevdis.Add(vdis[j]);
                        }
                    }
                    foreach (VDI vdi in samevdis)
                    {
                        allvdisize += vdi.virtual_size;
                    }
                    foreach (VDI vdi in selection.Connection.ResolveAll <VDI>(vdi_sr[samevdis[0]].VDIs))
                    {
                        storage_overhead += vdi.virtual_size;
                    }
                    free_sr_size = vdi_sr[samevdis[0]].FreeSpace;
                    sr_vdinum.Add(vdi_sr[samevdis[0]], Convert.ToInt32(free_sr_size / allvdisize));
                    foreach (VDI vdi in samevdis)
                    {
                        vdi_sr.Remove(vdi);
                        vdis.Remove(vdi);
                    }
                    samevdis.Clear();
                    i = -1;
                }
                if (Number > sr_vdinum.Values.Min())
                {
                    new NotEnoughStorageWarningDialog().ShowDialog();
                    return;
                }
            }
            List <AsyncAction> actions = new List <AsyncAction>();

            for (int i = 0; i < Number; i++)
            {
                var createAction = new CreateVMFastAction(selection.Connection, selection.XenObject as VM);
//                createAction.Completed += createAction_Completed;
                actions.Add(createAction);
            }
            MultipleAction multiAction = new MultipleAction(selectedItem.Connection, Messages.INSTANT_CREATE_VMS, Messages.INSTANT_CREATE_VMS_START, Messages.INSTANT_CREATE_VMS_FINISH, actions);

            multiAction.RunAsync();
        }
예제 #15
0
        protected override void FinishWizard()
        {
            AsyncAction action;

            if (bugToolPageDestination1.Upload)
            {
                // The MultipleAction is only used as a wrapper, we will suppress its history and expose the sub-actions in the history
                List <AsyncAction>    subActions = new List <AsyncAction>();
                ZipStatusReportAction zipAction  = new ZipStatusReportAction(bugToolPageRetrieveData.OutputFolder, bugToolPageDestination1.OutputFile, false);
                subActions.Add(zipAction);
                UploadServerStatusReportAction uploadAction = new UploadServerStatusReportAction(bugToolPageDestination1.OutputFile,   // tmp folder
                                                                                                 bugToolPageDestination1.UploadToken,  // upload token
                                                                                                 bugToolPageDestination1.CaseNumber,   // case id
                                                                                                 Registry.HealthCheckUploadDomainName, // domain name
                                                                                                 false);                               // suppressHistory
                subActions.Add(uploadAction);
                action = new MultipleAction(null, Messages.BUGTOOL_SAVING, Messages.BUGTOOL_SAVING, Messages.COMPLETED, subActions, true);
            }
            else
            {
                action = new ZipStatusReportAction(bugToolPageRetrieveData.OutputFolder, bugToolPageDestination1.OutputFile, false);
            }

            action.RunAsync();

            log.Debug("Cleaning up crash dump logs on server");
            var capabilities = bugToolPageSelectCapabilities1.Capabilities;

            foreach (Capability c in capabilities)
            {
                if (c.Key == "host-crashdump-dumps" && c.Checked)
                {
                    var hostList = bugToolPageSelectHosts1.SelectedHosts;
                    if (!hostList.Any(h => h.HasCrashDumps()))
                    {
                        break;
                    }

                    DialogResult result;
                    using (var dlg = new ThreeButtonDialog(
                               new ThreeButtonDialog.Details(null, Messages.REMOVE_CRASHDUMP_QUESTION, Messages.REMOVE_CRASHDUMP_FILES),
                               ThreeButtonDialog.ButtonYes,
                               ThreeButtonDialog.ButtonNo))
                    {
                        result = dlg.ShowDialog(this);
                    }
                    if (result == DialogResult.Yes)
                    {
                        foreach (Host host in hostList)
                        {
                            if (host != null && host.HasCrashDumps())
                            {
                                new Actions.DestroyHostCrashDumpAction(host).RunAsync();
                            }
                        }
                    }
                    break;
                }
            }

            base.FinishWizard();
        }
예제 #16
0
        public override void PageLoaded(PageLoadedDirection direction)
        {
            base.PageLoaded(direction);

            if (_thisPageHasBeenCompleted)
            {
                actionsWorker = null;
                return;
            }

            if (!IsAutomaticMode)
            {
                textBoxLog.Text = ManualTextInstructions;

                List <AsyncAction> actions = new List <AsyncAction>();

                if (SelectedUpdateType == UpdateType.ISO && PoolUpdate != null)
                {
                    //Ely or greater: iso update format
                    foreach (var server in SelectedServers)
                    {
                        actions.Add(new ApplyUpdateAction(PoolUpdate, server));
                    }
                }
                else
                {
                    //legacy mode
                    if (SelectedUpdateType != UpdateType.ISO)
                    {
                        foreach (var server in SelectedServers)
                        {
                            actions.Add(new ApplyPatchAction(Patch, server));
                        }
                    }
                    else
                    {
                        actions.Add(new InstallSupplementalPackAction(SuppPackVdis, false));
                    }
                }

                if (RemoveUpdateFile && SelectedUpdateType != UpdateType.ISO)
                {
                    foreach (Pool pool in SelectedPools)
                    {
                        actions.Add(new PoolPatchCleanAction(pool, Patch, false));
                    }
                }

                using (var multipleAction = new MultipleAction(Connection, "", "", "", actions, true, true, true))
                {
                    multipleAction.Changed   += action_Changed;
                    multipleAction.Completed += action_Completed;
                    multipleAction.RunAsync();
                }
                return;
            }

            _nextEnabled = false;
            OnPageUpdated();

            List <PlanAction> planActions = new List <PlanAction>();

            foreach (Pool pool in SelectedPools)
            {
                var  poolHosts = new List <Host>(pool.Connection.Cache.Hosts);
                Host master    = SelectedServers.Find(host => host.IsMaster() && poolHosts.Contains(host));

                //For Ely or greater: ISO updates only
                if (SelectedUpdateType == UpdateType.ISO && Helpers.ElyOrGreater(pool.Connection)) //updates for Ely (or higher) are always ISO
                {
                    var poolUpdates = new List <Pool_update>(pool.Connection.Cache.Pool_updates);
                    var poolUpdate  = poolUpdates.FirstOrDefault(u => u != null && string.Equals(u.uuid, PoolUpdate.uuid, StringComparison.OrdinalIgnoreCase));

                    //master first
                    if (master != null && !poolUpdate.AppliedOn(master))
                    {
                        planActions.AddRange(CompilePoolUpdateActionList(master, poolUpdate));
                    }

                    //other hosts
                    foreach (var host in SelectedServers.Where(s => poolHosts.Contains(s) && !s.IsMaster() && !poolUpdate.AppliedOn(s)).ToList())
                    {
                        planActions.AddRange(CompilePoolUpdateActionList(host, poolUpdate));
                    }
                }
                // Legacy (pre-Ely) case: either ISO for supplemental packs (Pool_patch == null) or patch (Pool_patch != null)
                else
                {
                    Pool_patch poolPatch = null;

                    if (SelectedUpdateType != UpdateType.ISO)
                    {
                        List <Pool_patch> poolPatches = new List <Pool_patch>(pool.Connection.Cache.Pool_patches);

                        poolPatch = poolPatches.Find(delegate(Pool_patch otherPatch)
                        {
                            if (Patch != null)
                            {
                                return(string.Equals(otherPatch.uuid, Patch.uuid, StringComparison.OrdinalIgnoreCase));
                            }
                            return(false);
                        });
                    }

                    //master first
                    if (master != null && (poolPatch == null || poolPatch.AppliedOn(master) == DateTime.MaxValue))
                    {
                        planActions.AddRange(CompileActionList(master, poolPatch));
                    }

                    foreach (Host server in SelectedServers)
                    {
                        if (poolHosts.Contains(server))
                        {
                            if (!server.IsMaster())
                            {
                                // check patch isn't already applied here
                                if (poolPatch == null || poolPatch.AppliedOn(server) == DateTime.MaxValue)
                                {
                                    planActions.AddRange(CompileActionList(server, poolPatch));
                                }
                            }
                        }
                    }

                    if (RemoveUpdateFile)
                    {
                        planActions.Add(new RemoveUpdateFile(pool, poolPatch));
                    }
                }
            } //end pool in foreach

            planActions.Add(new UnwindProblemsAction(ProblemsResolvedPreCheck));

            actionsWorker         = new BackgroundWorker();
            actionsWorker.DoWork += new DoWorkEventHandler(PatchingWizardAutomaticPatchWork);
            actionsWorker.WorkerReportsProgress      = true;
            actionsWorker.ProgressChanged           += new ProgressChangedEventHandler(actionsWorker_ProgressChanged);
            actionsWorker.RunWorkerCompleted        += new RunWorkerCompletedEventHandler(actionsWorker_RunWorkerCompleted);
            actionsWorker.WorkerSupportsCancellation = true;
            actionsWorker.RunWorkerAsync(planActions);
        }
예제 #17
0
        private void TryUploading()
        {
            // reset progress bar and action progress description
            UpdateActionProgress(null);

            // Check if we can upload the patches to the masters if it is necessary.
            // This check is only available for Cream or greater hosts.
            // If we can upload (i.e. there is enough disk space) then start the upload.
            // Otherwise display error.
            canUpload             = true;
            diskSpaceRequirements = null;
            var diskSpaceActions = new List <AsyncAction>();

            foreach (Host master in SelectedMasters.Where(master => Helpers.CreamOrGreater(master.Connection) && !Helpers.ElyOrGreater(master.Connection)))
            {
                AsyncAction action = null;
                switch (SelectedUpdateType)
                {
                case UpdateType.NewRetail:
                    if (CanUploadUpdateOnHost(SelectedNewPatchPath, master))
                    {
                        action = new CheckDiskSpaceForPatchUploadAction(master, SelectedNewPatchPath, true);
                    }
                    break;

                case UpdateType.Existing:
                    if (SelectedExistingPatch != null && !PatchExistsOnPool(SelectedExistingPatch, master))
                    {
                        action = new CheckDiskSpaceForPatchUploadAction(master, SelectedExistingPatch, true);
                    }
                    break;
                }

                if (action != null)
                {
                    action.Changed += delegate
                    {
                        Program.Invoke(Program.MainWindow, () => UpdateActionDescription(action));
                    };
                    diskSpaceActions.Add(action);
                }
            }

            if (diskSpaceActions.Count == 0)
            {
                StartUploading();
                return;
            }

            using (var multipleAction = new MultipleAction(Connection, "", "", "", diskSpaceActions, true, true, true))
            {
                multipleAction.Completed += delegate
                {
                    Program.Invoke(Program.MainWindow, () =>
                    {
                        if (multipleAction.Exception is NotEnoughSpaceException)
                        {
                            canUpload             = false;
                            diskSpaceRequirements = (multipleAction.Exception as NotEnoughSpaceException).DiskSpaceRequirements;
                        }
                        UpdateButtons();
                        OnPageUpdated();
                        if (canUpload)
                        {
                            StartUploading();
                        }
                    });
                };
                multipleAction.RunAsync();
            }
        }
        public override void PageLoaded(PageLoadedDirection direction)
        {
            base.PageLoaded(direction);

            if (_thisPageHasBeenCompleted)
            {
                actionManualMode = null;
                actionsWorker    = null;
                return;
            }

            if (!IsAutomaticMode)
            {
                textBoxLog.Text = ManualTextInstructions;

                List <AsyncAction> actions = new List <AsyncAction>();
                if (SelectedUpdateType != UpdateType.NewSuppPack)
                {
                    actionManualMode = new ApplyPatchAction(new List <Pool_patch> {
                        Patch
                    }, SelectedServers);
                }
                else
                {
                    actionManualMode = new InstallSupplementalPackAction(SuppPackVdis, false);
                }

                actions.Add(actionManualMode);
                if (RemoveUpdateFile && SelectedUpdateType != UpdateType.NewSuppPack)
                {
                    foreach (Pool pool in SelectedPools)
                    {
                        actions.Add(new PoolPatchCleanAction(pool, Patch, false));
                    }
                }

                using (var multipleAction = new MultipleAction(Connection, "", "", "", actions, true, true, true))
                {
                    multipleAction.Changed   += action_Changed;
                    multipleAction.Completed += action_Completed;
                    multipleAction.RunAsync();
                }
                return;
            }

            _nextEnabled = false;
            OnPageUpdated();

            List <PlanAction> planActions = new List <PlanAction>();

            foreach (Pool pool in SelectedPools)
            {
                Pool_patch poolPatch = null;
                if (SelectedUpdateType != UpdateType.NewSuppPack)
                {
                    List <Pool_patch> poolPatches = new List <Pool_patch>(pool.Connection.Cache.Pool_patches);
                    poolPatch = poolPatches.Find(delegate(Pool_patch otherPatch)
                    {
                        if (Patch != null)
                        {
                            return(string.Equals(otherPatch.uuid, Patch.uuid, StringComparison.OrdinalIgnoreCase));
                        }
                        return(false);
                    });
                }

                List <Host> poolHosts = new List <Host>(pool.Connection.Cache.Hosts);
                Host        master    = SelectedServers.Find(host => host.IsMaster() && poolHosts.Contains(host));
                if (master != null && (poolPatch == null || poolPatch.AppliedOn(master) == DateTime.MaxValue))
                {
                    planActions.AddRange(CompileActionList(master, poolPatch));
                }
                foreach (Host server in SelectedServers)
                {
                    if (poolHosts.Contains(server))
                    {
                        if (!server.IsMaster())
                        {
                            // check patch isn't already applied here
                            if (poolPatch == null || poolPatch.AppliedOn(server) == DateTime.MaxValue)
                            {
                                planActions.AddRange(CompileActionList(server, poolPatch));
                            }
                        }
                    }
                }
                if (RemoveUpdateFile)
                {
                    planActions.Add(new RemoveUpdateFile(pool, poolPatch));
                }
            }
            planActions.Add(new UnwindProblemsAction(ProblemsResolvedPreCheck));

            actionsWorker         = new BackgroundWorker();
            actionsWorker.DoWork += new DoWorkEventHandler(PatchingWizardAutomaticPatchWork);
            actionsWorker.WorkerReportsProgress      = true;
            actionsWorker.ProgressChanged           += new ProgressChangedEventHandler(actionsWorker_ProgressChanged);
            actionsWorker.RunWorkerCompleted        += new RunWorkerCompletedEventHandler(actionsWorker_RunWorkerCompleted);
            actionsWorker.WorkerSupportsCancellation = true;
            actionsWorker.RunWorkerAsync(planActions);
        }
예제 #19
0
        protected override void FinishWizard()
        {
            // If the user has chosen a file that already exists, get confirmation
            string path = bugToolPageDestination1.OutputFile;

            if (File.Exists(path))
            {
                DialogResult dialogResult;
                using (var dlg = new ThreeButtonDialog(
                           new ThreeButtonDialog.Details(SystemIcons.Warning, string.Format(Messages.FILE_X_EXISTS_OVERWRITE, path), Messages.XENCENTER),
                           ThreeButtonDialog.ButtonOK,
                           new ThreeButtonDialog.TBDButton(Messages.CANCEL, DialogResult.Cancel, ThreeButtonDialog.ButtonType.CANCEL, true)))
                {
                    dialogResult = dlg.ShowDialog(this);
                }
                if (dialogResult != DialogResult.OK)
                {
                    FinishCanceled();
                    return;
                }
            }

            // Check we can write to the destination file - otherwise we only find out at the
            // end of the ZipStatusReportAction, and the downloaded server files are lost,
            // and the user will have to run the wizard again.
            try
            {
                using (FileStream temp = File.OpenWrite(path))
                {
                    // Yay, it worked
                }
            }
            catch (Exception exn)
            {
                // Failure
                using (var dlg = new ThreeButtonDialog(
                           new ThreeButtonDialog.Details(
                               SystemIcons.Error,
                               string.Format(Messages.COULD_NOT_WRITE_FILE, path, exn.Message),
                               Messages.XENCENTER)))
                {
                    dlg.ShowDialog(this);
                }
                FinishCanceled();
                return;
            }

            AsyncAction action;

            if (bugToolPageDestination1.Upload)
            {
                // The MultipleAction is only used as a wrapper, we will suppress its history and expose the sub-actions in the history
                List <AsyncAction>    subActions = new List <AsyncAction>();
                ZipStatusReportAction zipAction  = new ZipStatusReportAction(bugToolPageRetrieveData.OutputFolder, bugToolPageDestination1.OutputFile, false);
                subActions.Add(zipAction);
                UploadServerStatusReportAction uploadAction = new UploadServerStatusReportAction(bugToolPageDestination1.OutputFile,   // tmp folder
                                                                                                 bugToolPageDestination1.UploadToken,  // upload token
                                                                                                 bugToolPageDestination1.CaseNumber,   // case id
                                                                                                 Registry.HealthCheckUploadDomainName, // domain name
                                                                                                 false);                               // suppressHistory
                subActions.Add(uploadAction);
                action = new MultipleAction(null, Messages.BUGTOOL_SAVING, Messages.BUGTOOL_SAVING, Messages.COMPLETED, subActions, true);
            }
            else
            {
                action = new ZipStatusReportAction(bugToolPageRetrieveData.OutputFolder, bugToolPageDestination1.OutputFile, false);
            }

            action.RunAsync();


            // Save away the output path for next time
            XenAdmin.Properties.Settings.Default.ServerStatusPath = bugToolPageDestination1.OutputFile;

            log.Debug("Cleaning up crash dump logs on server");
            var capabilities = bugToolPageSelectCapabilities1.Capabilities;

            foreach (Capability c in capabilities)
            {
                if (c.Key == "host-crashdump-dumps" && c.Checked)
                {
                    var hostList = bugToolPageSelectHosts1.SelectedHosts;
                    if (!hostList.Any(h => h.HasCrashDumps()))
                    {
                        break;
                    }

                    DialogResult result;
                    using (var dlg = new ThreeButtonDialog(
                               new ThreeButtonDialog.Details(null, Messages.REMOVE_CRASHDUMP_QUESTION, Messages.REMOVE_CRASHDUMP_FILES),
                               ThreeButtonDialog.ButtonYes,
                               ThreeButtonDialog.ButtonNo))
                    {
                        result = dlg.ShowDialog(this);
                    }
                    if (result == DialogResult.Yes)
                    {
                        foreach (Host host in hostList)
                        {
                            if (host != null && host.HasCrashDumps())
                            {
                                new Actions.DestroyHostCrashDumpAction(host).RunAsync();
                            }
                        }
                    }
                    break;
                }
            }

            base.FinishWizard();
        }