CP-11032: Allow cross-pool move of stopped and suspended VMs

Changes following code review:
- add static methods to the cross pool migrate and move commands to determine if the command can execute
- In the Cross Pool migrate wizard: add Transfer network page for cross-pool move (and copy) operation (as well as all migrate cases)

Signed-off-by: Mihaela Stoica <mihaela.stoica@citrix.com>
This commit is contained in:
Mihaela Stoica 2015-03-24 17:14:03 +00:00
parent d616009824
commit cbedbd43cd
4 changed files with 27 additions and 24 deletions

View File

@ -98,12 +98,17 @@ namespace XenAdmin.Commands
}
protected override bool CanExecute(VM vm)
{
return CanExecute(vm, preSelectedHost);
}
public static bool CanExecute(VM vm, Host preselectedHost)
{
bool failureFound = false;
if(preSelectedHost != null)
if (preselectedHost != null)
{
failureFound = new CrossPoolMigrateCanMigrateFilter(preSelectedHost, new List<VM> { vm }).FailureFound;
failureFound = new CrossPoolMigrateCanMigrateFilter(preselectedHost, new List<VM> { vm }).FailureFound;
}
return !failureFound &&
@ -111,7 +116,7 @@ namespace XenAdmin.Commands
vm.allowed_operations.Contains(vm_operations.migrate_send) &&
!Helpers.WlbEnabledAndConfigured(vm.Connection) &&
vm.SRs.ToList().All(sr=> sr != null && !sr.HBALunPerVDI) &&
(vm.Connection.Resolve(vm.resident_on) == null || vm.Connection.Resolve(vm.resident_on) != preSelectedHost); //Not the same as the pre-selected host
(preselectedHost == null || vm.Connection.Resolve(vm.resident_on) != preselectedHost); //Not the same as the pre-selected host
}
}
}

View File

@ -67,9 +67,15 @@ namespace XenAdmin.Commands
protected override bool CanExecute(VM vm)
{
if (vm == null || vm.is_a_template || vm.Locked)
return CanExecute(vm, preSelectedHost);
}
public new static bool CanExecute(VM vm, Host preSelectedHost)
{
if (vm == null || vm.is_a_template || vm.Locked || vm.power_state == vm_power_state.Running)
return false;
return base.CanExecute(vm);
return CrossPoolMigrateCommand.CanExecute(vm, preSelectedHost);
}
}
}

View File

@ -67,23 +67,20 @@ namespace XenAdmin.Commands
{
VM vm = (VM)selection[0].XenObject;
var cmd = new CrossPoolMoveVMCommand(MainWindowCommandInterface, selection);
if (cmd.CanExecute())
cmd.Execute();
if (CrossPoolMoveVMCommand.CanExecute(vm, null))
new CrossPoolMoveVMCommand(MainWindowCommandInterface, selection).Execute();
else
MainWindowCommandInterface.ShowPerXenModelObjectWizard(vm, new MoveVMDialog(vm));
}
protected override bool CanExecuteCore(SelectedItemCollection selection)
{
if (new CrossPoolMoveVMCommand(MainWindowCommandInterface, selection).CanExecute())
return true;
return selection.ContainsOneItemOfType<VM>() && selection.AtLeastOneXenObjectCan<VM>(CanExecute);
}
private static bool CanExecute(VM vm)
{
return vm != null && vm.CanBeMoved;
return vm != null && (CrossPoolMoveVMCommand.CanExecute(vm, null) || vm.CanBeMoved);
}
public override string MenuText

View File

@ -101,7 +101,7 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard
return true;
}
Host host = xenConnection.Resolve(vm.resident_on);
Host host = xenConnection.Resolve(vm.resident_on) ?? Helpers.GetMaster(xenConnection);
if (mapping.Value.XenRef is XenRef<Host>)
{
Host targetHost = TargetConnection.Resolve(mapping.Value.XenRef as XenRef<Host>);
@ -140,10 +140,7 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard
m_pageFinish = new CrossPoolMigrateFinishPage {SummaryRetreiver = GetVMMappingSummary};
m_pageTargetRbac = new RBACWarningPage();
if (wizardMode == WizardMode.Migrate)
AddPages(m_pageDestination, m_pageStorage, m_pageTransferNetwork, m_pageFinish);
else
AddPages(m_pageDestination, m_pageStorage, m_pageFinish);
AddPages(m_pageDestination, m_pageStorage, m_pageFinish);
}
public override sealed string Text
@ -184,13 +181,6 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard
if(target == null)
throw new ApplicationException("Cannot resolve the target host");
if (SelectedTransferNetwork == null)
{
// select management interface
var managementPif = NetworkingHelper.GetManagementPIF(target);
SelectedTransferNetwork = TargetConnection.Resolve(managementPif.network);
}
if (wizardMode == WizardMode.Move && IsIntraPoolMigration(pair) && vm.CanBeMoved)
{
new VMMoveAction(vm, pair.Value.Storage, target).RunAsync();
@ -249,15 +239,20 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard
if (type == typeof(CrossPoolMigrateDestinationPage))
{
RemovePage(m_pageNetwork);
RemovePage(m_pageTransferNetwork);
RemovePage(m_pageTargetRbac);
m_vmMappings = m_pageDestination.VmMappings;
TargetConnection = m_pageDestination.Connection;
m_pageStorage.TargetConnection = TargetConnection;
m_pageNetwork.TargetConnection = TargetConnection;
m_pageTransferNetwork.Connection = TargetConnection;
ConfigureRbacPage();
AddHostNameToWindowTitle();
// add Transfer network page for all migration cases and for all other cross-pool operations (move, copy)
if (wizardMode == WizardMode.Migrate || !IsIntraPoolMigration())
AddAfterPage(m_pageStorage, m_pageTransferNetwork);
m_pageTransferNetwork.Connection = TargetConnection;
if(!IsIntraPoolMigration())
{
AddAfterPage(m_pageStorage, m_pageNetwork);