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; Host fromHost = null; Host toHost = null; if (vmItem.Key.is_control_domain) { log.Debug(vmItem.Value.powerOperation + " " + Helpers.GetName(vmItem.Value.toHost)); fromHost = vmItem.Value.fromHost; Helpers.SetOtherConfig(fromHost.Connection.Session, fromHost,WlbOptimizationRecommendation.OPTIMIZINGPOOL, vmItem.Value.recId.ToString()); try { 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); } } } catch (Exception) { throw; } } else { log.Debug("Migrating VM " + vm.Name); fromHost = this.Pool.Connection.Resolve(vm.resident_on); 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 = 0; 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.MainWindow.closeActiveWizards(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 f; } } } 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, (Failure)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; }
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; }
/// <summary> /// In the case there being nowhere to start/resume the VM (NO_HOSTS_AVAILABLE), shows the reason why the VM could not be started /// on each host. If the start failed due to HA_OPERATION_WOULD_BREAK_FAILOVER_PLAN, offers to decrement ntol and try the operation /// again. /// </summary> public static void StartDiagnosisForm(VMStartAbstractAction VMStartAction, Failure failure) { if (failure.ErrorDescription[0] == Failure.NO_HOSTS_AVAILABLE) { // Show a dialog displaying why the VM couldn't be started on each host StartDiagnosisForm(VMStartAction.VM, VMStartAction.IsStart); } else if (failure.ErrorDescription[0] == Failure.HA_OPERATION_WOULD_BREAK_FAILOVER_PLAN) { // The action was blocked by HA because it would reduce the number of tolerable server failures. // With the user's consent, we'll reduce the number of configured failures to tolerate and try again. Pool pool = Helpers.GetPool(VMStartAction.VM.Connection); if (pool == null) { log.ErrorFormat("Could not get pool for VM {0} in StartDiagnosisForm()", Helpers.GetName(VMStartAction.VM)); return; } long ntol = pool.ha_host_failures_to_tolerate; long newNtol = Math.Min(pool.ha_plan_exists_for - 1, ntol - 1); if (newNtol <= 0) { // We would need to basically turn HA off to start this VM string msg = String.Format(VMStartAction.IsStart ? Messages.HA_VM_START_NTOL_ZERO : Messages.HA_VM_RESUME_NTOL_ZERO, Helpers.GetName(pool).Ellipsise(100), Helpers.GetName(VMStartAction.VM).Ellipsise(100)); Program.Invoke(Program.MainWindow, delegate() { using (var dlg = new ThreeButtonDialog(new ThreeButtonDialog.Details(SystemIcons.Warning, msg, Messages.HIGH_AVAILABILITY))) { dlg.ShowDialog(Program.MainWindow); } }); } else { // Show 'reduce ntol?' dialog string msg = String.Format(VMStartAction.IsStart ? Messages.HA_VM_START_NTOL_DROP : Messages.HA_VM_RESUME_NTOL_DROP, Helpers.GetName(pool).Ellipsise(100), ntol, Helpers.GetName(VMStartAction.VM).Ellipsise(100), newNtol); Program.Invoke(Program.MainWindow, delegate() { DialogResult r; using (var dlg = new ThreeButtonDialog( new ThreeButtonDialog.Details(SystemIcons.Warning, msg, Messages.HIGH_AVAILABILITY), ThreeButtonDialog.ButtonYes, new ThreeButtonDialog.TBDButton(Messages.NO_BUTTON_CAPTION, DialogResult.No, ThreeButtonDialog.ButtonType.CANCEL, true))) { r = dlg.ShowDialog(Program.MainWindow); } if (r == DialogResult.Yes) { DelegatedAsyncAction action = new DelegatedAsyncAction(VMStartAction.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, pool.opaque_ref, newNtol); // ntol set succeeded, start new action VMStartAction.Clone().RunAsync(); }); action.RunAsync(); } }); } } }
private void ButtonLogout_Click(object sender, EventArgs e) { Program.AssertOnEventThread(); // Double check, this method is called from a context menu as well and the state could have changed under it if (!ButtonLogout.Enabled) { return; } Session session = _connection.Session; if (session == null) { return; } // First we check through the list to check what warning message we show List <Subject> subjectsToLogout = new List <Subject>(); foreach (AdSubjectRow r in GridViewSubjectList.SelectedRows) { if (r.IsLocalRootRow || !r.LoggedIn) { continue; } subjectsToLogout.Add(r.subject); } bool suicide = false; // Warn if user is logging themselves out if (session.Subject != null)//have already checked session not null { var warnMsg = string.Format(subjectsToLogout.Count > 1 ? Messages.AD_LOGOUT_SUICIDE_MANY : Messages.AD_LOGOUT_SUICIDE_ONE, Helpers.GetName(_connection).Ellipsise(50)); foreach (Subject entry in subjectsToLogout) { if (entry.opaque_ref == session.Subject) { DialogResult r; using (var dlg = new ThreeButtonDialog( new ThreeButtonDialog.Details( SystemIcons.Warning, warnMsg, Messages.AD_FEATURE_NAME), ThreeButtonDialog.ButtonYes, new ThreeButtonDialog.TBDButton(Messages.NO_BUTTON_CAPTION, DialogResult.No, ThreeButtonDialog.ButtonType.CANCEL, true))) { r = dlg.ShowDialog(this); } //CA-64818: DialogResult can be No if the No button has been hit //or Cancel if the dialog has been closed from the control box if (r != DialogResult.Yes) { return; } suicide = true; break; } } } var logoutMessage = subjectsToLogout.Count == 1 ? string.Format(Messages.QUESTION_LOGOUT_AD_USER_ONE, subjectsToLogout[0].DisplayName ?? subjectsToLogout[0].SubjectName) : string.Format(Messages.QUESTION_LOGOUT_AD_USER_MANY, subjectsToLogout.Count); if (!suicide)//CA-68645 { DialogResult questionDialog; using (var dlg = new ThreeButtonDialog( new ThreeButtonDialog.Details( SystemIcons.Warning, logoutMessage, Messages.AD_FEATURE_NAME), ThreeButtonDialog.ButtonYes, new ThreeButtonDialog.TBDButton(Messages.NO_BUTTON_CAPTION, DialogResult.No, ThreeButtonDialog.ButtonType.CANCEL, true))) { questionDialog = dlg.ShowDialog(this); } //CA-64818: DialogResult can be No if the No button has been hit //or Cancel if the dialog has been closed from the control box if (questionDialog != DialogResult.Yes) { return; } } // Then we go through the list and disconnect each user session, doing our own last if necessary foreach (AdSubjectRow r in GridViewSubjectList.SelectedRows) { // check they are not the root row and are logged in if (r.IsLocalRootRow || !r.LoggedIn) { continue; } if (session.UserSid == r.subject.subject_identifier) { continue; } DelegatedAsyncAction logoutAction = new DelegatedAsyncAction(_connection, Messages.TERMINATING_SESSIONS, Messages.IN_PROGRESS, Messages.COMPLETED, delegate(Session s) { Session.logout_subject_identifier(s, r.subject.subject_identifier); }, "session.logout_subject_identifier"); logoutAction.RunAsync(); } if (suicide) { DelegatedAsyncAction logoutAction = new DelegatedAsyncAction(_connection, Messages.TERMINATING_SESSIONS, Messages.IN_PROGRESS, Messages.COMPLETED, delegate(Session s) { Session.logout_subject_identifier(s, session.UserSid); _connection.Logout(); }, "session.logout_subject_identifier"); logoutAction.RunAsync(); } else { // signal the background thread to update the logged in status lock (statusUpdaterLock) Monitor.Pulse(statusUpdaterLock); } }
private void updateCell(int index) { switch (index) { case 0: Cells[0].Value = pif.Name(); break; case 1: Cells[1].Value = pif.MAC; break; case 2: Cells[2].Value = pif.Carrier() ? Messages.CONNECTED : Messages.DISCONNECTED; break; case 3: Cells[3].Value = pif.Carrier() ? pif.Speed() : Messages.HYPHEN; break; case 4: Cells[4].Value = pif.Carrier() ? pif.Duplex() : Messages.HYPHEN; break; case 5: Cells[5].Value = vendor; break; case 6: Cells[6].Value = device; break; case 7: Cells[7].Value = busPath; break; case 8: Cells[8].Value = pif.FCoECapable().ToYesNoStringI18n(); break; case 9: string sriovSupported = ""; if (!pif.SriovCapable() || !pif.IsSriovPhysicalPIF()) { sriovSupported = !pif.SriovCapable() ? Messages.NO : Messages.SRIOV_DISABLED; Cells[9].Value = sriovSupported; } else { DelegatedAsyncAction action = new DelegatedAsyncAction(pif.Connection, "", "", "", delegate(Session session) { try { var remainingCapacity = Network_sriov.get_remaining_capacity(session, pif.sriov_physical_PIF_of[0].opaque_ref); sriovSupported = string.Format(Messages.REAMININF_VFS, remainingCapacity); } catch { sriovSupported = Messages.YES; } }, true); action.Completed += delegate { Program.Invoke(Program.MainWindow, delegate { Cells[9].Value = sriovSupported; }); }; action.RunAsync(); } break; } }
private void Scan() { DelegatedAsyncAction saveVMsAction = new DelegatedAsyncAction(connection, Messages.SAVING_VMS_ACTION_TITLE, Messages.SAVING_VMS_ACTION_DESC, Messages.COMPLETED, delegate(Session session) { //Save Evacuated VMs for later host.SaveEvacuatedVMs(session); }, "host.remove_from_other_config", "host.add_to_other_config"); DelegatedAsyncAction action = new DelegatedAsyncAction(connection, Messages.MAINTENANCE_MODE, Messages.SCANNING_VMS, Messages.SCANNING_VMS, delegate(Session session) { reasons = new Dictionary <XenRef <VM>, string[]>(); // WLB: get host wlb evacuate recommendation if wlb is enabled if (Helpers.WlbEnabled(host.Connection)) { try { reasons = XenAPI.Host.retrieve_wlb_evacuate_recommendations(session, host.opaque_ref); } catch (Exception ex) { log.Debug(ex.Message, ex); } } // WLB: in case wlb has no recommendations or get errors when retrieve recommendation, // assume retrieve_wlb_evacuate_recommendations returns 0 recommendation // or return recommendations for all running vms on this host if (reasons.Count == 0 || !ValidRecommendation(reasons)) { reasons = Host.get_vms_which_prevent_evacuation(session, host.opaque_ref); } // take care of errors Program.Invoke(this, delegate() { foreach (KeyValuePair <XenRef <VM>, String[]> kvp in reasons) { //WLB: filter out errors if (string.Compare(kvp.Value[0].Trim(), "wlb", true) != 0) { ProcessError(kvp.Key.opaque_ref, kvp.Value); } //Update NewMasterComboBox for host power on recommendation if ((session.Connection.Resolve(kvp.Key)).is_control_domain) { Host powerOnHost = session.Connection.Cache.Find_By_Uuid <Host>(kvp.Value[(int)RecProperties.ToHost]); if (powerOnHost != null) { var previousSelection = NewMasterComboBox.SelectedItem as ToStringWrapper <Host>; var hostToAdd = new ToStringWrapper <Host>(powerOnHost, powerOnHost.Name); if (NewMasterComboBox.Items.Count == 0) { powerOnHost.PropertyChanged -= new PropertyChangedEventHandler(host_PropertyChanged); powerOnHost.PropertyChanged += new PropertyChangedEventHandler(host_PropertyChanged); NewMasterComboBox.Items.Add(hostToAdd); } else { foreach (ToStringWrapper <Host> tswh in NewMasterComboBox.Items) { if (tswh.item.CompareTo(powerOnHost) != 0) { powerOnHost.PropertyChanged -= new PropertyChangedEventHandler(host_PropertyChanged); powerOnHost.PropertyChanged += new PropertyChangedEventHandler(host_PropertyChanged); NewMasterComboBox.Items.Add(hostToAdd); } } } SelectProperItemInNewMasterComboBox(previousSelection); } } } }); }, true); SetSession(saveVMsAction); SetSession(action); saveVMsAction.RunAsync(); new ActionProgressDialog(action, ProgressBarStyle.Blocks).ShowDialog(this); RefreshEntermaintenanceButton(); }
private void CheckXenServerCredentials() { if (string.IsNullOrEmpty(textboxXSUserName.Text.Trim()) || string.IsNullOrEmpty(textboxXSPassword.Text)) { return; } bool passedRbacChecks = false; DelegatedAsyncAction action = new DelegatedAsyncAction(connection, Messages.CREDENTIALS_CHECKING, "", "", delegate { Session elevatedSession = null; try { elevatedSession = connection.ElevatedSession(textboxXSUserName.Text.Trim(), textboxXSPassword.Text); if (elevatedSession != null && (elevatedSession.IsLocalSuperuser || SessionAuthorized(elevatedSession, Role.ValidRoleList("pool.set_health_check_config", connection)))) { passedRbacChecks = true; } } catch (Failure f) { if (f.ErrorDescription.Count > 0 && f.ErrorDescription[0] == Failure.RBAC_PERMISSION_DENIED) { // we use a different error message here from the standard one in friendly names throw new Exception(Messages.HEALTH_CHECK_USER_HAS_NO_PERMISSION_TO_CONNECT); } throw; } finally { if (elevatedSession != null) { elevatedSession.Connection.Logout(elevatedSession); elevatedSession = null; } } }, true); action.Completed += delegate { log.DebugFormat("Logging with the new credentials returned: {0} ", passedRbacChecks); Program.Invoke(Program.MainWindow, () => { if (passedRbacChecks) { ShowTestCredentialsStatus(Resources._000_Tick_h32bit_16, null); } else { ShowTestCredentialsStatus(Resources._000_error_h32bit_16, action.Exception != null ? action.Exception.Message : Messages.HEALTH_CHECK_USER_NOT_AUTHORIZED); } textboxXSUserName.Enabled = textboxXSPassword.Enabled = testCredentialsButton.Enabled = newXsCredentialsRadioButton.Checked; }); }; log.Debug("Testing logging in with the new credentials"); ShowTestCredentialsStatus(Resources.ajax_loader, null); textboxXSUserName.Enabled = textboxXSPassword.Enabled = testCredentialsButton.Enabled = false; action.RunAsync(); }
private void Update() { _cellName.Value = Pif.Name(); _cellMac.Value = Pif.MAC; _cellConnected.Value = Pif.Carrier() ? Messages.CONNECTED : Messages.DISCONNECTED; _cellSpeed.Value = Pif.Carrier() ? Pif.Speed() : Messages.HYPHEN; _cellDuplex.Value = Pif.Carrier() ? Pif.Duplex() : Messages.HYPHEN; var pifMetrics = Pif.PIFMetrics(); _cellVendor.Value = pifMetrics == null ? Messages.HYPHEN : pifMetrics.vendor_name; _cellDevice.Value = pifMetrics == null ? Messages.HYPHEN : pifMetrics.device_name; _cellBusPath.Value = pifMetrics == null ? Messages.HYPHEN : pifMetrics.pci_bus_path; _cellFcoe.Value = Pif.FCoECapable().ToYesNoStringI18n(); if (!Pif.SriovCapable()) { _cellSriov.Value = Messages.NO; } else if (!Pif.IsSriovPhysicalPIF()) { _cellSriov.Value = Messages.SRIOV_NETWORK_SHOULD_BE_CREATED; } else { var networkSriov = Pif.Connection.Resolve(Pif.sriov_physical_PIF_of[0]); if (networkSriov == null || networkSriov.requires_reboot) { _cellSriov.Value = Messages.HOST_NEEDS_REBOOT_ENABLE_SRIOV; return; } PIF sriovLogicalPif = Pif.Connection.Resolve(networkSriov.logical_PIF); if (sriovLogicalPif == null || !sriovLogicalPif.currently_attached) { _cellSriov.Value = Messages.SRIOV_LOGICAL_PIF_UNPLUGGED; return; } var sriovSupported = ""; var action = new DelegatedAsyncAction(Pif.Connection, "", "", "", delegate(Session session) { try { var remainingCapacity = Network_sriov.get_remaining_capacity(session, Pif.sriov_physical_PIF_of[0].opaque_ref); sriovSupported = string.Format(Messages.REMAINING_VFS, remainingCapacity); } catch { sriovSupported = Messages.YES; } }, true); action.Completed += delegate { Program.Invoke(Program.MainWindow, () => _cellSriov.Value = sriovSupported); }; action.RunAsync(); } }