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;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using XenAdmin.Dialogs;
|
|
|
|
|
using XenAdmin.Network;
|
|
|
|
|
using XenAdmin.Properties;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
var cantExecuteReason = CantExecuteReason;
|
|
|
|
|
return string.IsNullOrEmpty(cantExecuteReason)
|
|
|
|
|
? preSelectedHost.Name.EscapeAmpersands()
|
2017-06-13 17:47:43 +02:00
|
|
|
|
: string.Format(Messages.MAINWINDOW_CONTEXT_REASON, preSelectedHost.Name.EscapeAmpersands(), cantExecuteReason);
|
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
|
|
|
|
|
|
|
|
|
protected override void ExecuteCore(SelectedItemCollection selection)
|
|
|
|
|
{
|
|
|
|
|
var con = selection.GetConnectionOfFirstItem();
|
|
|
|
|
|
|
|
|
|
if (Helpers.FeatureForbidden(con, Host.RestrictCrossPoolMigrate))
|
|
|
|
|
{
|
|
|
|
|
ShowUpsellDialog(Parent);
|
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
return Helpers.GetMaster(vm.Connection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ShowUpsellDialog(IWin32Window parent)
|
|
|
|
|
{
|
2016-06-20 14:26:52 +02:00
|
|
|
|
using (var dlg = new UpsellDialog(HiddenFeatures.LinkLabelHidden ? Messages.UPSELL_BLURB_CPM : Messages.UPSELL_BLURB_CPM + Messages.UPSELL_BLURB_CPM_MORE,
|
|
|
|
|
InvisibleMessages.UPSELL_LEARNMOREURL_CPM))
|
|
|
|
|
dlg.ShowDialog(parent);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-13 14:12:01 +02:00
|
|
|
|
private readonly Dictionary<VM, string> cantExecuteReasons = new Dictionary<VM, string>();
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
protected override bool CanExecute(VM vm)
|
2015-03-24 18:14:03 +01:00
|
|
|
|
{
|
2017-06-13 14:12:01 +02:00
|
|
|
|
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;
|
2015-03-24 18:14:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-13 14:12:01 +02:00
|
|
|
|
public static bool CanExecute(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) &&
|
2013-06-24 13:41:48 +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
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|