private void EnterMaintenanceMode(Host host) { Pool pool = Helpers.GetPool(host.Connection); if (pool != null && pool.ha_enabled && host.IsMaster()) { using (var dlg = new ThreeButtonDialog( new ThreeButtonDialog.Details( SystemIcons.Error, String.Format(Messages.HA_CANNOT_EVACUATE_MASTER, Helpers.GetName(host).Ellipsise(Helpers.DEFAULT_NAME_TRIM_LENGTH)), Messages.XENCENTER))) { dlg.ShowDialog(Parent); } return; } if (!host.GetRunningVMs().Any() && (pool == null || !host.IsMaster())) { Program.MainWindow.CloseActiveWizards(host.Connection); var action = new EvacuateHostAction(host, null, new Dictionary <XenRef <VM>, string[]>(), AddHostToPoolCommand.NtolDialog, AddHostToPoolCommand.EnableNtolDialog); action.Completed += Program.MainWindow.action_Completed; action.RunAsync(); return; } new EvacuateHostDialog(host).ShowPerXenObject(host, Program.MainWindow); }
private void EnterMaintenanceMode(Host host) { Pool pool = Helpers.GetPool(host.Connection); if (pool != null && pool.ha_enabled && host.IsMaster()) { using (var dlg = new ErrorDialog(string.Format(Messages.HA_CANNOT_EVACUATE_MASTER, Helpers.GetName(host).Ellipsise(Helpers.DEFAULT_NAME_TRIM_LENGTH)))) { dlg.ShowDialog(Parent); } return; } if (!host.GetRunningVMs().Any() && (pool == null || pool.Connection.Cache.Hosts.Length == 1 || !host.IsMaster())) { Program.MainWindow.CloseActiveWizards(host.Connection); var action = new EvacuateHostAction(host, null, new Dictionary <XenRef <VM>, string[]>(), AddHostToPoolCommand.NtolDialog, AddHostToPoolCommand.EnableNtolDialog); action.Completed += Program.MainWindow.action_Completed; action.RunAsync(); return; } //The EvacuateHostDialog uses several different actions all of which might need an elevated session //We sudo once for all of them and store the session string elevatedUsername = null; string elevatedPassword = null; Session elevatedSession = null; if (!host.Connection.Session.IsLocalSuperuser && !Registry.DontSudo && !Role.CanPerform(new RbacMethodList(EvacuateHostDialog.RbacMethods), host.Connection, out var validRoles)) { using (var d = new RoleElevationDialog(host.Connection, host.Connection.Session, validRoles, string.Format(Messages.EVACUATE_HOST_DIALOG_TITLE, host.Name()))) if (d.ShowDialog(Program.MainWindow) == DialogResult.OK) { elevatedUsername = d.elevatedUsername; elevatedPassword = d.elevatedPassword; elevatedSession = d.elevatedSession; } else { return; } } new EvacuateHostDialog(host, elevatedUsername, elevatedPassword, elevatedSession) .ShowPerXenObject(host, Program.MainWindow); }
private void EvacuateButton_Click(object sender, EventArgs e) { var newMaster = tableLayoutPanelNewMaster.Visible ? NewMasterComboBox.SelectedItem as ToStringWrapper <Host> : null; hostAction = new EvacuateHostAction(_host, newMaster?.item, reasons ?? new Dictionary <XenRef <VM>, string[]>(), AddHostToPoolCommand.NtolDialog, AddHostToPoolCommand.EnableNtolDialog); hostAction.Completed += Program.MainWindow.action_Completed; hostAction.Changed += HostAction_Changed; hostAction.Completed += HostAction_Completed; //Closes all per-Connection and per-VM wizards for the given connection. Program.MainWindow.CloseActiveWizards(_host.Connection); DisableButtons(); progressBar1.Visible = true; pictureBoxStatus.Visible = false; tableLayoutPanelStatus.Visible = true; hostAction.RunAsync(GetSudoElevationResult()); }