protected override void ExecuteCore(SelectedItemCollection selection) { VM vm = (VM)selection[0].XenObject; using (var dlg = new ThreeButtonDialog( new ThreeButtonDialog.Details( SystemIcons.Warning, string.Format(Messages.CONVERT_TEMPLATE_DIALOG_TEXT, vm.Name().Ellipsise(25)), Messages.CONVERT_TO_TEMPLATE), new ThreeButtonDialog.TBDButton(Messages.CONVERT, DialogResult.OK, ThreeButtonDialog.ButtonType.ACCEPT, true), ThreeButtonDialog.ButtonCancel)) { if (dlg.ShowDialog() == DialogResult.OK) { List <AsyncAction> actions = new List <AsyncAction>(); actions.Add(new SetVMOtherConfigAction(vm.Connection, vm, "instant", "true")); actions.Add(new VMToTemplateAction(vm)); XenDialogBase.CloseAll(vm); RunMultipleActions(actions, string.Format(Messages.ACTION_VM_TEMPLATIZING_TITLE, vm.Name()), Messages.ACTION_VM_TEMPLATIZING, Messages.ACTION_VM_TEMPLATIZED, true); } } }
private static void Connection_ConnectionStateChanged(IXenConnection conn) { if (conn.IsConnected) { return; } // Close dialogs on termination Program.Invoke(Program.MainWindow, () => XenDialogBase.CloseAll(conn)); }
private void DoDisconnect(IXenConnection connection) { string msg = string.Format(Messages.CONNECTION_CLOSED_NOTICE_TEXT, connection.Hostname); ActionBase notice = new ActionBase(msg, msg, false, true); notice.Pool = Helpers.GetPoolOfOne(connection); notice.Host = Helpers.GetMaster(connection); log.Warn($"Connection to {connection.Hostname} closed."); MainWindowCommandInterface.CloseActiveWizards(connection); XenDialogBase.CloseAll(connection); connection.EndConnect(); MainWindowCommandInterface.SaveServerList(); }
private static void Connection_ConnectionStateChanged(object sender, EventArgs e) { // Close dialogs on termination IXenConnection connection = (IXenConnection)sender; if (connection.IsConnected) { return; } Program.Invoke(Program.MainWindow, delegate() { XenDialogBase.CloseAll(connection); }); }
protected override void ExecuteCore(SelectedItemCollection selection) { AssertOperationAllowsExecution(); string title = Messages.ACTION_VMS_RESUMING_ON_TITLE; string startDescription = Messages.ACTION_VMS_RESUMING_ON_TITLE; string endDescription = Messages.ACTION_VM_RESUMED; List <AsyncAction> actions = new List <AsyncAction>(); if (_operation == vm_operations.pool_migrate) { title = Messages.ACTION_VMS_MIGRATING_TITLE; startDescription = Messages.ACTION_VMS_MIGRATING_TITLE; endDescription = Messages.ACTION_VM_MIGRATED; foreach (VM vm in selection.AsXenObjects <VM>(CanExecute)) { XenDialogBase.CloseAll(vm); Host host = GetHost(vm); actions.Add(new VMMigrateAction(vm, host)); } } else if (_operation == vm_operations.start_on) { title = Messages.ACTION_VMS_STARTING_ON_TITLE; startDescription = Messages.ACTION_VMS_STARTING_ON_TITLE; endDescription = Messages.ACTION_VM_STARTED; foreach (VM vm in selection.AsXenObjects <VM>(CanExecute)) { Host host = GetHost(vm); actions.Add(new VMStartOnAction(vm, host, WarningDialogHAInvalidConfig, StartDiagnosisForm)); } } else if (_operation == vm_operations.resume_on) { title = Messages.ACTION_VMS_RESUMING_ON_TITLE; startDescription = Messages.ACTION_VMS_RESUMING_ON_TITLE; endDescription = Messages.ACTION_VM_RESUMED; foreach (VM vm in selection.AsXenObjects <VM>(CanExecute)) { Host host = GetHost(vm); actions.Add(new VMResumeOnAction(vm, host, WarningDialogHAInvalidConfig, StartDiagnosisForm)); } } RunMultipleActions(actions, title, startDescription, endDescription, true); }
protected override void Run() { if (vmOptList.Count == 0) { log.ErrorFormat("{0} has no VMs need to be optimized", Helpers.GetName(Pool)); return; } this.Description = Messages.ACTION_WLB_POOL_OPTIMIZING; try { log.Debug("Optimizing " + Pool.Name()); // for checking whether to display recommendations on optimize pool listview Helpers.SetOtherConfig(this.Session, this.Pool, WlbOptimizationRecommendation.OPTIMIZINGPOOL, Messages.IN_PROGRESS); int start = 0; int each = 90 / vmOptList.Count; foreach (KeyValuePair <VM, WlbOptimizationRecommendation> vmItem in vmOptList) { VM vm = vmItem.Key; if (vmItem.Key.is_control_domain) { log.Debug(vmItem.Value.powerOperation + " " + Helpers.GetName(vmItem.Value.toHost)); Host fromHost = vmItem.Value.fromHost; Helpers.SetOtherConfig(fromHost.Connection.Session, fromHost, WlbOptimizationRecommendation.OPTIMIZINGPOOL, vmItem.Value.recId.ToString()); AsyncAction hostAction = null; int waitingInterval = 10 * 1000; // default to 10s if (vmItem.Value.fromHost.IsLive()) { hostAction = new ShutdownHostAction(fromHost, AddHostToPoolCommand.NtolDialog); } else { hostAction = new HostPowerOnAction(fromHost); waitingInterval = 30 * 1000; // wait for 30s } hostAction.Completed += HostAction_Completed; hostAction.RunAsync(); while (!moveToNext) { if (!String.IsNullOrEmpty(hostActionError)) { throw new Exception(hostActionError); } else { //wait System.Threading.Thread.Sleep(waitingInterval); } } } else { log.Debug("Migrating VM " + vm.Name()); Host toHost = vmItem.Value.toHost; try { // check if there is a conflict with HA, start optimize if we can RelocateVmWithHa(this, vm, toHost, start, start + each, vmItem.Value.recId); } catch (Failure f) { // prompt to user if ha notl can be raised, if yes, continue long newNtol; if (RaiseHANotl(vm, f, out newNtol)) { DelegatedAsyncAction action = new DelegatedAsyncAction(vm.Connection, Messages.HA_LOWERING_NTOL, null, null, delegate(Session session) { // Set new ntol, then retry action XenAPI.Pool.set_ha_host_failures_to_tolerate(session, this.Pool.opaque_ref, newNtol); // ntol set succeeded, start new action Program.Invoke(Program.MainWindow, () => XenDialogBase.CloseAll(vm)); new VMMigrateAction(vm, toHost).RunAsync(); }); action.RunAsync(); } else { Helpers.SetOtherConfig(this.Session, this.Pool, WlbOptimizationRecommendation.OPTIMIZINGPOOL, Messages.WLB_OPT_FAILED); this.Description = Messages.WLB_OPT_FAILED; throw; } } } start += each; // stop if user cancels optimize pool if (Cancelling) { throw new CancelledException(); } } this.Description = Messages.WLB_OPT_OK_NOTICE_TEXT; Helpers.SetOtherConfig(this.Session, this.Pool, WlbOptimizationRecommendation.OPTIMIZINGPOOL, optId); log.Debug("Completed optimizing " + Pool.Name()); } catch (Failure ex) { Helpers.SetOtherConfig(this.Session, this.Pool, WlbOptimizationRecommendation.OPTIMIZINGPOOL, optId); WlbServerState.SetState(Pool, WlbServerState.ServerState.ConnectionError, ex); throw; } catch (CancelledException) { Helpers.SetOtherConfig(this.Session, this.Pool, WlbOptimizationRecommendation.OPTIMIZINGPOOL, optId); throw; } catch (Exception ex) { log.Error(ex, ex); this.Description = Messages.WLB_OPT_FAILED; Helpers.SetOtherConfig(this.Session, this.Pool, WlbOptimizationRecommendation.OPTIMIZINGPOOL, optId); log.Debug("Optimizing " + Pool.Name() + " is failed"); } this.PercentComplete = 100; }