Merge pull request #1642 from MihaelaStoica/CA-249858

CA-249858: XenCenter gives different messages for migrate VM at diffe…
This commit is contained in:
Gabor Apati-Nagy 2017-06-13 16:53:19 +01:00 committed by GitHub
commit 4e8541fb91
3 changed files with 44 additions and 7 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);
}
}
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;
}
}
}
}

View File

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