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;
|
2018-05-17 16:33:30 +02:00
|
|
|
|
using XenAdmin.Core;
|
2015-05-27 13:17:35 +02:00
|
|
|
|
using XenAdmin.Wizards.CrossPoolMigrateWizard;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using XenAPI;
|
|
|
|
|
using XenAdmin.Dialogs.VMDialogs;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Commands
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2015-05-27 13:17:35 +02:00
|
|
|
|
/// Launches the Move-VM dialog for the selected VM.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// </summary>
|
|
|
|
|
internal class MoveVMCommand : Command
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of this Command. The parameter-less constructor is required in the derived
|
|
|
|
|
/// class if it is to be attached to a ToolStrip menu item or button. It should not be used in any other scenario.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public MoveVMCommand()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MoveVMCommand(IMainWindow mainWindow, IEnumerable<SelectedItem> selection)
|
|
|
|
|
: base(mainWindow, selection)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
protected override void RunCore(SelectedItemCollection selection)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-05-17 16:33:30 +02:00
|
|
|
|
var cmd = new CrossPoolMoveVMCommand(MainWindowCommandInterface, selection);
|
|
|
|
|
var con = selection.GetConnectionOfFirstItem();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (cmd.CanRun() && !Helpers.FeatureForbidden(con, Host.RestrictCrossPoolMigrate))
|
2017-06-16 15:29:46 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
cmd.Run();
|
2017-06-16 15:29:46 +02:00
|
|
|
|
}
|
2015-03-17 17:35:12 +01:00
|
|
|
|
else
|
2017-06-16 15:29:46 +02:00
|
|
|
|
{
|
|
|
|
|
VM vm = (VM) selection[0].XenObject;
|
2020-02-26 14:27:52 +01:00
|
|
|
|
new MoveVMDialog(vm).ShowPerXenObject(vm, Program.MainWindow);
|
2017-06-16 15:29:46 +02:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
protected override bool CanRunCore(SelectedItemCollection selection)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-09-12 17:49:02 +02:00
|
|
|
|
return selection.AllItemsAre<VM>(CBTDisabled) &&
|
2021-08-31 12:31:16 +02:00
|
|
|
|
(new CrossPoolMoveVMCommand(MainWindowCommandInterface, selection).CanRun() ||
|
|
|
|
|
selection.ContainsOneItemOfType<VM>(CanRun));
|
2017-09-12 17:49:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool CBTDisabled(VM vm)
|
|
|
|
|
{
|
|
|
|
|
if (vm == null)
|
|
|
|
|
return false;
|
|
|
|
|
foreach (var vbd in vm.Connection.ResolveAll(vm.VBDs))
|
|
|
|
|
{
|
|
|
|
|
var vdi = vm.Connection.Resolve(vbd.VDI);
|
|
|
|
|
if (vdi != null && vdi.cbt_enabled)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
private static bool CanRun(VM vm)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
return vm != null && (CrossPoolMoveVMCommand.CanRun(vm, null) || vm.CanBeMoved());
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string MenuText
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2015-05-27 13:17:35 +02:00
|
|
|
|
return CrossPoolMoveVMCommand.GetWizardMode(GetSelection()) == WizardMode.Migrate
|
|
|
|
|
? Messages.MAINWINDOW_MIGRATEVM
|
|
|
|
|
: Messages.MAINWINDOW_MOVEVM;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|