mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2025-01-20 07:19:18 +01:00
CA-186244: Cross-pool copy of a stopped VM allows selection of the current pool
Now CrossPoolMigrateCanMigrateFilter can accept a parameter to decide whether to allow same target pool or not -- if allowSameTargetPool is false, it won't. Signed-off-by: Gabor Apati-Nagy <gabor.apati-nagy@citrix.com>
This commit is contained in:
parent
bf1bbd8475
commit
aecb18ab15
@ -44,6 +44,7 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard
|
||||
private readonly Host preSelectedHost;
|
||||
private readonly List<VM> preSelectedVMs;
|
||||
private Queue<ReasoningFilter> filters;
|
||||
private bool allowSameTargetPool;
|
||||
|
||||
/// <summary>
|
||||
/// Instantiate a delay loading combo box item for cross pool migrate
|
||||
@ -51,11 +52,12 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard
|
||||
/// <param name="itemAddedToComboBox">Item being added to the list</param>
|
||||
/// <param name="preSelectedHost">Host that was preselected by user prior to loading this item</param>
|
||||
/// <param name="preSelectedVMs">VMs selected prior to loading this item</param>
|
||||
public CrossPoolMigrateDelayLoadingComboBoxItem(IXenObject itemAddedToComboBox, Host preSelectedHost, List<VM> preSelectedVMs)
|
||||
public CrossPoolMigrateDelayLoadingComboBoxItem(IXenObject itemAddedToComboBox, Host preSelectedHost, List<VM> preSelectedVMs, bool allowSameTargetPool)
|
||||
: base(itemAddedToComboBox)
|
||||
{
|
||||
this.preSelectedHost = preSelectedHost;
|
||||
this.preSelectedVMs = preSelectedVMs;
|
||||
this.allowSameTargetPool = allowSameTargetPool;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -67,7 +69,7 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard
|
||||
filters = new Queue<ReasoningFilter>();
|
||||
filters.Enqueue(new CrossPoolMigrateVersionFilter(Item));
|
||||
filters.Enqueue(new ResidentHostIsSameAsSelectionFilter(Item, preSelectedVMs));
|
||||
filters.Enqueue(new CrossPoolMigrateCanMigrateFilter(Item, preSelectedVMs));
|
||||
filters.Enqueue(new CrossPoolMigrateCanMigrateFilter(Item, preSelectedVMs, allowSameTargetPool));
|
||||
filters.Enqueue(new WlbEnabledFilter(Item, preSelectedVMs));
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard
|
||||
|
||||
public override DelayLoadingOptionComboBoxItem CreateDelayLoadingOptionComboBoxItem(IXenObject xenItem)
|
||||
{
|
||||
return new CrossPoolMigrateDelayLoadingComboBoxItem(xenItem, preSelectedHost, selectedVMs);
|
||||
return new CrossPoolMigrateDelayLoadingComboBoxItem(xenItem, preSelectedHost, selectedVMs, wizardMode != WizardMode.Copy);
|
||||
}
|
||||
|
||||
protected override List<ReasoningFilter> CreateHomeServerFilterList(IEnableableXenObjectComboBoxItem selectedItem)
|
||||
|
@ -44,6 +44,7 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard.Filters
|
||||
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
private readonly List<VM> preSelectedVMs;
|
||||
private readonly List<FailureReason> failureReasons = new List<FailureReason>();
|
||||
private readonly bool allowSameTargetPool;
|
||||
|
||||
/// <summary>
|
||||
/// Helper class used for determining if the hosts in the failure
|
||||
@ -62,10 +63,11 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard.Filters
|
||||
}
|
||||
}
|
||||
|
||||
public CrossPoolMigrateCanMigrateFilter(IXenObject itemAddedToComboBox, List<VM> preSelectedVMs)
|
||||
public CrossPoolMigrateCanMigrateFilter(IXenObject itemAddedToComboBox, List<VM> preSelectedVMs, bool allowSameTargetPool = true)
|
||||
: base(itemAddedToComboBox)
|
||||
{
|
||||
this.preSelectedVMs = preSelectedVMs;
|
||||
this.allowSameTargetPool = allowSameTargetPool;
|
||||
}
|
||||
|
||||
private struct FailureReason
|
||||
@ -94,10 +96,15 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard.Filters
|
||||
{
|
||||
try
|
||||
{
|
||||
//Skip the resident host as there's a filter for it and
|
||||
//if not then you could exclude intrapool migration
|
||||
if(vm.resident_on == host.opaque_ref)
|
||||
continue;
|
||||
if (!allowSameTargetPool && IsVmInTargetsPool(vm, host))
|
||||
throw new Failure(Messages.ACTION_VM_CROSS_POOL_COPY_CANNOT_COPY_TO_SAME_POOL, new Exception());
|
||||
else
|
||||
{
|
||||
//Skip the resident host as there's a filter for it and
|
||||
//if not then you could exclude intrapool migration
|
||||
if (vm.resident_on == host.opaque_ref)
|
||||
continue;
|
||||
}
|
||||
|
||||
PIF managementPif = host.Connection.Cache.PIFs.First(p => p.management);
|
||||
XenAPI.Network network = host.Connection.Cache.Resolve(managementPif.network);
|
||||
@ -123,6 +130,20 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard.Filters
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsVmInTargetsPool(VM vm, Host target)
|
||||
{
|
||||
if (vm == null || target == null)
|
||||
return false;
|
||||
|
||||
var vmPool = Helpers.GetPoolOfOne(vm.Connection);
|
||||
var targetPool = Helpers.GetPoolOfOne(target.Connection);
|
||||
|
||||
if (targetPool == vmPool)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If we have a pool, then we need to fail only when there are failures for
|
||||
/// each of the hosts. Otherwise any failure counts.
|
||||
|
9
XenModel/Messages.Designer.cs
generated
9
XenModel/Messages.Designer.cs
generated
@ -2742,6 +2742,15 @@ namespace XenAdmin {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Cannot copy to resident host or pool.
|
||||
/// </summary>
|
||||
public static string ACTION_VM_CROSS_POOL_COPY_CANNOT_COPY_TO_SAME_POOL {
|
||||
get {
|
||||
return ResourceManager.GetString("ACTION_VM_CROSS_POOL_COPY_CANNOT_COPY_TO_SAME_POOL", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Copying VM '{0}' to '{1}'.
|
||||
/// </summary>
|
||||
|
@ -1023,6 +1023,9 @@
|
||||
<data name="ACTION_VM_CROSS_POOL_COPY_CANCELLED" xml:space="preserve">
|
||||
<value>Copying {0} canceled</value>
|
||||
</data>
|
||||
<data name="ACTION_VM_CROSS_POOL_COPY_CANNOT_COPY_TO_SAME_POOL" xml:space="preserve">
|
||||
<value>Cannot copy to resident host or pool</value>
|
||||
</data>
|
||||
<data name="ACTION_VM_CROSS_POOL_COPY_TITLE" xml:space="preserve">
|
||||
<value>Copying VM '{0}' to '{1}'</value>
|
||||
</data>
|
||||
|
Loading…
Reference in New Issue
Block a user