//private static void BringDown(AsyncAction action, PIF master, bool this_host, int hi) //{ // ForSomeHosts(action, master, this_host, false, hi, BringDown); //} /// <summary> /// Depurpose (set disallow_unplug=false) and remove the IP address from the given PIF. /// </summary> internal static void BringDown(AsyncAction action, PIF pif, int hi) { int mid = (action.PercentComplete + hi) / 2; Depurpose(action, pif, mid); ClearIP(action, pif, hi); }
/// <summary> /// Polls the action regularly and updates the history item's progress from the task's progress, /// scaled to a value between lo and hi. /// </summary> public TaskPoller(AsyncAction action, int lo, int hi) { _action = action; _lo = lo; if (hi < lo) { log.Warn("Squelching progress bar reversal."); hi = lo + 1; } _scale = hi - lo; }
public ActionProgressDialog(AsyncAction action, ProgressBarStyle progressBarStyle) { InitializeComponent(); this.action = action; action.Completed += action_Completed; action.Changed += action_Changed; progressBar1.Style = progressBarStyle; updateStatusLabel(); buttonCancel.Enabled = action.CanCancel; ShowIcon = false; HideTitleBarIcons(); }
/// <summary> /// HTTP PUT file from path to HTTP action f, updating action with progress every 500ms. /// </summary> /// <param name="action">Action on which to update the progress</param> /// <param name="timeout">Timeout value in ms</param> /// <param name="path">path of file to put</param> public static String Put(AsyncAction action, int timeout, string path, string hostname, Delegate f, params object[] p) { Session session = action.Session; action.RelatedTask = XenAPI.Task.create(session, "uploadTask", hostname); try { HTTP.UpdateProgressDelegate progressDelegate = delegate(int percent) { action.Tick(percent, action.Description); }; return Put(progressDelegate, action.GetCancelling, timeout, action.Connection, action.RelatedTask, ref session, path, hostname, f, p); } finally { action.Session = session; Task.destroy(session, action.RelatedTask); } }
private static string GetActionDescription(AsyncAction action) { return !action.StartedRunning ? "" : action.Exception == null ? action.Description : action.Exception is CancelledException ? Messages.CANCELLED_BY_USER : action.Exception.Message; }
/// <summary> /// Build optimize pool list view properly /// </summary> private void BuildRecList() { Program.AssertOnEventThread(); if(_xenObject == null) return; if (Helpers.WlbEnabled(_xenObject.Connection)) { try { if (_xenObject is Pool) { _pool = (Pool)_xenObject; // get any active WLB action action = HelpersGUI.FindActiveWLBAction(_xenObject.Connection); // make sure we are not initializing, starting or stopping WLB if (action is DisableWLBAction || action is EnableWLBAction || action is InitializeWLBAction) return; optimizePoolListView.BeginUpdate(); // check whether optimize pool is running before load optimize pool listview if ((action != null && action is WlbOptimizePoolAction) || (action == null && _pool.other_config.ContainsKey(WlbOptimizationRecommendation.OPTIMIZINGPOOL) && _pool.other_config[WlbOptimizationRecommendation.OPTIMIZINGPOOL] == Messages.IN_PROGRESS)) { //statusLabel.Text = Messages.WLB_OPT_OPTIMIZING; this.applyButton.Text = Messages.WLB_OPT_OPTIMIZING; EnableControls(false, false); } else if (action == null || (action != null && action.GetType() != typeof(WlbRetrieveRecommendationAction))) { this.applyButton.Text = Messages.WLB_OPT_APPLY_RECOMMENDATIONS; // retrieve recommendations, and load optimize pool listview properly WlbRetrieveRecommendationAction optAction = new WlbRetrieveRecommendationAction(_pool); optAction.Completed += this.OptRecRetrieveAction_Completed; optAction.RunAsync(); } } } catch (Failure f) { statusLabel.Text = Messages.WLB_OPT_LOADING_ERROR; log.Error(f, f); } catch (Exception e) { statusLabel.Text = Messages.WLB_OPT_LOADING_ERROR; log.ErrorFormat("There was an error calling retrieve_wlb_recommendations on pool {0}", _pool.name_label); log.Error(e, e); } finally { optimizePoolListView.EndUpdate(); } } else { this.WLBOptDisable(true); } }
private void UpdateActionProgress(AsyncAction action) { progressBar1.Value = action == null ? 0 : action.PercentComplete; labelProgress.Text = action == null ? string.Empty : action.Description; }
public PropertiesDialogClosingEventArgs(AsyncAction action, bool startAction) { StartAction = startAction; Action = action; }
/// <summary> /// Clear the disallow_unplug and ManagementPurpose on the given NIC. /// </summary> private static void Depurpose(AsyncAction action, PIF pif, int hi) { log.DebugFormat("Depurposing PIF {0} {1}...", pif.Name, pif.uuid); action.Description = string.Format(Messages.ACTION_CHANGE_NETWORKING_DEPURPOSING, pif.Name); PIF p = (PIF)pif.Clone(); p.disallow_unplug = false; p.ManagementPurpose = null; p.SaveChanges(action.Session); action.PercentComplete = hi; log.DebugFormat("Depurposed PIF {0} {1}.", pif.Name, pif.uuid); action.Description = string.Format(Messages.ACTION_CHANGE_NETWORKING_DEPURPOSED, pif.Name); }
public override void PageLoaded(PageLoadedDirection direction) { base.PageLoaded(direction); if (_thisPageHasBeenCompleted) { actionManualMode = null; actionsWorker = null; oemWorker = null; return; } if (SelectedUpdateType == UpdateType.NewOem) { InstallOEMUpdates(); return; } //if we reach here it's either UpdateType.NewRetail, UpdateType.Existing or UpdateType.NewSuppPack if (!IsAutomaticMode) { if (SelectedUpdateType != UpdateType.NewSuppPack) actionManualMode = new ApplyPatchAction(new List<Pool_patch> { Patch }, SelectedServers); else actionManualMode = new InstallSupplementalPackAction(SuppPackVdis, false); actionManualMode.Changed += action_Changed; actionManualMode.Completed += action_Completed; textBoxLog.Text = ManualTextInstructions; actionManualMode.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 otherPatch.uuid == Patch.uuid; 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); }
private void UpdateActionDescription(AsyncAction action) { if (action == null) // reset action description { labelProgress.Text = ""; labelProgress.ForeColor = SystemColors.ControlText; } else if (action.StartedRunning) // update description for started actions { labelProgress.Text = GetActionDescription(action); labelProgress.ForeColor = !action.IsCompleted || action.Succeeded ? SystemColors.ControlText : Color.Red; } }
void AddActionToSummary(AsyncAction action) { if (action == null) return; SrDescriptor srDescriptor; actionSrDescriptorDict.TryGetValue(action, out srDescriptor); if (srDescriptor == null) return; if (action.Succeeded) xenTabPageLvmoHbaSummary.SuccessfullyCreatedSRs.Add(srDescriptor); else xenTabPageLvmoHbaSummary.FailedToCreateSRs.Add(srDescriptor); }
private List<string> ExtractApiCallList(AsyncAction myAction) { RbacMethodList rbacMethods = new RbacMethodList(); RbacCollectorProxy.GetProxy(rbacMethods); Session session = new Session(RbacCollectorProxy.GetProxy(rbacMethods), myAction.Connection); myAction.RunExternal(session); return rbacMethods.ConvertAll(c => c.Method.ToLower().Replace('.', '_').Replace("async_", "")); }
private void SetSessionDetails(AsyncAction action) { if (elevatedSession == null || string.IsNullOrEmpty(elevatedUsername) || string.IsNullOrEmpty(elevatedPassword)) return; action.sudoUsername = elevatedUsername; action.sudoPassword = elevatedPassword; action.Session = elevatedSession; }
internal void DoAction(AsyncAction action) { Program.AssertOnEventThread(); action.Changed += action_Changed; action.Completed += action_Completed; Grow(action.RunAsync); }
/// <summary> /// Configure an IP address, management purpose, and set the disallow_unplug flag on the given existing_pif. /// </summary> /// <param name="new_pif">The source of the new IP details</param> /// <param name="existing_pif">The PIF to configure</param> internal static void BringUp(AsyncAction action, PIF new_pif, string new_ip, PIF existing_pif, int hi) { bool primary = string.IsNullOrEmpty(new_pif.ManagementPurpose); int lo = action.PercentComplete; int inc = (hi - lo) / (primary ? 2 : 3); log.DebugFormat("Bringing PIF {0} {1} up as {2}/{3}, {4}, {5}...", existing_pif.Name, existing_pif.uuid, new_ip, new_pif.netmask, new_pif.gateway, new_pif.DNS); action.Description = string.Format(Messages.ACTION_CHANGE_NETWORKING_BRINGING_UP, existing_pif.Name); PIF p = (PIF)existing_pif.Clone(); p.disallow_unplug = !primary; p.ManagementPurpose = new_pif.ManagementPurpose; p.SaveChanges(action.Session); action.PercentComplete = lo + inc; ReconfigureIP(action, new_pif, existing_pif, new_ip, action.PercentComplete + inc); if (!primary) Plug(action, existing_pif, hi); action.Description = string.Format(Messages.ACTION_CHANGE_NETWORKING_BRINGING_UP_DONE, existing_pif.Name); log.DebugFormat("Brought PIF {0} {1} up.", existing_pif.Name, existing_pif.uuid); }
/// <summary> /// Configure an IP address, management purpose, and set the disallow_unplug flag on the given pif, then plug it. /// </summary> internal static void BringUp(AsyncAction action, PIF new_pif, PIF existing_pif, int hi) { BringUp(action, new_pif, new_pif.IP, existing_pif, hi); }
private void CancelAction(AsyncAction action) { Program.AssertOnEventThread(); OnPageUpdated(); action.Changed -= singleAction_Changed; action.Completed -= singleAction_Completed; action.Cancel(); }
/// <summary> /// HTTP GET file from HTTP action f, saving it to path (via a temporary file). /// </summary> /// <param name="action">Action on which to update the progress</param> /// <param name="timeout">Whether to apply a timeout</param> /// <param name="path">Path to save file to.</param> /// <returns>Result of the task used to GET the file</returns> public static String Get(AsyncAction action, bool timeout, string path, string hostname, Delegate f, params object[] p) { return Get(action, timeout, null, path, hostname, f, p); }
private Color GetTextColor(AsyncAction action) { Color textColor; if (action == null || !action.StartedRunning) // not started yet textColor = flickerFreeListBox1.ForeColor; else if (!action.IsCompleted) // in progress textColor = Color.Blue; else textColor = action.Succeeded ? Color.Green : Color.Red; // completed return textColor; }
/// <summary> /// Switch the host's management interface from its current setting over to the given PIF. /// </summary> private static void ReconfigureManagement_(AsyncAction action, PIF pif, int hi) { log.DebugFormat("Switching to PIF {0} {1} for management...", pif.Name, pif.uuid); action.Description = string.Format(Messages.ACTION_CHANGE_NETWORKING_MANAGEMENT_RECONFIGURING, pif.Name); int mid = (hi + action.PercentComplete) / 2; PIF p = (PIF)pif.Clone(); p.disallow_unplug = false; p.ManagementPurpose = null; p.SaveChanges(action.Session); action.PercentComplete = mid; action.RelatedTask = XenAPI.Host.async_management_reconfigure(action.Session, pif.opaque_ref); action.PollToCompletion(mid, hi); log.DebugFormat("Switched to PIF {0} {1} for management.", pif.Name, pif.uuid); action.Description = string.Format(Messages.ACTION_CHANGE_NETWORKING_MANAGEMENT_RECONFIGURED, pif.Name); }
private void UpdateActionProgress(AsyncAction action) { UpdateActionDescription(action); progressBar1.Value = action == null ? 0 : action.PercentComplete; }
public ActionProgressDialog(AsyncAction action, ProgressBarStyle progressBarStyle, bool showTryAgain) : this(action, progressBarStyle) { this.showTryAgain = showTryAgain; }
// // The following functions do puts and gets to and from the filesystem // updating Actions etc where appropriate. // /// <summary> /// HTTP PUT file from path to HTTP action f, updating action with progress every 500ms. /// </summary> /// <param name="action">Action on which to update the progress</param> /// <param name="timeout">Whether to apply a timeout</param> /// <param name="path">path of file to put</param> public static String Put(AsyncAction action, bool timeout, string path, string hostname, Delegate f, params object[] p) { return Put(action, XenAdminConfigManager.Provider.GetProxyTimeout(timeout), path, hostname, f, p); }
/// <summary> /// Apply optimization to a pool /// </summary> /// <param name="sender">object</param> /// <param name="e">EventArgs</param> private void ButtonApply_Click(object sender, EventArgs e) { if (this._pool == null) return; applyButton.Enabled = false; action = HelpersGUI.FindActiveOptAction(_xenObject.Connection); if ((action != null && action.GetType() != typeof(WlbOptimizePoolAction)) || action == null) { new WlbOptimizePoolAction(_pool, _vmOptList, _optId).RunAsync(); // Switch to logs tab, since this action takes a while and there's no feedback on the HA tab Program.MainWindow.SwitchToTab(MainWindow.Tab.History); Program.MainWindow.UpdateToolbars(); } }
private void RunFinalAction(out bool closeWizard) { FinalAction = null; closeWizard = false; // Override the WizardBase: try running the SR create/attach. If it succeeds, close the wizard. // Otherwise show the error and allow the user to adjust the settings and try again. Pool pool = Helpers.GetPoolOfOne(xenConnection); if (pool == null) { log.Error("New SR Wizard: Pool has disappeared"); new ThreeButtonDialog( new ThreeButtonDialog.Details(SystemIcons.Warning, string.Format(Messages.NEW_SR_CONNECTION_LOST, Helpers.GetName(xenConnection)), Messages.XENCENTER)).ShowDialog(this); closeWizard = true; return; } Host master = xenConnection.Resolve(pool.master); if (master == null) { log.Error("New SR Wizard: Master has disappeared"); new ThreeButtonDialog( new ThreeButtonDialog.Details(SystemIcons.Warning, string.Format(Messages.NEW_SR_CONNECTION_LOST, Helpers.GetName(xenConnection)), Messages.XENCENTER)).ShowDialog(this); closeWizard = true; return; } if (_srToReattach != null && !_srToReattach.IsDetached && _srToReattach.Connection == xenConnection) { // Error - cannot reattach attached SR MessageBox.Show(this, String.Format(Messages.STORAGE_IN_USE, _srToReattach.Name, Helpers.GetName(xenConnection)), Text, MessageBoxButtons.OK, MessageBoxIcon.Error); FinishCanceled(); return; } // show warning prompt if required if (!AskUserIfShouldContinue()) { FinishCanceled(); return; } List<AsyncAction> actionList = GetActions(master, m_srWizardType.DisasterRecoveryTask); if (actionList.Count == 1) FinalAction = actionList[0]; else FinalAction = new ParallelAction(xenConnection, Messages.NEW_SR_WIZARD_FINAL_ACTION_TITLE, Messages.NEW_SR_WIZARD_FINAL_ACTION_START, Messages.NEW_SR_WIZARD_FINAL_ACTION_END, actionList); // if this is a Disaster Recovery Task, it could be either a "Find existing SRs" or an "Attach SR needed for DR" case if (m_srWizardType.DisasterRecoveryTask) { closeWizard = true; return; } ProgressBarStyle progressBarStyle = FinalAction is SrIntroduceAction ? ProgressBarStyle.Blocks : ProgressBarStyle.Marquee; ActionProgressDialog dialog = new ActionProgressDialog(FinalAction, progressBarStyle) {ShowCancel = true}; if (m_srWizardType is SrWizardType_LvmoHba) { foreach (var asyncAction in actionList) { asyncAction.Completed += asyncAction_Completed; } ActionProgressDialog closureDialog = dialog; // close dialog even when there's an error for HBA SR type as there will be the Summary page displayed. FinalAction.Completed += (s, ea) => Program.Invoke(Program.MainWindow, () => { if (closureDialog != null) closureDialog.Close(); }); } dialog.ShowDialog(this); if (!FinalAction.Succeeded && FinalAction is SrReattachAction && !_srToReattach.IsDetached) { // reattach failed. Ensure SR is now detached. dialog = new ActionProgressDialog(new SrAction(SrActionKind.Detach, _srToReattach), progressBarStyle); dialog.ShowCancel = false; dialog.ShowDialog(); } // If action failed and frontend wants to stay open, just return if (!FinalAction.Succeeded) { DialogResult = DialogResult.None; FinishCanceled(); if (m_srWizardType.AutoDescriptionRequired) { foreach (var srDescriptor in m_srWizardType.SrDescriptors) { srDescriptor.Description = null; } } return; } // Close wizard closeWizard = true; }
private void buttonResolveAll_Click(object sender, EventArgs e) { List<AsyncAction> actions = new List<AsyncAction>(); foreach (DataGridViewRow row in dataGridView1.Rows) { PreCheckHostRow preCheckHostRow = row as PreCheckHostRow; if (preCheckHostRow != null && preCheckHostRow.Problem != null) { bool cancelled; AsyncAction action = preCheckHostRow.Problem.SolveImmediately(out cancelled); if (action != null) { preCheckHostRow.Enabled = false; actions.Add(action); } } } resolvePrechecksAction = new ParallelAction(Messages.PATCHINGWIZARD_PRECHECKPAGE_RESOLVING_ALL, Messages.PATCHINGWIZARD_PRECHECKPAGE_RESOLVING_ALL, Messages.COMPLETED, actions, true, false); StartResolvePrechecksAction(); }
private void btnOK_Click(object sender, EventArgs e) { // Have any of the fields in the tab pages changed? if (!HasChanged) { Close(); return; } if (!ValidToSave) { // Keep dialog open and allow user to correct the error as // indicated by the balloon tooltip. DialogResult = DialogResult.None; return; } // Yes, save to the LocalXenObject. List<AsyncAction> actions = SaveSettings(); Program.Invoke(Program.MainWindow.GeneralPage, Program.MainWindow.GeneralPage.EnableDisableEdit); // Add a save changes on the beginning of the actions to enact the alterations that were just changes to the xenObjectCopy. // Must come first because some pages' SaveChanges() rely on modifying the object via the xenObjectCopy before their actions are run. actions.Insert(0, new SaveChangesAction(xenObjectCopy, xenObjectBefore, true)); _action = new MultipleAction( connection, string.Format(Messages.UPDATE_PROPERTIES, Helpers.GetName(xenObject).Ellipsise(50)), Messages.UPDATING_PROPERTIES, Messages.UPDATED_PROPERTIES, actions); _action.SetObject(xenObjectCopy); _action.Completed += action_Completed; Close(); if (_startAction) { _action.RunAsync(); } }
private void ExecuteSolution(PreCheckHostRow preCheckHostRow) { bool cancelled; resolvePrechecksAction = preCheckHostRow.Problem.SolveImmediately(out cancelled); if (resolvePrechecksAction != null) { // disable all problems foreach (DataGridViewRow row in dataGridView1.Rows) { PreCheckHostRow preCheckRow = row as PreCheckHostRow; if (preCheckRow != null && preCheckRow.Problem != null) { preCheckRow.Enabled = false; } } StartResolvePrechecksAction(); } else { if (preCheckHostRow.Problem is WarningWithInformationUrl) (preCheckHostRow.Problem as WarningWithInformationUrl).LaunchUrlInBrowser(); else if (preCheckHostRow.Problem is ProblemWithInformationUrl) (preCheckHostRow.Problem as ProblemWithInformationUrl).LaunchUrlInBrowser(); else if (!cancelled) using (var dlg = new ThreeButtonDialog(new ThreeButtonDialog.Details(SystemIcons.Information, string.Format(Messages.PATCHING_WIZARD_SOLVE_MANUALLY, preCheckHostRow.Problem.Description).Replace("\\n", "\n"), Messages.PATCHINGWIZARD_PRECHECKPAGE_TEXT))) { dlg.ShowDialog(this); } } }
protected override void FinishWizard() { Action = new CreateVMAction(xenConnection, page_1_Template.SelectedTemplate, page_1_Template.CopyBiosStrings ? page_1b_BiosLocking.CopyBiosStringsFrom : null, page_2_Name.SelectedName, page_2_Name.SelectedDescription, page_3_InstallationMedia.SelectedInstallMethod, page_3_InstallationMedia.SelectedPvArgs, page_3_InstallationMedia.SelectedCD, page_3_InstallationMedia.SelectedUrl, m_affinity, page_5_CpuMem.SelectedVcpus, page_5_CpuMem.SelectedMemoryDynamicMin, page_5_CpuMem.SelectedMemoryDynamicMax, page_5_CpuMem.SelectedMemoryStaticMax, page_6b_LunPerVdi.MapLunsToVdisRequired ? page_6b_LunPerVdi.MappedDisks : page_6_Storage.SelectedDisks, page_6_Storage.FullCopySR, page_7_Networking.SelectedVifs, page_8_Finish.StartImmediately, VMOperationCommand.WarningDialogHAInvalidConfig, VMOperationCommand.StartDiagnosisForm, gpuCapability ? pageVgpu.GpuGroup : null, gpuCapability ? pageVgpu.VgpuType : null, page_5_CpuMem.SelectedCoresPerSocket, page_CloudConfigParameters.ConfigDriveTemplateText); Action.RunAsync(); base.FinishWizard(); }