From 70f61c0cd70093fbb53fe296484e87dfdead4bb0 Mon Sep 17 00:00:00 2001 From: Alexander Schulz Date: Mon, 16 Jul 2018 23:06:58 +0200 Subject: [PATCH] Add new MenuItem to Force Migrate a VM --- .../Controls/MigrateVMToolStripMenuItem.cs | 9 +++++-- .../Controls/VMOperationToolStripMenuItem.cs | 4 +-- XenAdmin/Commands/CopyTemplateCommand.cs | 4 +-- XenAdmin/Commands/CopyVMCommand.cs | 4 +-- XenAdmin/Commands/CrossPoolCopyVMCommand.cs | 24 ++++++++--------- XenAdmin/Commands/CrossPoolMigrateCommand.cs | 26 ++++++++++++------- .../Commands/CrossPoolMigrateToHomeCommand.cs | 4 +-- XenAdmin/Commands/CrossPoolMoveVMCommand.cs | 14 +++++----- .../DragDropCrossPoolMoveHaltedVMCommand.cs | 2 +- XenAdmin/Commands/DragDropMigrateVMCommand.cs | 2 +- XenAdmin/Commands/MoveVMCommand.cs | 2 +- .../CrossPoolMigrateDestinationPage.cs | 11 +++++--- .../CrossPoolMigrateWizard.cs | 15 ++++++++--- .../CrossPoolMigrateCanMigrateFilter.cs | 11 +++++--- .../Actions/VM/VMCrossPoolMigrateAction.cs | 2 +- 15 files changed, 81 insertions(+), 53 deletions(-) diff --git a/XenAdmin/Commands/Controls/MigrateVMToolStripMenuItem.cs b/XenAdmin/Commands/Controls/MigrateVMToolStripMenuItem.cs index eb885e4d3..dca142f0b 100644 --- a/XenAdmin/Commands/Controls/MigrateVMToolStripMenuItem.cs +++ b/XenAdmin/Commands/Controls/MigrateVMToolStripMenuItem.cs @@ -59,10 +59,15 @@ namespace XenAdmin.Commands { if (selection.ToList().All(item => !Helpers.CrossPoolMigrationRestrictedWithWlb(item.Connection))) { - VMOperationCommand cmd = new CrossPoolMigrateCommand(Command.MainWindowCommandInterface, selection); DropDownItems.Add(new ToolStripSeparator()); + + VMOperationCommand cmd = new CrossPoolMigrateCommand(Command.MainWindowCommandInterface, selection, false); VMOperationToolStripMenuSubItem lastItem = new VMOperationToolStripMenuSubItem(cmd); - DropDownItems.Add(lastItem); + DropDownItems.Add(lastItem); + + VMOperationCommand cmdForce = new CrossPoolMigrateCommand(Command.MainWindowCommandInterface, selection, true); + VMOperationToolStripMenuSubItem lastItemForce = new VMOperationToolStripMenuSubItem(cmdForce); + DropDownItems.Add(lastItemForce); } } diff --git a/XenAdmin/Commands/Controls/VMOperationToolStripMenuItem.cs b/XenAdmin/Commands/Controls/VMOperationToolStripMenuItem.cs index 593c9f238..95e55e75a 100644 --- a/XenAdmin/Commands/Controls/VMOperationToolStripMenuItem.cs +++ b/XenAdmin/Commands/Controls/VMOperationToolStripMenuItem.cs @@ -299,8 +299,8 @@ namespace XenAdmin.Commands else { var cpmCmd = isHomeServer - ? new CrossPoolMigrateToHomeCommand(menu.Command.MainWindowCommandInterface, selection, host) - : new CrossPoolMigrateCommand(menu.Command.MainWindowCommandInterface, selection, host, menu._resumeAfter); + ? new CrossPoolMigrateToHomeCommand(menu.Command.MainWindowCommandInterface, selection, host, false) + : new CrossPoolMigrateCommand(menu.Command.MainWindowCommandInterface, selection, host, false, menu._resumeAfter); var crossPoolMigrateCmdCanRun = cpmCmd.CanExecute(); if (Stopped) diff --git a/XenAdmin/Commands/CopyTemplateCommand.cs b/XenAdmin/Commands/CopyTemplateCommand.cs index 3729aef8c..3bf93c755 100644 --- a/XenAdmin/Commands/CopyTemplateCommand.cs +++ b/XenAdmin/Commands/CopyTemplateCommand.cs @@ -66,7 +66,7 @@ namespace XenAdmin.Commands { VM template = (VM)selection[0].XenObject; - if (CrossPoolCopyTemplateCommand.CanExecute(template, null)) + if (CrossPoolCopyTemplateCommand.CanExecute(template, null, false)) new CrossPoolCopyTemplateCommand(MainWindowCommandInterface, selection).Execute(); else MainWindowCommandInterface.ShowPerXenModelObjectWizard(template, new CopyVMDialog(template)); @@ -81,7 +81,7 @@ namespace XenAdmin.Commands { if (vm != null && vm.is_a_template && !vm.is_a_snapshot && !vm.Locked && vm.allowed_operations != null && !vm.InternalTemplate()) { - if (CrossPoolCopyTemplateCommand.CanExecute(vm, null)) + if (CrossPoolCopyTemplateCommand.CanExecute(vm, null, false)) return true; if (vm.allowed_operations.Contains(vm_operations.clone) || vm.allowed_operations.Contains(vm_operations.copy)) return true; diff --git a/XenAdmin/Commands/CopyVMCommand.cs b/XenAdmin/Commands/CopyVMCommand.cs index ee9713260..7f5197cae 100644 --- a/XenAdmin/Commands/CopyVMCommand.cs +++ b/XenAdmin/Commands/CopyVMCommand.cs @@ -66,7 +66,7 @@ namespace XenAdmin.Commands { VM vm = (VM)selection[0].XenObject; - if (CrossPoolCopyVMCommand.CanExecute(vm, null)) + if (CrossPoolCopyVMCommand.CanExecute(vm, null, false)) new CrossPoolCopyVMCommand(MainWindowCommandInterface, selection).Execute(); else MainWindowCommandInterface.ShowPerXenModelObjectWizard(vm, new CopyVMDialog(vm)); @@ -79,7 +79,7 @@ namespace XenAdmin.Commands private static bool CanExecute(VM vm) { - return vm != null && (CrossPoolCopyVMCommand.CanExecute(vm, null) || vm.CanBeCopied()); + return vm != null && (CrossPoolCopyVMCommand.CanExecute(vm, null, false) || vm.CanBeCopied()); } public override string MenuText diff --git a/XenAdmin/Commands/CrossPoolCopyVMCommand.cs b/XenAdmin/Commands/CrossPoolCopyVMCommand.cs index 012e4b341..305486896 100644 --- a/XenAdmin/Commands/CrossPoolCopyVMCommand.cs +++ b/XenAdmin/Commands/CrossPoolCopyVMCommand.cs @@ -40,11 +40,11 @@ namespace XenAdmin.Commands internal class CrossPoolCopyVMCommand : CrossPoolMigrateCommand { public CrossPoolCopyVMCommand(IMainWindow mainWindow, IEnumerable selection) - : this(mainWindow, selection, null) + : this(mainWindow, selection, null, false) { } - public CrossPoolCopyVMCommand(IMainWindow mainWindow, IEnumerable selection, Host preSelectedHost) - : base(mainWindow, selection, preSelectedHost) + public CrossPoolCopyVMCommand(IMainWindow mainWindow, IEnumerable selection, Host preSelectedHost, bool force) + : base(mainWindow, selection, preSelectedHost, force) { } @@ -58,31 +58,31 @@ namespace XenAdmin.Commands var con = selection.GetConnectionOfFirstItem(); MainWindowCommandInterface.ShowPerConnectionWizard(con, - new CrossPoolMigrateWizard(con, selection, preSelectedHost, WizardMode.Copy)); + new CrossPoolMigrateWizard(con, selection, preSelectedHost, WizardMode.Copy, false)); } protected override bool CanExecute(VM vm) { - return CanExecute(vm, preSelectedHost); + return CanExecute(vm, preSelectedHost, _force); } - public static bool CanExecute(VM vm, Host preSelectedHost) + public static bool CanExecute(VM vm, Host preSelectedHost, bool force) { if (vm == null || vm.is_a_template || vm.Locked || vm.power_state != vm_power_state.Halted) return false; - return CrossPoolMigrateCommand.CanExecute(vm, preSelectedHost); + return CrossPoolMigrateCommand.CanExecute(vm, preSelectedHost, force); } } internal class CrossPoolCopyTemplateCommand : CrossPoolCopyVMCommand { public CrossPoolCopyTemplateCommand(IMainWindow mainWindow, IEnumerable selection) - : this(mainWindow, selection, null) + : this(mainWindow, selection, null, false) { } - public CrossPoolCopyTemplateCommand(IMainWindow mainWindow, IEnumerable selection, Host preSelectedHost) - : base(mainWindow, selection, preSelectedHost) + public CrossPoolCopyTemplateCommand(IMainWindow mainWindow, IEnumerable selection, Host preSelectedHost, bool force) + : base(mainWindow, selection, preSelectedHost, force) { } @@ -91,12 +91,12 @@ namespace XenAdmin.Commands get { return Messages.MAINWINDOW_COPY_TEMPLATE; } } - public new static bool CanExecute(VM vm, Host preSelectedHost) + public new static bool CanExecute(VM vm, Host preSelectedHost, bool force) { if (vm == null || !vm.is_a_template || vm.DefaultTemplate() || vm.Locked) return false; - return CrossPoolMigrateCommand.CanExecute(vm, preSelectedHost); + return CrossPoolMigrateCommand.CanExecute(vm, preSelectedHost, force); } } } diff --git a/XenAdmin/Commands/CrossPoolMigrateCommand.cs b/XenAdmin/Commands/CrossPoolMigrateCommand.cs index da2af6cc8..68107ff59 100644 --- a/XenAdmin/Commands/CrossPoolMigrateCommand.cs +++ b/XenAdmin/Commands/CrossPoolMigrateCommand.cs @@ -48,17 +48,21 @@ namespace XenAdmin.Commands internal class CrossPoolMigrateCommand : VMOperationCommand { private bool _resumeAfter; + internal bool _force = false; - public CrossPoolMigrateCommand(IMainWindow mainWindow, IEnumerable selection) + public CrossPoolMigrateCommand(IMainWindow mainWindow, IEnumerable selection, bool force) : base(mainWindow, selection) - { } + { + _force = force; + } protected Host preSelectedHost = null; - public CrossPoolMigrateCommand(IMainWindow mainWindow, IEnumerable selection, Host preSelectedHost, bool resumeAfter=false) + public CrossPoolMigrateCommand(IMainWindow mainWindow, IEnumerable selection, Host preSelectedHost, bool force, bool resumeAfter=false) : base(mainWindow, selection) { this.preSelectedHost = preSelectedHost; _resumeAfter = resumeAfter; + _force = force; } public override string MenuText @@ -66,7 +70,11 @@ namespace XenAdmin.Commands get { if (preSelectedHost == null) + { + if (_force) + return "Force " + Messages.HOST_MENU_CPM_TEXT; return Messages.HOST_MENU_CPM_TEXT; + } var cantExecuteReason = CantExecuteReason; return string.IsNullOrEmpty(cantExecuteReason) @@ -92,7 +100,7 @@ namespace XenAdmin.Commands } else { - var wizard = new CrossPoolMigrateWizard(con, selection, preSelectedHost, WizardMode.Migrate, _resumeAfter); + var wizard = new CrossPoolMigrateWizard(con, selection, preSelectedHost, WizardMode.Migrate, _force, _resumeAfter); MainWindowCommandInterface.ShowPerConnectionWizard(con, wizard); } } @@ -114,10 +122,10 @@ namespace XenAdmin.Commands protected override bool CanExecute(VM vm) { if (preSelectedHost == null) - return CanExecute(vm, preSelectedHost); + return CanExecute(vm, preSelectedHost, _force); - var filter = new CrossPoolMigrateCanMigrateFilter(preSelectedHost, new List {vm}, WizardMode.Migrate); - var canExecute = CanExecute(vm, preSelectedHost, filter); + var filter = new CrossPoolMigrateCanMigrateFilter(preSelectedHost, new List {vm}, WizardMode.Migrate, _force); + var canExecute = CanExecute(vm, preSelectedHost, _force, filter); if (string.IsNullOrEmpty(filter.Reason)) cantExecuteReasons.Remove(vm); else @@ -125,14 +133,14 @@ namespace XenAdmin.Commands return canExecute; } - public static bool CanExecute(VM vm, Host preselectedHost, CrossPoolMigrateCanMigrateFilter filter = null) + public static bool CanExecute(VM vm, Host preselectedHost, bool force, CrossPoolMigrateCanMigrateFilter filter = null) { bool failureFound = false; if (preselectedHost != null) { failureFound = filter == null - ? new CrossPoolMigrateCanMigrateFilter(preselectedHost, new List {vm}, WizardMode.Migrate).FailureFound + ? new CrossPoolMigrateCanMigrateFilter(preselectedHost, new List {vm}, WizardMode.Migrate, force).FailureFound : filter.FailureFound; } diff --git a/XenAdmin/Commands/CrossPoolMigrateToHomeCommand.cs b/XenAdmin/Commands/CrossPoolMigrateToHomeCommand.cs index af03dd760..1ea24da65 100644 --- a/XenAdmin/Commands/CrossPoolMigrateToHomeCommand.cs +++ b/XenAdmin/Commands/CrossPoolMigrateToHomeCommand.cs @@ -42,8 +42,8 @@ namespace XenAdmin.Commands /// internal class CrossPoolMigrateToHomeCommand : CrossPoolMigrateCommand { - public CrossPoolMigrateToHomeCommand(IMainWindow mainWindow, IEnumerable selection, Host preSelectedHost) - : base(mainWindow, selection, preSelectedHost) + public CrossPoolMigrateToHomeCommand(IMainWindow mainWindow, IEnumerable selection, Host preSelectedHost, bool force) + : base(mainWindow, selection, preSelectedHost, force) { } diff --git a/XenAdmin/Commands/CrossPoolMoveVMCommand.cs b/XenAdmin/Commands/CrossPoolMoveVMCommand.cs index 0a0d8e8e0..c4a203e3d 100644 --- a/XenAdmin/Commands/CrossPoolMoveVMCommand.cs +++ b/XenAdmin/Commands/CrossPoolMoveVMCommand.cs @@ -40,11 +40,11 @@ namespace XenAdmin.Commands internal class CrossPoolMoveVMCommand : CrossPoolMigrateCommand { public CrossPoolMoveVMCommand(IMainWindow mainWindow, IEnumerable selection) - : this(mainWindow, selection, null) + : this(mainWindow, selection, null, false) { } - public CrossPoolMoveVMCommand(IMainWindow mainWindow, IEnumerable selection, Host preSelectedHost) - : base(mainWindow, selection, preSelectedHost) + public CrossPoolMoveVMCommand(IMainWindow mainWindow, IEnumerable selection, Host preSelectedHost, bool force) + : base(mainWindow, selection, preSelectedHost, force) { } @@ -64,22 +64,22 @@ namespace XenAdmin.Commands else { MainWindowCommandInterface.ShowPerConnectionWizard(con, - new CrossPoolMigrateWizard(con, selection, preSelectedHost, GetWizardMode(selection))); + new CrossPoolMigrateWizard(con, selection, preSelectedHost, GetWizardMode(selection), _force)); } } protected override bool CanExecute(VM vm) { - return CanExecute(vm, preSelectedHost); + return CanExecute(vm, preSelectedHost, _force); } - public static bool CanExecute(VM vm, Host preSelectedHost) + public static bool CanExecute(VM vm, Host preSelectedHost, bool force) { if (vm == null || vm.is_a_template || vm.Locked || vm.power_state == vm_power_state.Running) return false; - return CrossPoolMigrateCommand.CanExecute(vm, preSelectedHost); + return CrossPoolMigrateCommand.CanExecute(vm, preSelectedHost, force); } public static WizardMode GetWizardMode(SelectedItemCollection selection) diff --git a/XenAdmin/Commands/DragDropCrossPoolMoveHaltedVMCommand.cs b/XenAdmin/Commands/DragDropCrossPoolMoveHaltedVMCommand.cs index 240233839..523683d29 100644 --- a/XenAdmin/Commands/DragDropCrossPoolMoveHaltedVMCommand.cs +++ b/XenAdmin/Commands/DragDropCrossPoolMoveHaltedVMCommand.cs @@ -180,7 +180,7 @@ namespace XenAdmin.Commands List selectedItems = new List(); draggedVMs.ForEach(vm => selectedItems.Add(new SelectedItem(vm))); - new CrossPoolMoveVMCommand(MainWindowCommandInterface, selectedItems, targetHost) + new CrossPoolMoveVMCommand(MainWindowCommandInterface, selectedItems, targetHost, false) .Execute(); } } diff --git a/XenAdmin/Commands/DragDropMigrateVMCommand.cs b/XenAdmin/Commands/DragDropMigrateVMCommand.cs index c9b1c214c..7d0a3ba9a 100644 --- a/XenAdmin/Commands/DragDropMigrateVMCommand.cs +++ b/XenAdmin/Commands/DragDropMigrateVMCommand.cs @@ -230,7 +230,7 @@ namespace XenAdmin.Commands { List selectedItems = new List(); draggedVMs.ForEach(vm => selectedItems.Add(new SelectedItem(vm))); - new CrossPoolMigrateCommand(MainWindowCommandInterface, selectedItems, targetHost).Execute(); + new CrossPoolMigrateCommand(MainWindowCommandInterface, selectedItems, targetHost, false).Execute(); return; } } diff --git a/XenAdmin/Commands/MoveVMCommand.cs b/XenAdmin/Commands/MoveVMCommand.cs index d58213fde..63221303e 100644 --- a/XenAdmin/Commands/MoveVMCommand.cs +++ b/XenAdmin/Commands/MoveVMCommand.cs @@ -95,7 +95,7 @@ namespace XenAdmin.Commands private static bool CanExecute(VM vm) { - return vm != null && (CrossPoolMoveVMCommand.CanExecute(vm, null) || vm.CanBeMoved()); + return vm != null && (CrossPoolMoveVMCommand.CanExecute(vm, null, false) || vm.CanBeMoved()); } public override string MenuText diff --git a/XenAdmin/Wizards/CrossPoolMigrateWizard/CrossPoolMigrateDestinationPage.cs b/XenAdmin/Wizards/CrossPoolMigrateWizard/CrossPoolMigrateDestinationPage.cs index eeeddb141..91392e211 100755 --- a/XenAdmin/Wizards/CrossPoolMigrateWizard/CrossPoolMigrateDestinationPage.cs +++ b/XenAdmin/Wizards/CrossPoolMigrateWizard/CrossPoolMigrateDestinationPage.cs @@ -43,6 +43,8 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard { private List selectedVMs; private WizardMode wizardMode; + private bool force = false; + // A 2-level cache to store the result of CrossPoolMigrateCanMigrateFilter. // Cache structure is like: >. private IDictionary> migrateFilterCache = @@ -50,14 +52,15 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard public CrossPoolMigrateDestinationPage() - : this(null, WizardMode.Migrate, null) + : this(null, WizardMode.Migrate, null, false) { } - public CrossPoolMigrateDestinationPage(List selectedVMs, WizardMode wizardMode, List ignoredConnections) + public CrossPoolMigrateDestinationPage(List selectedVMs, WizardMode wizardMode, List ignoredConnections, bool force) { this.selectedVMs = selectedVMs; this.wizardMode = wizardMode; + this.force = force; this.ignoredConnections = ignoredConnections ?? new List(); InitializeText(); @@ -134,7 +137,7 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard var filters = new List { new ResidentHostIsSameAsSelectionFilter(xenItem, selectedVMs), - new CrossPoolMigrateCanMigrateFilter(xenItem, selectedVMs, wizardMode, migrateFilterCache), + new CrossPoolMigrateCanMigrateFilter(xenItem, selectedVMs, wizardMode, force, migrateFilterCache), new WlbEnabledFilter(xenItem, selectedVMs) }; return new DelayLoadingOptionComboBoxItem(xenItem, filters); @@ -151,7 +154,7 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard vmList.Add(selectedVMs.Find(vm => vm.opaque_ref == opaqueRef)); filters.Add(new ResidentHostIsSameAsSelectionFilter(selectedItem.Item, vmList)); - filters.Add(new CrossPoolMigrateCanMigrateFilter(selectedItem.Item, vmList, wizardMode, migrateFilterCache)); + filters.Add(new CrossPoolMigrateCanMigrateFilter(selectedItem.Item, vmList, wizardMode, force, migrateFilterCache)); filters.Add(new WlbEnabledFilter(selectedItem.Item, vmList)); } diff --git a/XenAdmin/Wizards/CrossPoolMigrateWizard/CrossPoolMigrateWizard.cs b/XenAdmin/Wizards/CrossPoolMigrateWizard/CrossPoolMigrateWizard.cs index d3580c628..0ff7e0349 100644 --- a/XenAdmin/Wizards/CrossPoolMigrateWizard/CrossPoolMigrateWizard.cs +++ b/XenAdmin/Wizards/CrossPoolMigrateWizard/CrossPoolMigrateWizard.cs @@ -69,15 +69,17 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard private WizardMode wizardMode; + private bool _force; private bool _resumeAfterMigrate; // Note that resumeAfter is currently only implemented for Migrate mode, used for resume on server functionality - public CrossPoolMigrateWizard(IXenConnection con, SelectedItemCollection selection, Host targetHostPreSelection, WizardMode mode, bool resumeAfterMigrate = false) + public CrossPoolMigrateWizard(IXenConnection con, SelectedItemCollection selection, Host targetHostPreSelection, WizardMode mode, bool force, bool resumeAfterMigrate = false) : base(con) { InitializeComponent(); hostPreSelection = targetHostPreSelection; wizardMode = mode; + _force = force; InitialiseWizard(selection); _resumeAfterMigrate = resumeAfterMigrate; } @@ -184,7 +186,7 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard UpdateWindowTitle(); m_pageDestination = new CrossPoolMigrateDestinationPage(vmsFromSelection, - wizardMode, GetSourceConnectionsForSelection(selection)) + wizardMode, GetSourceConnectionsForSelection(selection), _force) { VmMappings = m_vmMappings, Connection = selection.GetConnectionOfFirstItem() @@ -271,14 +273,14 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard } } if (moveStorage) - new VMMoveAction(vm, pair.Value.Storage, target).RunAsync(); + new VMMoveAction(vm, pair.Value.Storage, target).RunAsync(); } else { var isCopy = wizardMode == WizardMode.Copy; AsyncAction migrateAction; if (isCopy || IsStorageMotion(pair)) - migrateAction = new VMCrossPoolMigrateAction(vm, target, SelectedTransferNetwork, pair.Value, isCopy); + migrateAction = new VMCrossPoolMigrateAction(vm, target, SelectedTransferNetwork, pair.Value, isCopy, _force); else migrateAction = new VMMigrateAction(vm, target); @@ -340,6 +342,11 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard : wizardMode == WizardMode.Move ? Messages.MOVE_VM_WIZARD_TITLE : IsCopyTemplate() ? Messages.COPY_TEMPLATE_WIZARD_TITLE : Messages.COPY_VM_WIZARD_TITLE; + + if (_force) + { + Text = "Force " + Text; + } } protected override void UpdateWizardContent(XenTabPage page) diff --git a/XenAdmin/Wizards/CrossPoolMigrateWizard/Filters/CrossPoolMigrateCanMigrateFilter.cs b/XenAdmin/Wizards/CrossPoolMigrateWizard/Filters/CrossPoolMigrateCanMigrateFilter.cs index 5992ea637..d87cb3e1e 100644 --- a/XenAdmin/Wizards/CrossPoolMigrateWizard/Filters/CrossPoolMigrateCanMigrateFilter.cs +++ b/XenAdmin/Wizards/CrossPoolMigrateWizard/Filters/CrossPoolMigrateCanMigrateFilter.cs @@ -48,9 +48,10 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard.Filters private readonly List preSelectedVMs; private IDictionary> cache; private bool canceled = false; + private readonly bool force = false; private static readonly Object cacheLock = new Object(); - public CrossPoolMigrateCanMigrateFilter(IXenObject itemAddedToComboBox, List preSelectedVMs, WizardMode wizardMode, IDictionary> cache = null) + public CrossPoolMigrateCanMigrateFilter(IXenObject itemAddedToComboBox, List preSelectedVMs, WizardMode wizardMode, bool force, IDictionary> cache = null) : base(itemAddedToComboBox) { _wizardMode = wizardMode; @@ -59,6 +60,8 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard.Filters else this.cache = cache; + this.force = force; + if (preSelectedVMs == null) throw new ArgumentNullException("Pre-selected VMs are null"); this.preSelectedVMs = preSelectedVMs; @@ -147,14 +150,16 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard.Filters Session session = host.Connection.DuplicateSession(); Dictionary receiveMapping = Host.migrate_receive(session, host.opaque_ref, network.opaque_ref, new Dictionary()); + Dictionary options = new Dictionary(); + if (force) + options.Add("force", "true"); VM.assert_can_migrate(vm.Connection.Session, vm.opaque_ref, receiveMapping, true, GetVdiMap(vm, targetSrs), vm.Connection == host.Connection ? new Dictionary, XenRef>() : GetVifMap(vm, targetNetwork), - //TODO: Implement force=true as general option - new Dictionary(){{ "force", "true" }}); + options); lock (cacheLock) { vmCache.Add(host.opaque_ref, string.Empty); diff --git a/XenModel/Actions/VM/VMCrossPoolMigrateAction.cs b/XenModel/Actions/VM/VMCrossPoolMigrateAction.cs index 1d3ba9b2c..fc53828ac 100644 --- a/XenModel/Actions/VM/VMCrossPoolMigrateAction.cs +++ b/XenModel/Actions/VM/VMCrossPoolMigrateAction.cs @@ -52,7 +52,7 @@ namespace XenAdmin.Actions.VMActions /// the storage and networking mappings /// weather this should be a cross-pool copy (true) or migrate (false) operation /// weather this should be forced - public VMCrossPoolMigrateAction(VM vm, Host destinationHost, XenAPI.Network transferNetwork, VmMapping mapping, bool copy, bool force=true) + public VMCrossPoolMigrateAction(VM vm, Host destinationHost, XenAPI.Network transferNetwork, VmMapping mapping, bool copy, bool force) : base(vm.Connection, GetTitle(vm, destinationHost, copy)) { Session = vm.Connection.Session;