CA-244663: In the Migrate VM wizard, add storage mappings for the VDIs belonging to the VM's snapshots

Signed-off-by: Mihaela Stoica <mihaela.stoica@citrix.com>
This commit is contained in:
Mihaela Stoica 2017-05-11 16:42:41 +01:00
parent 5aaaf48139
commit d2f3c0c116
3 changed files with 45 additions and 3 deletions

View File

@ -33,6 +33,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using XenAdmin.Controls;
using XenAdmin.Mappings;
using XenAdmin.Wizards.GenericPages;
using XenAPI;
@ -111,5 +112,38 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard
return templatesOnly ? Messages.CPS_WIZARD_STORAGE_PAGE_DISK_COLUMN_HEADER_FOR_TEMPLATE : Messages.CPS_WIZARD_STORAGE_PAGE_DISK_COLUMN_HEADER_FOR_VM;
}
}
/// <summary>
/// Add storage mappings for snapshots
/// </summary>
/// <param name="vmMappings"></param>
protected override void AddAditionalMappings(Dictionary<string, VmMapping> vmMappings)
{
foreach (var kvp in vmMappings)
{
var vm = Connection.Resolve(new XenRef<VM>(kvp.Key));
if (vm == null)
continue;
var vmMapping = kvp.Value;
var suitableSr = vmMapping.Storage.Values.FirstOrDefault(); //an SR already selected for VM's disks
foreach (var snapshot in Connection.ResolveAll(vm.snapshots))
{
foreach (IStorageResource resourceData in ResourceData(snapshot.opaque_ref))
{
var snapshotVdi = Connection.Resolve(new XenRef<VDI>(resourceData.Tag.ToString()));
if (snapshotVdi == null)
continue;
// try to use the mapping of the original vdi; if this doesn't exist, then use another suitable SR
if (snapshotVdi.snapshot_of != null && vmMapping.Storage.ContainsKey(snapshotVdi.snapshot_of.opaque_ref))
vmMapping.Storage[snapshotVdi.opaque_ref] = vmMapping.Storage[snapshotVdi.snapshot_of.opaque_ref];
else if (suitableSr != null)
vmMapping.Storage[snapshotVdi.opaque_ref] = suitableSr;
}
}
}
}
}
}

View File

@ -146,6 +146,9 @@ namespace XenAdmin.Wizards.GenericPages
}
}
protected virtual void AddAditionalMappings(Dictionary<string, VmMapping> vmMappings)
{}
#region Base class (XenTabPage) overrides
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
@ -342,6 +345,9 @@ namespace XenAdmin.Wizards.GenericPages
}
}
}
AddAditionalMappings(m_vmMappings);
return m_vmMappings;
}
set { m_vmMappings = value; }

View File

@ -233,17 +233,19 @@ namespace XenAdmin.Wizards.GenericPages
private void AddStorageMappings(ref List<SummaryDetails> decoratedSummary)
{
bool firstItem = true;
foreach (var pair in mapping.Storage)
{
VDI vdi = connection.Resolve(new XenRef<VDI>(pair.Key));
if (vdi == null)
if (vdi == null || vdi.is_a_snapshot) // don't display the storage mappings for the shapshots
continue;
string valueToAdd = vdi.Name + separatorText + pair.Value.Name;
if (pair.Key == mapping.Storage.First().Key)
if (firstItem)
{
decoratedSummary.Add(new SummaryDetails(Messages.CPM_SUMMARY_KEY_STORAGE, valueToAdd));
firstItem = false;
}
else
{