mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2024-11-25 14:27:26 +01:00
Merge pull request #1642 from MihaelaStoica/CA-249858
CA-249858: XenCenter gives different messages for migrate VM at diffe…
This commit is contained in:
commit
4e8541fb91
@ -200,13 +200,13 @@ namespace XenAdmin.Commands
|
||||
if (host != null)
|
||||
{
|
||||
VMOperationCommand cmd = new VMOperationHostCommand(Command.MainWindowCommandInterface, selection, delegate { return host; }, host.Name.EscapeAmpersands(), _operation, session);
|
||||
VMOperationCommand cpmCmd = new CrossPoolMigrateCommand(Command.MainWindowCommandInterface, selection, host, _resumeAfter);
|
||||
CrossPoolMigrateCommand cpmCmd = new CrossPoolMigrateCommand(Command.MainWindowCommandInterface, selection, host, _resumeAfter);
|
||||
|
||||
VMOperationToolStripMenuSubItem tempItem = item;
|
||||
Program.Invoke(Program.MainWindow, delegate
|
||||
{
|
||||
bool oldMigrateCmdCanRun = cmd.CanExecute();
|
||||
if (_operation == vm_operations.start_on || !oldMigrateCmdCanRun && !cpmCmd.CanExecute())
|
||||
if (_operation == vm_operations.start_on || (!oldMigrateCmdCanRun && !cpmCmd.CanExecute() && string.IsNullOrEmpty(cpmCmd.CantExecuteReason)))
|
||||
tempItem.Command = cmd;
|
||||
else
|
||||
tempItem.Command = oldMigrateCmdCanRun ? cmd : cpmCmd;
|
||||
|
@ -63,7 +63,16 @@ namespace XenAdmin.Commands
|
||||
|
||||
public override string MenuText
|
||||
{
|
||||
get { return preSelectedHost == null ? Messages.HOST_MENU_CPM_TEXT : preSelectedHost.Name.EscapeAmpersands(); }
|
||||
get
|
||||
{
|
||||
if (preSelectedHost == null)
|
||||
return Messages.HOST_MENU_CPM_TEXT;
|
||||
|
||||
var cantExecuteReason = CantExecuteReason;
|
||||
return string.IsNullOrEmpty(cantExecuteReason)
|
||||
? preSelectedHost.Name.EscapeAmpersands()
|
||||
: string.Format(Messages.MAINWINDOW_CONTEXT_REASON, preSelectedHost.Name.EscapeAmpersands(), cantExecuteReason);
|
||||
}
|
||||
}
|
||||
|
||||
public override string ContextMenuText { get { return Messages.HOST_MENU_CPM_TEXT; } }
|
||||
@ -100,18 +109,31 @@ namespace XenAdmin.Commands
|
||||
dlg.ShowDialog(parent);
|
||||
}
|
||||
|
||||
private readonly Dictionary<VM, string> cantExecuteReasons = new Dictionary<VM, string>();
|
||||
|
||||
protected override bool CanExecute(VM vm)
|
||||
{
|
||||
return CanExecute(vm, preSelectedHost);
|
||||
if (preSelectedHost == null)
|
||||
return CanExecute(vm, preSelectedHost);
|
||||
|
||||
var filter = new CrossPoolMigrateCanMigrateFilter(preSelectedHost, new List<VM> {vm}, WizardMode.Migrate);
|
||||
var canExecute = CanExecute(vm, preSelectedHost, filter);
|
||||
if (string.IsNullOrEmpty(filter.Reason))
|
||||
cantExecuteReasons.Remove(vm);
|
||||
else
|
||||
cantExecuteReasons[vm] = filter.Reason;
|
||||
return canExecute;
|
||||
}
|
||||
|
||||
public static bool CanExecute(VM vm, Host preselectedHost)
|
||||
public static bool CanExecute(VM vm, Host preselectedHost, CrossPoolMigrateCanMigrateFilter filter = null)
|
||||
{
|
||||
bool failureFound = false;
|
||||
|
||||
if (preselectedHost != null)
|
||||
{
|
||||
failureFound = new CrossPoolMigrateCanMigrateFilter(preselectedHost, new List<VM> {vm}, WizardMode.Migrate).FailureFound;
|
||||
failureFound = filter == null
|
||||
? new CrossPoolMigrateCanMigrateFilter(preselectedHost, new List<VM> {vm}, WizardMode.Migrate).FailureFound
|
||||
: filter.FailureFound;
|
||||
}
|
||||
|
||||
return !failureFound &&
|
||||
@ -121,5 +143,20 @@ namespace XenAdmin.Commands
|
||||
vm.SRs.ToList().All(sr=> sr != null && !sr.HBALunPerVDI) &&
|
||||
(preselectedHost == null || vm.Connection.Resolve(vm.resident_on) != preselectedHost); //Not the same as the pre-selected host
|
||||
}
|
||||
|
||||
public string CantExecuteReason
|
||||
{
|
||||
get
|
||||
{
|
||||
if (cantExecuteReasons.Count == GetSelection().Count) // none can execute
|
||||
{
|
||||
var uniqueReasons = cantExecuteReasons.Values.Distinct().ToList();
|
||||
|
||||
if (uniqueReasons.Count == 1)
|
||||
return uniqueReasons[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard.Filters
|
||||
catch (Failure failure)
|
||||
{
|
||||
if (failure.ErrorDescription.Count > 0 && failure.ErrorDescription[0] == Failure.RBAC_PERMISSION_DENIED)
|
||||
disableReason = failure.Message.Split('\n')[0]; // we want the first line only
|
||||
disableReason = failure.Message.Split('\n')[0].TrimEnd('\r'); // we want the first line only
|
||||
else
|
||||
disableReason = failure.Message;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user