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)))
            {
                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();
            }
        }
 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);
         }
     }
 }
示例#3
0
 private void RunMultipleActions(string title, string startDescription, string endDescription,
     List<AsyncAction> subActions)
 {
     if (subActions.Count > 0)
     {
         using (MultipleAction multipleAction = new MultipleAction(xenConnection, title, startDescription,
                                                                   endDescription, subActions, false, true))
         {
             ActionProgressDialog dialog = new ActionProgressDialog(multipleAction, ProgressBarStyle.Blocks);
             dialog.ShowDialog(Program.MainWindow);
         }
     }
 }
        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();
            }
        }
        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 (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);
                return multipleAction;
            }
        }
        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)
                    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);
        }
示例#7
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);
            }
        }
        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();
        }
示例#9
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;
        }
        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;
        }
示例#11
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;
            }
        }
        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();
        }
        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.ISO && PoolUpdate != null)
                {
                    //Ely or greater: iso update format
                    actionManualMode = new ApplyUpdateAction(new List<Pool_update>() { PoolUpdate }, SelectedServers);
                }
                else
                {
                    //legacy mode
                    if (SelectedUpdateType != UpdateType.ISO)
                        actionManualMode = new ApplyPatchAction(new List<Pool_patch> { Patch }, SelectedServers);
                    else
                        actionManualMode = new InstallSupplementalPackAction(SuppPackVdis, false);
                }

                actions.Add(actionManualMode);
                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);
        }