2017-01-16 20:59:50 +01:00
|
|
|
|
/* Copyright (c) Citrix Systems, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
{
|
2016-11-03 16:35:25 +01:00
|
|
|
|
private bool _resumeAfter;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
public CrossPoolMigrateCommand(IMainWindow mainWindow, IEnumerable<SelectedItem> selection)
|
|
|
|
|
: base(mainWindow, selection)
|
|
|
|
|
{ }
|
|
|
|
|
|
2015-03-17 17:35:12 +01:00
|
|
|
|
protected Host preSelectedHost = null;
|
2016-11-03 16:35:25 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ContextMenuText { get { return Messages.HOST_MENU_CPM_TEXT; } }
|
|
|
|
|
|
2016-09-30 12:33:18 +02:00
|
|
|
|
public override Image MenuImage
|
|
|
|
|
{
|
2017-01-11 14:54:56 +01:00
|
|
|
|
get { return preSelectedHost == null ? Images.StaticImages._000_MigrateVM_h32bit_16 : Images.StaticImages._000_TreeConnected_h32bit_16; }
|
2016-09-30 12:33:18 +02:00
|
|
|
|
}
|
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();
|
|
|
|
|
|
|
|
|
|
if (Helpers.FeatureForbidden(con, Host.RestrictCrossPoolMigrate))
|
|
|
|
|
{
|
2021-02-28 00:07:03 +01:00
|
|
|
|
UpsellDialog.ShowUpsellDialog(Messages.UPSELL_BLURB_CPM, Parent);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-11-03 16:35:25 +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
|
|
|
|
private readonly Dictionary<VM, string> cantRunReasons = new Dictionary<VM, string>();
|
2017-06-13 14:12:01 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
protected override bool CanRun(VM vm)
|
2015-03-24 18:14:03 +01:00
|
|
|
|
{
|
2017-06-13 14:12:01 +02:00
|
|
|
|
if (preSelectedHost == null)
|
2021-08-31 12:31:16 +02:00
|
|
|
|
return CanRun(vm, preSelectedHost);
|
2017-06-13 14:12:01 +02:00
|
|
|
|
|
|
|
|
|
var filter = new CrossPoolMigrateCanMigrateFilter(preSelectedHost, new List<VM> {vm}, WizardMode.Migrate);
|
2021-08-31 12:31:16 +02:00
|
|
|
|
var canRun = CanRun(vm, preSelectedHost, filter);
|
2017-06-13 14:12:01 +02:00
|
|
|
|
if (string.IsNullOrEmpty(filter.Reason))
|
2021-08-31 12:31:16 +02:00
|
|
|
|
cantRunReasons.Remove(vm);
|
2017-06-13 14:12:01 +02:00
|
|
|
|
else
|
2021-08-31 12:31:16 +02:00
|
|
|
|
cantRunReasons[vm] = filter.Reason;
|
|
|
|
|
return canRun;
|
2015-03-24 18:14:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
public static bool CanRun(VM vm, Host preselectedHost, CrossPoolMigrateCanMigrateFilter filter = null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
bool failureFound = false;
|
|
|
|
|
|
2015-03-24 18:14:03 +01:00
|
|
|
|
if (preselectedHost != null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-06-13 14:12:01 +02:00
|
|
|
|
failureFound = filter == null
|
|
|
|
|
? new CrossPoolMigrateCanMigrateFilter(preselectedHost, new List<VM> {vm}, WizardMode.Migrate).FailureFound
|
|
|
|
|
: filter.FailureFound;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return !failureFound &&
|
|
|
|
|
vm.allowed_operations != null &&
|
|
|
|
|
vm.allowed_operations.Contains(vm_operations.migrate_send) &&
|
2015-12-16 13:58:24 +01:00
|
|
|
|
!Helpers.CrossPoolMigrationRestrictedWithWlb(vm.Connection) &&
|
2017-09-03 04:33:29 +02:00
|
|
|
|
vm.SRs().ToList().All(sr=> sr != null && !sr.HBALunPerVDI()) &&
|
2015-03-24 18:14:03 +01:00
|
|
|
|
(preselectedHost == null || vm.Connection.Resolve(vm.resident_on) != preselectedHost); //Not the same as the pre-selected host
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2017-06-13 14:12:01 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
public string CantRunReason
|
2017-06-13 14:12:01 +02:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (cantRunReasons.Count == GetSelection().Count) // none can run
|
2017-06-13 14:12:01 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
var uniqueReasons = cantRunReasons.Values.Distinct().ToList();
|
2017-06-13 14:12:01 +02:00
|
|
|
|
|
|
|
|
|
if (uniqueReasons.Count == 1)
|
|
|
|
|
return uniqueReasons[0];
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|