CA-249858: XenCenter gives different messages for migrate VM at different screens when pool connected with vm-operator user

Expose the reasons why a cross pool migration command cannot execute.

Signed-off-by: Mihaela Stoica <mihaela.stoica@citrix.com>
This commit is contained in:
Mihaela Stoica 2017-06-13 13:12:01 +01:00
parent bb5235ca40
commit 8f6c345c66
2 changed files with 43 additions and 6 deletions

View File

@ -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;

View File

@ -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.TrimEnd('\n', '\r'));
}
}
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;
}
}
}
}