2023-01-24 15:29:31 +01:00
|
|
|
|
/* Copyright (c) Cloud Software Group, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms,
|
|
|
|
|
* with or without modification, are permitted provided
|
|
|
|
|
* that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* * Redistributions of source code must retain the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer.
|
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
|
* materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
2020-03-04 13:47:22 +01:00
|
|
|
|
using System.Linq;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
using XenAdmin.Actions;
|
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using XenAdmin.Wlb;
|
|
|
|
|
using XenAdmin.Commands;
|
|
|
|
|
using XenAdmin.Actions.VMActions;
|
2021-06-15 03:04:14 +02:00
|
|
|
|
using XenAdmin.Actions.Wlb;
|
2017-11-17 02:04:45 +01:00
|
|
|
|
using XenCenterLib;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Dialogs
|
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
public partial class EvacuateHostDialog : XenDialogBase
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-10-24 15:05:01 +02:00
|
|
|
|
#region Private fields
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
private readonly Host _host;
|
|
|
|
|
private readonly Pool _pool;
|
2021-06-15 03:04:14 +02:00
|
|
|
|
private WlbEvacuateRecommendationsAction vmErrorsAction;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private EvacuateHostAction hostAction;
|
2020-09-17 22:43:39 +02:00
|
|
|
|
private ToStringWrapper<Host> hostSelection;
|
|
|
|
|
private Dictionary<string, AsyncAction> solveActionsByVmUuid;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private Dictionary<XenRef<VM>, String[]> reasons;
|
2020-09-17 22:43:39 +02:00
|
|
|
|
private string elevatedUsername;
|
|
|
|
|
private string elevatedPassword;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private Session elevatedSession;
|
2020-09-17 22:43:39 +02:00
|
|
|
|
private volatile bool _rebuildInProgress;
|
|
|
|
|
private volatile bool _rebuildRequired;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
public static readonly string[] RbacMethods =
|
|
|
|
|
{
|
|
|
|
|
"host.remove_from_other_config", // save VM list
|
|
|
|
|
"host.add_to_other_config",
|
|
|
|
|
"host.disable", // disable the host
|
2013-10-24 15:05:01 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
"pbd.plug", // Repair SR and install tools
|
|
|
|
|
"pbd.create",
|
2013-10-24 15:05:01 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
"vm.suspend", // Suspend VMs
|
2013-10-24 15:05:01 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
"vbd.async_eject", // Change ISO
|
|
|
|
|
"vbd.async_insert",
|
|
|
|
|
"vbd.eject",
|
|
|
|
|
"vbd.insert",
|
|
|
|
|
};
|
2013-10-24 15:05:01 +02:00
|
|
|
|
|
|
|
|
|
#endregion
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
public EvacuateHostDialog(Host host, string elevatedUserName, string elevatedPassword, Session elevatedSession)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
: base(host.Connection)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2021-08-31 12:31:16 +02:00
|
|
|
|
labelCoordinatorBlurb.Text = string.Format(labelCoordinatorBlurb.Text, BrandManager.BrandConsole);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
this.elevatedUsername = elevatedUserName;
|
|
|
|
|
this.elevatedPassword = elevatedPassword;
|
|
|
|
|
this.elevatedSession = elevatedSession;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
_host = host;
|
|
|
|
|
_pool = Helpers.GetPoolOfOne(_host.Connection);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (!_host.IsCoordinator() || connection.Cache.HostCount <= 1)
|
|
|
|
|
tableLayoutPanelNewCoordinator.Visible = false;
|
2020-09-17 22:43:39 +02:00
|
|
|
|
else
|
|
|
|
|
tableLayoutPanelPSr.Visible = false;
|
|
|
|
|
|
|
|
|
|
tableLayoutPanelWlb.Visible = _pool.IsVisible() && Helpers.WlbEnabled(_host.Connection) &&
|
|
|
|
|
WlbServerState.GetState(_pool) == WlbServerState.ServerState.Enabled;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
tableLayoutPanelSpinner.Visible = false;
|
|
|
|
|
tableLayoutPanelStatus.Visible = false;
|
|
|
|
|
progressBar1.Visible = false;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
_host.PropertyChanged += hostUpdate;
|
|
|
|
|
_pool.PropertyChanged += poolUpdate;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
ActiveControl = CloseButton;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
protected override void OnShown(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnShown(e);
|
|
|
|
|
Text = string.Format(Messages.EVACUATE_HOST_DIALOG_TITLE, _host.Name());
|
|
|
|
|
Rebuild();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Rebuild()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
if (_rebuildInProgress || hostAction != null && !hostAction.IsCompleted)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
_rebuildRequired = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
Program.Invoke(this, () =>
|
|
|
|
|
{
|
|
|
|
|
_rebuildInProgress = true;
|
|
|
|
|
tableLayoutPanelStatus.Visible = false;
|
|
|
|
|
progressBar1.Visible = false;
|
|
|
|
|
DisableButtons();
|
|
|
|
|
ClearVMs();
|
|
|
|
|
ClearHosts();
|
|
|
|
|
labelSpinner.Text = Messages.SCANNING_VMS;
|
|
|
|
|
spinnerIcon1.StartSpinning();
|
|
|
|
|
tableLayoutPanelSpinner.Visible = true;
|
|
|
|
|
Scan();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Scan()
|
|
|
|
|
{
|
|
|
|
|
//Save Evacuated VMs for later
|
|
|
|
|
var saveVMsAction = new DelegatedAsyncAction(connection,
|
|
|
|
|
Messages.SAVING_VM_PROPERTIES_ACTION_TITLE, Messages.SAVING_VM_PROPERTIES_ACTION_DESC, Messages.COMPLETED,
|
|
|
|
|
session => _host.SaveEvacuatedVMs(session), true, "host.remove_from_other_config", "host.add_to_other_config");
|
|
|
|
|
|
|
|
|
|
saveVMsAction.RunAsync(GetSudoElevationResult());
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-06-15 03:04:14 +02:00
|
|
|
|
vmErrorsAction = new WlbEvacuateRecommendationsAction(_host);
|
2020-09-17 22:43:39 +02:00
|
|
|
|
vmErrorsAction.Completed += VmErrorsAction_Completed;
|
|
|
|
|
vmErrorsAction.RunAsync(GetSudoElevationResult());
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
private void VmErrorsAction_Completed(ActionBase obj)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-06-15 03:04:14 +02:00
|
|
|
|
if (!(obj is WlbEvacuateRecommendationsAction action))
|
2020-09-17 22:43:39 +02:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
try
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
Program.Invoke(this, () =>
|
2013-10-31 16:55:49 +01:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
if (action.Succeeded)
|
|
|
|
|
{
|
2021-06-15 03:04:14 +02:00
|
|
|
|
reasons = action.CantEvacuateReasons;
|
2020-09-17 22:43:39 +02:00
|
|
|
|
tableLayoutPanelSpinner.Visible = false;
|
|
|
|
|
spinnerIcon1.StopSpinning();
|
|
|
|
|
PopulateVMs();
|
|
|
|
|
PopulateHosts();
|
|
|
|
|
EnableButtons();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
spinnerIcon1.ShowFailureImage();
|
|
|
|
|
labelSpinner.Text = action.Exception.Message;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
_rebuildInProgress = false;
|
|
|
|
|
if (_rebuildRequired)
|
|
|
|
|
{
|
|
|
|
|
_rebuildRequired = false;
|
|
|
|
|
Rebuild();
|
2013-10-31 16:55:49 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private void hostUpdate(object o, PropertyChangedEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (args == null || args.PropertyName == "name_label" || args.PropertyName == "resident_VMs")
|
2020-09-17 22:43:39 +02:00
|
|
|
|
Rebuild();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
private void poolUpdate(object o, PropertyChangedEventArgs args)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
if (args == null || args.PropertyName == "is_psr_pending" ||
|
|
|
|
|
args.PropertyName == "allowed_operations" || args.PropertyName == "current_operations")
|
|
|
|
|
Program.Invoke(this, ()=>
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
EnableComboBox();
|
|
|
|
|
EnableButtons();
|
|
|
|
|
});
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2020-09-17 22:43:39 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private void VM_PropertyChanged(object sender, PropertyChangedEventArgs args)
|
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
if (args.PropertyName == "name_label" || args.PropertyName == "allowed_operations" ||
|
|
|
|
|
args.PropertyName == "current_operations")
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
Program.Invoke(this, () =>
|
|
|
|
|
{
|
|
|
|
|
if (sender is VM vm)
|
|
|
|
|
dataGridViewVms.Rows.Cast<VmPrecheckRow>()
|
|
|
|
|
.FirstOrDefault(r => r.vm.opaque_ref == vm.opaque_ref)?.Refresh();
|
|
|
|
|
});
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2020-09-17 22:43:39 +02:00
|
|
|
|
else if (args.PropertyName == "virtualisation_status" || args.PropertyName == "resident_on")
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
Rebuild();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
else if (args.PropertyName == "guest_metrics")
|
|
|
|
|
{
|
|
|
|
|
VM v = sender as VM;
|
2020-09-17 22:43:39 +02:00
|
|
|
|
VM_guest_metrics gm = connection.Resolve(v?.guest_metrics);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (gm == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
gm.PropertyChanged -= gm_PropertyChanged;
|
|
|
|
|
gm.PropertyChanged += gm_PropertyChanged;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
private void gm_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
if (e.PropertyName == "PV_drivers_version")
|
2020-09-17 22:43:39 +02:00
|
|
|
|
Rebuild();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void host_PropertyChanged(object sender, PropertyChangedEventArgs args)
|
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
if (args == null || args.PropertyName == "name_label" ||
|
|
|
|
|
args.PropertyName == "enabled" || args.PropertyName == "metrics")
|
|
|
|
|
{
|
|
|
|
|
Program.Invoke(this, () =>
|
|
|
|
|
{
|
|
|
|
|
ClearHosts();
|
|
|
|
|
PopulateHosts();
|
|
|
|
|
});
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
|
|
|
|
|
private void ClearVMs()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
solveActionsByVmUuid = new Dictionary<string, AsyncAction>();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
foreach (DataGridViewRow row in dataGridViewVms.Rows)
|
|
|
|
|
{
|
|
|
|
|
if (row is VmPrecheckRow precheckRow)
|
|
|
|
|
{
|
|
|
|
|
DeregisterVmRowEvents(precheckRow);
|
|
|
|
|
solveActionsByVmUuid.Add(precheckRow.vm.uuid, precheckRow.SolutionAction);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-24 15:05:01 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
dataGridViewVms.Rows.Clear();
|
|
|
|
|
}
|
2013-10-24 15:05:01 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
private void PopulateVMs()
|
|
|
|
|
{
|
|
|
|
|
Program.AssertOnEventThread();
|
2013-10-31 16:55:49 +01:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
2013-10-31 16:55:49 +01:00
|
|
|
|
dataGridViewVms.SuspendLayout();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
foreach (VM vm in connection.ResolveAll(_host.resident_VMs))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
if (vm.is_control_domain || vm.is_a_template)
|
|
|
|
|
continue;
|
|
|
|
|
|
2013-10-31 16:55:49 +01:00
|
|
|
|
vm.PropertyChanged += VM_PropertyChanged;
|
2020-09-17 22:43:39 +02:00
|
|
|
|
solveActionsByVmUuid.TryGetValue(vm.uuid, out var action);
|
|
|
|
|
var row = new VmPrecheckRow(vm) {SolutionAction = action};
|
2013-10-31 16:55:49 +01:00
|
|
|
|
dataGridViewVms.Rows.Add(row);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2020-09-17 22:43:39 +02:00
|
|
|
|
|
|
|
|
|
foreach (KeyValuePair<XenRef<VM>, string[]> kvp in reasons)
|
|
|
|
|
{
|
|
|
|
|
if (kvp.Value[0].Trim().ToLower() != "wlb")
|
|
|
|
|
UpdateVMWithError(kvp.Value, kvp.Key.opaque_ref);
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
2013-10-31 16:55:49 +01:00
|
|
|
|
dataGridViewVms.ResumeLayout();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
private void ClearHosts()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (tableLayoutPanelNewCoordinator.Visible)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
NewCoordinatorComboBox.Enabled = false;
|
|
|
|
|
hostSelection = NewCoordinatorComboBox.SelectedItem as ToStringWrapper<Host>;
|
|
|
|
|
NewCoordinatorComboBox.Items.Clear();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
private void PopulateHosts()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
Program.AssertOnEventThread();
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (!tableLayoutPanelNewCoordinator.Visible)
|
2020-09-17 22:43:39 +02:00
|
|
|
|
return;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
NewCoordinatorComboBox.BeginUpdate();
|
2020-09-17 22:43:39 +02:00
|
|
|
|
var hosts = connection.Cache.Hosts.Where(h => h.opaque_ref != _host.opaque_ref).ToList();
|
|
|
|
|
hosts.Sort();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
foreach (Host host in hosts)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
host.PropertyChanged -= host_PropertyChanged;
|
|
|
|
|
host.PropertyChanged += host_PropertyChanged;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
Host_metrics metrics = connection.Resolve(host.metrics);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (host.enabled && metrics != null && metrics.live)
|
2020-09-17 22:43:39 +02:00
|
|
|
|
{
|
|
|
|
|
var item = new ToStringWrapper<Host>(host, host.Name());
|
2021-08-31 12:31:16 +02:00
|
|
|
|
NewCoordinatorComboBox.Items.Add(item);
|
2020-09-17 22:43:39 +02:00
|
|
|
|
|
|
|
|
|
if (hostSelection != null && host.opaque_ref == hostSelection.item.opaque_ref)
|
2021-08-31 12:31:16 +02:00
|
|
|
|
NewCoordinatorComboBox.SelectedItem = item;
|
2020-09-17 22:43:39 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
//Update NewCoordinatorComboBox for host power on recommendation
|
2020-09-17 22:43:39 +02:00
|
|
|
|
foreach (KeyValuePair<XenRef<VM>, string[]> kvp in reasons)
|
|
|
|
|
{
|
|
|
|
|
var vm = connection.Resolve(kvp.Key);
|
|
|
|
|
if (vm != null && vm.is_control_domain)
|
|
|
|
|
{
|
|
|
|
|
Host powerOnHost = connection.Cache.Hosts.FirstOrDefault(h =>
|
|
|
|
|
h.uuid == kvp.Value[(int)RecProperties.ToHost]);
|
|
|
|
|
|
|
|
|
|
if (powerOnHost != null)
|
|
|
|
|
{
|
|
|
|
|
var hostToAdd = new ToStringWrapper<Host>(powerOnHost, powerOnHost.Name());
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (NewCoordinatorComboBox.Items.Cast<ToStringWrapper<Host>>().FirstOrDefault(i =>
|
2020-09-17 22:43:39 +02:00
|
|
|
|
i.item.opaque_ref == powerOnHost.opaque_ref) == null)
|
|
|
|
|
{
|
|
|
|
|
powerOnHost.PropertyChanged -= host_PropertyChanged;
|
|
|
|
|
powerOnHost.PropertyChanged += host_PropertyChanged;
|
2021-08-31 12:31:16 +02:00
|
|
|
|
NewCoordinatorComboBox.Items.Add(hostToAdd);
|
2020-09-17 22:43:39 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (NewCoordinatorComboBox.SelectedItem == null && NewCoordinatorComboBox.Items.Count > 0)
|
|
|
|
|
NewCoordinatorComboBox.SelectedIndex = 0;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
EnableComboBox();
|
2021-08-31 12:31:16 +02:00
|
|
|
|
NewCoordinatorComboBox.EndUpdate();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
private void EnableComboBox()
|
2016-03-11 14:53:12 +01:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (tableLayoutPanelNewCoordinator.Visible)
|
2016-03-11 14:53:12 +01:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
bool enable = connection.Cache.Hosts.Any(Host.RestrictPoolSecretRotation) ||
|
|
|
|
|
!_pool.is_psr_pending &&
|
|
|
|
|
_pool.allowed_operations.Contains(pool_allowed_operations.designate_new_master);
|
|
|
|
|
|
2021-10-12 01:21:57 +02:00
|
|
|
|
var msg = string.Empty;
|
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
if (!enable)
|
2016-03-11 14:53:12 +01:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
if (_pool.is_psr_pending)
|
2021-10-12 01:21:57 +02:00
|
|
|
|
msg = Messages.ROTATE_POOL_SECRET_PENDING_NEW_COORDINATOR;
|
2020-09-17 22:43:39 +02:00
|
|
|
|
else if (_pool.current_operations.Values.Contains(pool_allowed_operations.ha_enable))
|
2021-10-12 01:21:57 +02:00
|
|
|
|
msg = Messages.EVACUATE_HOST_HA_ENABLING;
|
2020-09-17 22:43:39 +02:00
|
|
|
|
else if (_pool.current_operations.Values.Contains(pool_allowed_operations.ha_disable))
|
2021-10-12 01:21:57 +02:00
|
|
|
|
msg = Messages.EVACUATE_HOST_HA_DISABLING;
|
2020-09-17 22:43:39 +02:00
|
|
|
|
else if (_pool.current_operations.Values.Contains(pool_allowed_operations.cluster_create))
|
2021-10-12 01:21:57 +02:00
|
|
|
|
msg = Messages.EVACUATE_HOST_CLUSER_CREATING;
|
2016-03-11 14:53:12 +01:00
|
|
|
|
}
|
2020-09-17 22:43:39 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
NewCoordinatorComboBox.Enabled = enable;
|
2021-10-12 01:21:57 +02:00
|
|
|
|
labelWarning.Text = msg;
|
|
|
|
|
tableLayoutPanelPSr.Visible = !enable && !string.IsNullOrEmpty(labelWarning.Text);
|
2016-03-11 14:53:12 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
private void EnableButtons()
|
|
|
|
|
{
|
|
|
|
|
buttonCheckAgain.Enabled = true;
|
|
|
|
|
|
|
|
|
|
var canMigrate = dataGridViewVms.Rows.Cast<VmPrecheckRow>().All(r => !r.HasSolution() && !r.HasSolutionActionInProgress());
|
|
|
|
|
//empty returns true, which is correct
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
EvacuateButton.Enabled = canMigrate && (!tableLayoutPanelNewCoordinator.Visible || NewCoordinatorComboBox.Enabled);
|
2020-09-17 22:43:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DisableButtons()
|
|
|
|
|
{
|
|
|
|
|
buttonCheckAgain.Enabled = false;
|
|
|
|
|
EvacuateButton.Enabled = false;
|
|
|
|
|
}
|
2016-03-11 14:53:12 +01:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
private void DeregisterVmRowEvents(VmPrecheckRow row)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
if (row.vm != null)
|
|
|
|
|
{
|
|
|
|
|
row.vm.PropertyChanged -= VM_PropertyChanged;
|
|
|
|
|
VM_guest_metrics gm = connection.Resolve(row.vm.guest_metrics);
|
|
|
|
|
if (gm == null)
|
|
|
|
|
return;
|
|
|
|
|
gm.PropertyChanged -= gm_PropertyChanged;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool CanSuspendVm(String vmRef)
|
|
|
|
|
{
|
|
|
|
|
if (vmRef == null)
|
|
|
|
|
return false;
|
|
|
|
|
VM vm = connection.Resolve(new XenRef<VM>(vmRef));
|
|
|
|
|
return vm != null && vm.allowed_operations != null && vm.allowed_operations.Contains(vm_operations.suspend);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateVMWithError(string[] errorDescription, string vmRef = null)
|
|
|
|
|
{
|
|
|
|
|
if (errorDescription.Length == 0)
|
|
|
|
|
return;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
Solution solution;
|
|
|
|
|
string error = "";
|
2013-10-31 16:55:49 +01:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
switch (errorDescription[0])
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
case Failure.VM_REQUIRES_SR:
|
|
|
|
|
vmRef = errorDescription[1];
|
|
|
|
|
SR sr = connection.Resolve(new XenRef<SR>(errorDescription[2]));
|
2013-10-31 16:55:49 +01:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
if (sr != null && sr.content_type == SR.Content_Type_ISO)
|
|
|
|
|
{
|
|
|
|
|
error = Messages.EVACUATE_HOST_LOCAL_CD;
|
|
|
|
|
solution = Solution.EjectCD;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
error = Messages.EVACUATE_HOST_LOCAL_STORAGE;
|
|
|
|
|
solution = CanSuspendVm(vmRef) ? Solution.Suspend : Solution.Shutdown;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Failure.VM_MISSING_PV_DRIVERS:
|
|
|
|
|
vmRef = errorDescription[1];
|
|
|
|
|
VM vm = connection.Resolve(new XenRef<VM>(vmRef));
|
2021-08-31 12:31:16 +02:00
|
|
|
|
solution = InstallToolsCommand.CanRun(vm) && !Helpers.StockholmOrGreater(connection)
|
2020-09-17 22:43:39 +02:00
|
|
|
|
? Solution.InstallPVDrivers
|
|
|
|
|
: Solution.InstallPVDriversNoSolution;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Failure.HA_NO_PLAN:
|
|
|
|
|
dataGridViewVms.Rows.Cast<VmPrecheckRow>().ToList().ForEach(r =>
|
|
|
|
|
r.SetError("", CanSuspendVm(r.vm.opaque_ref) ? Solution.Suspend : Solution.Shutdown));
|
|
|
|
|
return; //exit the method
|
|
|
|
|
|
|
|
|
|
case Failure.HOST_NOT_ENOUGH_FREE_MEMORY:
|
|
|
|
|
case Failure.VM_FAILED_SHUTDOWN_ACKNOWLEDGMENT:
|
|
|
|
|
vmRef = errorDescription[1];
|
|
|
|
|
solution = CanSuspendVm(vmRef) ? Solution.Suspend : Solution.Shutdown;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
solution = CanSuspendVm(vmRef) ? Solution.Suspend : Solution.Shutdown;
|
|
|
|
|
break;
|
2013-10-31 16:55:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
var row = dataGridViewVms.Rows.Cast<VmPrecheckRow>().FirstOrDefault(r => r.vm.opaque_ref == vmRef);
|
|
|
|
|
row?.SetError(error, solution);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private AsyncAction.SudoElevationResult GetSudoElevationResult()
|
|
|
|
|
{
|
|
|
|
|
if (elevatedUsername == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
var ser = new AsyncAction.SudoElevationResult(elevatedUsername, elevatedPassword, elevatedSession);
|
|
|
|
|
//use the session from the role elevation dialog, but only the first time
|
|
|
|
|
elevatedSession = null;
|
|
|
|
|
return ser;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Control event handlers
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
private void NewCoordinatorComboBox_DrawItem(object sender, DrawItemEventArgs e)
|
2020-09-17 22:43:39 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
var backColor = NewCoordinatorComboBox.Enabled ? NewCoordinatorComboBox.BackColor : SystemColors.Control;
|
2020-09-17 22:43:39 +02:00
|
|
|
|
|
|
|
|
|
using (SolidBrush backBrush = new SolidBrush(backColor))
|
|
|
|
|
e.Graphics.FillRectangle(backBrush, e.Bounds);
|
2013-10-31 16:55:49 +01:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (e.Index < 0 || e.Index > NewCoordinatorComboBox.Items.Count - 1)
|
2020-09-17 22:43:39 +02:00
|
|
|
|
return;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (!(NewCoordinatorComboBox.Items[e.Index] is ToStringWrapper<Host> host))
|
2020-09-17 22:43:39 +02:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Image icon = Images.GetImage16For(host.item);
|
|
|
|
|
|
|
|
|
|
var imageRectangle = new Rectangle(e.Bounds.Left + 1, e.Bounds.Top + 1, 16, 16);
|
|
|
|
|
Rectangle textRectangle = new Rectangle(e.Bounds.Height, e.Bounds.Y,
|
|
|
|
|
e.Bounds.Width - e.Bounds.Height - 5, e.Bounds.Height);
|
|
|
|
|
|
|
|
|
|
using (var g = e.Graphics)
|
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (NewCoordinatorComboBox.Enabled)
|
2013-10-31 16:55:49 +01:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
g.DrawImage(icon, imageRectangle);
|
|
|
|
|
|
|
|
|
|
Drawing.DrawText(g, host.ToString(), e.Font, textRectangle,
|
|
|
|
|
e.ForeColor, e.BackColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
|
2013-10-31 16:55:49 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
g.DrawImage(icon, imageRectangle, 0, 0, icon.Width, icon.Height, GraphicsUnit.Pixel, Drawing.GreyScaleAttributes);
|
2013-10-31 16:55:49 +01:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
Drawing.DrawText(g, host.ToString(), e.Font, textRectangle,
|
|
|
|
|
SystemColors.GrayText, SystemColors.Control, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2020-09-17 22:43:39 +02:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
|
|
|
|
|
private void dataGridViewVms_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.RowIndex >= 0 && e.RowIndex < dataGridViewVms.RowCount &&
|
|
|
|
|
e.ColumnIndex == columnAction.Index &&
|
|
|
|
|
dataGridViewVms.Rows[e.RowIndex] is VmPrecheckRow row && row.HasSolution())
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
Cursor.Current = Cursors.Hand;
|
|
|
|
|
return;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
Cursor.Current = Cursors.Default;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
private void dataGridViewVms_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.RowIndex >= 0 && e.RowIndex < dataGridViewVms.RowCount &&
|
|
|
|
|
e.ColumnIndex == columnAction.Index &&
|
|
|
|
|
dataGridViewVms.Rows[e.RowIndex] is VmPrecheckRow row && row.HasSolution())
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
AsyncAction action = null;
|
|
|
|
|
switch (row.Solution)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
case Solution.EjectCD:
|
2020-09-17 22:43:39 +02:00
|
|
|
|
action = new ChangeVMISOAction(row.vm.Connection, row.vm, null, row.vm.FindVMCDROM());
|
2013-06-24 13:41:48 +02:00
|
|
|
|
break;
|
|
|
|
|
case Solution.Suspend:
|
2020-09-17 22:43:39 +02:00
|
|
|
|
action = new VMSuspendAction(row.vm);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
break;
|
2015-04-16 11:38:43 +02:00
|
|
|
|
case Solution.Shutdown:
|
2020-09-17 22:43:39 +02:00
|
|
|
|
action = new VMHardShutdown(row.vm);
|
2015-04-16 11:38:43 +02:00
|
|
|
|
break;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
case Solution.InstallPVDrivers:
|
2020-09-17 22:43:39 +02:00
|
|
|
|
var cmd = new InstallToolsCommand(Program.MainWindow, row.vm, dataGridViewVms);
|
2021-08-31 12:31:16 +02:00
|
|
|
|
cmd.Run();
|
2020-09-17 22:43:39 +02:00
|
|
|
|
// The install pv tools action is marked as complete after they have taken the user to the
|
|
|
|
|
// console and loaded the disc. Rescanning when the action is 'complete' in this case
|
|
|
|
|
// doesn't gain us anything then. Keep showing the "Click here to install PV drivers" text.
|
|
|
|
|
return;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2013-10-31 16:55:49 +01:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
if (action != null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
action.Completed += a => Rebuild();
|
|
|
|
|
action.RunAsync(GetSudoElevationResult());
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2020-09-17 22:43:39 +02:00
|
|
|
|
//set this after starting the action so that the row is updated correctly
|
|
|
|
|
row.SolutionAction = action;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2020-09-17 22:43:39 +02:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2016-03-11 14:53:12 +01:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
private void buttonCheckAgain_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Rebuild();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
private void EvacuateButton_Click(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
var newCoordinator = tableLayoutPanelNewCoordinator.Visible
|
|
|
|
|
? NewCoordinatorComboBox.SelectedItem as ToStringWrapper<Host>
|
2020-09-17 22:43:39 +02:00
|
|
|
|
: null;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
hostAction = new EvacuateHostAction(_host, newCoordinator?.item,
|
2020-09-17 22:43:39 +02:00
|
|
|
|
reasons ?? new Dictionary<XenRef<VM>, string[]>(),
|
|
|
|
|
AddHostToPoolCommand.NtolDialog, AddHostToPoolCommand.EnableNtolDialog);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
hostAction.Completed += Program.MainWindow.action_Completed;
|
2020-09-17 22:43:39 +02:00
|
|
|
|
hostAction.Changed += HostAction_Changed;
|
|
|
|
|
hostAction.Completed += HostAction_Completed;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
//Closes all per-Connection and per-VM wizards for the given connection.
|
2020-09-17 22:43:39 +02:00
|
|
|
|
Program.MainWindow.CloseActiveWizards(_host.Connection);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
DisableButtons();
|
|
|
|
|
progressBar1.Visible = true;
|
|
|
|
|
pictureBoxStatus.Visible = false;
|
|
|
|
|
tableLayoutPanelStatus.Visible = true;
|
|
|
|
|
hostAction.RunAsync(GetSudoElevationResult());
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
private void CloseButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
|
|
|
|
|
private void EvacuateHostDialog_FormClosed(object sender, FormClosedEventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
vmErrorsAction?.Cancel();
|
|
|
|
|
hostAction?.Cancel();
|
|
|
|
|
|
|
|
|
|
if (_host != null)
|
|
|
|
|
_host.PropertyChanged -= hostUpdate;
|
|
|
|
|
if (_pool != null)
|
|
|
|
|
_pool.PropertyChanged -= poolUpdate;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
foreach (var h in connection.Cache.Hosts)
|
|
|
|
|
h.PropertyChanged -= host_PropertyChanged;
|
|
|
|
|
|
|
|
|
|
foreach (DataGridViewRow row in dataGridViewVms.Rows)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
if (row is VmPrecheckRow precheckRow)
|
|
|
|
|
{
|
|
|
|
|
DeregisterVmRowEvents(precheckRow);
|
|
|
|
|
precheckRow.SolutionAction?.Cancel();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (elevatedSession != null && elevatedSession.opaque_ref != null)
|
|
|
|
|
{
|
|
|
|
|
// NOTE: This doesnt happen currently, as we always scan once. Here as cheap insurance.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
// we still have the session from the role elevation dialog
|
2020-09-17 22:43:39 +02:00
|
|
|
|
// it hasn't been used by an action so needs to be logged out
|
|
|
|
|
elevatedSession.logout();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
#endregion
|
2013-11-01 10:24:24 +01:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
|
|
|
|
|
private void HostAction_Changed(ActionBase obj)
|
2013-11-01 10:24:24 +01:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
if (obj != hostAction)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Program.Invoke(this, UpdateProgress);
|
2013-11-01 10:24:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
private void HostAction_Completed(ActionBase obj)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
if (obj != hostAction)
|
|
|
|
|
return;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
hostAction.Changed -= HostAction_Changed;
|
|
|
|
|
hostAction.Completed -= HostAction_Completed;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
Program.Invoke(this, () =>
|
|
|
|
|
{
|
|
|
|
|
if (hostAction.Succeeded)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
Close();
|
2020-09-17 22:43:39 +02:00
|
|
|
|
return;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
UpdateProgress();
|
|
|
|
|
EnableButtons();
|
|
|
|
|
pictureBoxStatus.Visible = true;
|
|
|
|
|
tableLayoutPanelStatus.Visible = true;
|
|
|
|
|
progressBar1.Visible = false;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
if (hostAction.Exception is Failure failure && failure.ErrorDescription.Count > 0 &&
|
|
|
|
|
(failure.ErrorDescription[0] == Failure.HOST_NOT_ENOUGH_FREE_MEMORY ||
|
|
|
|
|
failure.ErrorDescription[0] == Failure.HA_NO_PLAN))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
if (failure.ErrorDescription[0] == Failure.HOST_NOT_ENOUGH_FREE_MEMORY)
|
|
|
|
|
labelProgress.Text = Messages.EVACUATE_HOST_NOT_ENOUGH_MEMORY;
|
|
|
|
|
else if (failure.ErrorDescription[0] == Failure.HA_NO_PLAN)
|
|
|
|
|
labelProgress.Text = Messages.EVACUATE_HOST_NO_OTHER_HOSTS;
|
2020-03-04 13:47:22 +01:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
UpdateVMWithError(failure.ErrorDescription.ToArray());
|
2020-03-04 13:47:22 +01:00
|
|
|
|
}
|
2020-09-17 22:43:39 +02:00
|
|
|
|
else
|
|
|
|
|
labelProgress.Text = hostAction.Exception.Message;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
if (_rebuildRequired)
|
|
|
|
|
Rebuild();
|
|
|
|
|
});
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
private void UpdateProgress()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
labelProgress.Text = hostAction.Description;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
if (hostAction.PercentComplete < 0)
|
|
|
|
|
progressBar1.Value = 0;
|
|
|
|
|
else if (hostAction.PercentComplete > 100)
|
|
|
|
|
progressBar1.Value = 100;
|
|
|
|
|
else
|
|
|
|
|
progressBar1.Value = hostAction.PercentComplete;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
|
|
|
|
|
#region Nested items
|
2016-03-11 14:53:12 +01:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
enum Solution { None, EjectCD, Suspend, InstallPVDrivers, InstallPVDriversNoSolution, Shutdown }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
private class VmPrecheckRow : DataGridViewRow, IComparable<VmPrecheckRow>
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
public readonly VM vm;
|
|
|
|
|
private AsyncAction _solutionAction;
|
|
|
|
|
private string error = string.Empty;
|
2013-10-24 15:05:01 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
public Solution Solution { get; private set; } = Solution.None;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
public AsyncAction SolutionAction
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
get => _solutionAction;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_solutionAction = value;
|
|
|
|
|
|
|
|
|
|
if (HasSolutionActionInProgress())
|
2020-03-29 03:06:35 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
Solution = Solution.None;
|
|
|
|
|
error = _solutionAction.Title;
|
2020-03-29 03:06:35 +02:00
|
|
|
|
}
|
2020-09-17 22:43:39 +02:00
|
|
|
|
|
|
|
|
|
Refresh();
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
private readonly DataGridViewImageCell cellImage = new DataGridViewImageCell();
|
|
|
|
|
private readonly DataGridViewTextBoxCell cellVm = new DataGridViewTextBoxCell();
|
|
|
|
|
private readonly DataGridViewTextBoxCell cellAction = new DataGridViewTextBoxCell();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
public VmPrecheckRow(VM vm)
|
|
|
|
|
{
|
|
|
|
|
this.vm = vm;
|
|
|
|
|
Cells.AddRange(cellImage, cellVm, cellAction);
|
|
|
|
|
Refresh();
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
public void Refresh()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
cellImage.Value = Images.GetImage16For(vm);
|
|
|
|
|
cellVm.Value = ToString();
|
|
|
|
|
cellAction.Value = error;
|
|
|
|
|
|
|
|
|
|
if (HasSolution())
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
cellAction.Style.Font = new Font(Program.DefaultFont, FontStyle.Underline);
|
|
|
|
|
cellAction.Style.ForeColor = Color.Blue;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cellAction.Style.Font = Program.DefaultFont;
|
|
|
|
|
cellAction.Style.ForeColor = DefaultForeColor;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2020-09-17 22:43:39 +02:00
|
|
|
|
|
|
|
|
|
cellAction.Style.SelectionForeColor = cellAction.Style.ForeColor;
|
|
|
|
|
cellAction.Style.SelectionBackColor = cellAction.Style.BackColor;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
public override string ToString()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
return vm.Name();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
public int CompareTo(VmPrecheckRow otherVM)
|
|
|
|
|
{
|
|
|
|
|
return vm.CompareTo(otherVM?.vm);
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
public void SetError(string message, Solution solution)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
// still running action to solve a previous error, no point in overwriting or we could end up 'solving' it twice
|
|
|
|
|
if (HasSolutionActionInProgress())
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
Solution = Solution.None;
|
|
|
|
|
error = SolutionAction.Title;
|
|
|
|
|
Refresh();
|
|
|
|
|
return;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2020-09-17 22:43:39 +02:00
|
|
|
|
|
|
|
|
|
Solution = solution;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
switch (solution)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
case Solution.EjectCD:
|
|
|
|
|
error = String.Format(Messages.EVACUATE_HOST_EJECT_CD_PROMPT, message);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Solution.Suspend:
|
|
|
|
|
error = String.Format(Messages.EVACUATE_HOST_SUSPEND_VM_PROMPT, message);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Solution.Shutdown:
|
|
|
|
|
error = String.Format(Messages.EVACUATE_HOST_SHUTDOWN_VM_PROMPT, message);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Solution.InstallPVDrivers:
|
2021-03-16 02:50:45 +01:00
|
|
|
|
error = vm.HasNewVirtualisationStates()
|
|
|
|
|
? string.Format(Messages.EVACUATE_HOST_INSTALL_MGMNT_PROMPT, message)
|
|
|
|
|
: string.Format(Messages.EVACUATE_HOST_INSTALL_TOOLS_PROMPT, message, BrandManager.VmTools);
|
2020-09-17 22:43:39 +02:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Solution.InstallPVDriversNoSolution:
|
|
|
|
|
// if the state is not unknown we have metrics and can show a detailed message.
|
|
|
|
|
// Otherwise go with the server and just say they aren't installed
|
|
|
|
|
error = !vm.GetVirtualisationStatus(out _).HasFlag(VM.VirtualisationStatus.UNKNOWN)
|
|
|
|
|
? vm.GetVirtualisationWarningMessages()
|
2021-03-16 02:50:45 +01:00
|
|
|
|
: string.Format(Messages.PV_DRIVERS_NOT_INSTALLED, BrandManager.VmTools);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
Refresh();
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
internal bool HasSolution()
|
|
|
|
|
{
|
|
|
|
|
return Solution != Solution.None
|
|
|
|
|
&& Solution != Solution.InstallPVDriversNoSolution;
|
|
|
|
|
}
|
2017-01-31 15:35:59 +01:00
|
|
|
|
|
2020-09-17 22:43:39 +02:00
|
|
|
|
internal bool HasSolutionActionInProgress()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-17 22:43:39 +02:00
|
|
|
|
return SolutionAction != null && !SolutionAction.IsCompleted;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-17 22:43:39 +02:00
|
|
|
|
|
|
|
|
|
#endregion
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|