2023-01-24 15:29:31 +01:00
|
|
|
|
/* Copyright (c) Cloud Software Group, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms,
|
|
|
|
|
* with or without modification, are permitted provided
|
|
|
|
|
* that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* * Redistributions of source code must retain the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer.
|
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
|
* materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using XenAdmin.Dialogs;
|
|
|
|
|
using XenAdmin.Wizards.CrossPoolMigrateWizard;
|
|
|
|
|
using XenAdmin.Wizards.CrossPoolMigrateWizard.Filters;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Commands
|
|
|
|
|
{
|
|
|
|
|
internal class CrossPoolMigrateCommand : VMOperationCommand
|
|
|
|
|
{
|
2022-04-30 01:12:21 +02:00
|
|
|
|
private readonly Dictionary<string, Dictionary<string, string>> cantRunReasons = new Dictionary<string, Dictionary<string, string>>();
|
|
|
|
|
|
|
|
|
|
private readonly bool _resumeAfter;
|
|
|
|
|
protected Host preSelectedHost;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
public CrossPoolMigrateCommand(IMainWindow mainWindow, IEnumerable<SelectedItem> selection)
|
|
|
|
|
: base(mainWindow, selection)
|
|
|
|
|
{ }
|
|
|
|
|
|
2024-01-01 17:33:57 +01:00
|
|
|
|
public CrossPoolMigrateCommand(IMainWindow mainWindow, IEnumerable<SelectedItem> selection, Host preSelectedHost, bool resumeAfter = false)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
: base(mainWindow, selection)
|
|
|
|
|
{
|
|
|
|
|
this.preSelectedHost = preSelectedHost;
|
2016-11-03 16:35:25 +01:00
|
|
|
|
_resumeAfter = resumeAfter;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string MenuText
|
|
|
|
|
{
|
2017-06-13 14:12:01 +02:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (preSelectedHost == null)
|
|
|
|
|
return Messages.HOST_MENU_CPM_TEXT;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
var cantRunReason = CantRunReason;
|
|
|
|
|
return string.IsNullOrEmpty(cantRunReason)
|
2017-09-03 04:33:29 +02:00
|
|
|
|
? preSelectedHost.Name().EscapeAmpersands()
|
2021-08-31 12:31:16 +02:00
|
|
|
|
: string.Format(Messages.MAINWINDOW_CONTEXT_REASON, preSelectedHost.Name().EscapeAmpersands(), cantRunReason);
|
2017-06-13 14:12:01 +02:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 01:12:21 +02:00
|
|
|
|
public override string ContextMenuText => Messages.HOST_MENU_CPM_TEXT;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2022-04-30 01:12:21 +02:00
|
|
|
|
public override Image MenuImage => preSelectedHost == null
|
|
|
|
|
? Images.StaticImages._000_MigrateVM_h32bit_16
|
|
|
|
|
: Images.StaticImages._000_TreeConnected_h32bit_16;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
protected override void RunCore(SelectedItemCollection selection)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
var con = selection.GetConnectionOfFirstItem();
|
|
|
|
|
|
2024-01-01 17:33:57 +01:00
|
|
|
|
var wizard = new CrossPoolMigrateWizard(con, selection, preSelectedHost, WizardMode.Migrate, _resumeAfter);
|
|
|
|
|
MainWindowCommandInterface.ShowPerConnectionWizard(con, wizard);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override Host GetHost(VM vm)
|
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
return Helpers.GetCoordinator(vm.Connection);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
protected override bool CanRun(VM vm)
|
2015-03-24 18:14:03 +01:00
|
|
|
|
{
|
2022-04-30 01:12:21 +02:00
|
|
|
|
var canRun = CanRun(vm, preSelectedHost, out var failureReason, cantRunReasons);
|
|
|
|
|
CantRunReason = failureReason;
|
2021-08-31 12:31:16 +02:00
|
|
|
|
return canRun;
|
2015-03-24 18:14:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 01:12:21 +02:00
|
|
|
|
public static bool CanRun(VM vm, Host preselectedHost, out string failureReason, Dictionary<string, Dictionary<string, string>> cache = null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2022-04-30 01:12:21 +02:00
|
|
|
|
if (vm.allowed_operations == null || !vm.allowed_operations.Contains(vm_operations.migrate_send))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2022-04-30 01:12:21 +02:00
|
|
|
|
failureReason = Messages.MIGRATION_NOT_ALLOWED;
|
|
|
|
|
return false;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-18 11:54:44 +02:00
|
|
|
|
if (!vm.SRs().All(sr => sr != null && !sr.HBALunPerVDI()))
|
2017-06-13 14:12:01 +02:00
|
|
|
|
{
|
2022-04-30 01:12:21 +02:00
|
|
|
|
failureReason = Messages.MIGRATION_NOT_ALLOWED_USUPPORTED_SR;
|
|
|
|
|
return false;
|
2017-06-13 14:12:01 +02:00
|
|
|
|
}
|
2022-04-30 01:12:21 +02:00
|
|
|
|
|
2023-11-14 14:25:34 +01:00
|
|
|
|
if (preselectedHost != null)
|
|
|
|
|
{
|
2024-01-01 17:33:57 +01:00
|
|
|
|
var vms = new List<VM> { vm };
|
2022-04-30 01:12:21 +02:00
|
|
|
|
|
2023-11-14 14:25:34 +01:00
|
|
|
|
if (new ResidentHostIsSameAsSelectionFilter(preselectedHost, vms).FailureFound(out failureReason))
|
|
|
|
|
return false;
|
2022-04-30 01:12:21 +02:00
|
|
|
|
|
2023-11-14 14:25:34 +01:00
|
|
|
|
if (new CrossPoolMigrateFilter(preselectedHost, vms, WizardMode.Migrate, cache).FailureFound(out failureReason))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-04-30 01:12:21 +02:00
|
|
|
|
|
2023-06-06 19:13:39 +02:00
|
|
|
|
failureReason = string.Empty;
|
2022-04-30 01:12:21 +02:00
|
|
|
|
return true;
|
2017-06-13 14:12:01 +02:00
|
|
|
|
}
|
2022-04-30 01:12:21 +02:00
|
|
|
|
|
|
|
|
|
public string CantRunReason { get; private set; }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|