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.Linq;
|
2013-11-19 18:02:02 +01:00
|
|
|
|
using XenAdmin.Controls;
|
2017-05-11 17:42:41 +02:00
|
|
|
|
using XenAdmin.Mappings;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using XenAdmin.Wizards.GenericPages;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Wizards.CrossPoolMigrateWizard
|
|
|
|
|
{
|
|
|
|
|
class CrossPoolMigrateStoragePage : SelectVMStorageWithMultipleVirtualDisksPage
|
|
|
|
|
{
|
2016-02-24 11:44:37 +01:00
|
|
|
|
private readonly bool templatesOnly = false;
|
2016-02-26 19:21:51 +01:00
|
|
|
|
private readonly WizardMode wizardMode;
|
2016-02-24 11:44:37 +01:00
|
|
|
|
|
2016-03-01 19:07:53 +01:00
|
|
|
|
public CrossPoolMigrateStoragePage(WizardMode wizardMode)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
DisplayDiskCapacity = false;
|
2016-02-26 19:21:51 +01:00
|
|
|
|
this.wizardMode = wizardMode;
|
2016-02-24 11:44:37 +01:00
|
|
|
|
|
|
|
|
|
InitializeText();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool ImplementsIsDirty()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-22 12:28:24 +01:00
|
|
|
|
protected override bool SrsAreSuitable(SR sourceSr, SR targetSr)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-11-22 12:28:24 +01:00
|
|
|
|
if (sourceSr == null || targetSr == null || sourceSr.HBALunPerVDI() || targetSr.HBALunPerVDI())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// intra-pool move of halted VMs does not require the SRs to support migration because we use VMMoveAction (vdi copy & destroy)
|
|
|
|
|
if (wizardMode == WizardMode.Move && sourceSr.Connection == targetSr.Connection)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return sourceSr.SupportsStorageMigration() && targetSr.SupportsStorageMigration();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-16 17:39:52 +01:00
|
|
|
|
protected override bool IsExtraSpaceNeeded(SR sourceSr, SR targetSr)
|
2018-02-05 11:07:24 +01:00
|
|
|
|
{
|
2018-11-16 17:39:52 +01:00
|
|
|
|
// No extra space is needed for Migrate or Move operation on same SR.
|
|
|
|
|
if (sourceSr != null && targetSr != null && targetSr.opaque_ref.Equals(sourceSr.opaque_ref) &&
|
|
|
|
|
(wizardMode == WizardMode.Migrate || wizardMode == WizardMode.Move))
|
2018-02-05 11:07:24 +01:00
|
|
|
|
return false;
|
2018-11-16 17:39:52 +01:00
|
|
|
|
return true;
|
2018-02-05 11:07:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-07-22 16:12:02 +02:00
|
|
|
|
public override string PageTitle => Messages.CPM_WIZARD_SELECT_STORAGE_PAGE_TITLE;
|
|
|
|
|
public override string Text => Messages.CPM_WIZARD_SELECT_STORAGE_PAGE_TEXT;
|
|
|
|
|
public override string HelpID => wizardMode == WizardMode.Copy ? "StorageCopyMode" : "Storage";
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-07-22 16:12:02 +02:00
|
|
|
|
protected override string IntroductionText => Messages.CPM_WIZARD_STORAGE_INSTRUCTIONS;
|
|
|
|
|
protected override string AllOnSameSRRadioButtonText => Messages.CPM_WIZARD_ALL_ON_SAME_SR_RADIO;
|
|
|
|
|
protected override string OnSpecificSRRadioButtonText => Messages.CPM_WIZARD_SPECIFIC_SR_RADIO;
|
|
|
|
|
protected override string VmDiskColumnHeaderText => templatesOnly
|
|
|
|
|
? Messages.CPS_WIZARD_STORAGE_PAGE_DISK_COLUMN_HEADER_FOR_TEMPLATE
|
|
|
|
|
: Messages.CPS_WIZARD_STORAGE_PAGE_DISK_COLUMN_HEADER_FOR_VM;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override StorageResourceContainer ResourceData(string sysId)
|
|
|
|
|
{
|
|
|
|
|
VM vm = Connection.Resolve(new XenRef<VM>(sysId));
|
2013-11-19 18:02:02 +01:00
|
|
|
|
|
|
|
|
|
if (vm == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
List<VDI> vdis = Connection.ResolveAll(vm.VBDs).Select(v => vm.Connection.Resolve(v.VDI)).ToList();
|
|
|
|
|
vdis.RemoveAll(vdi => vdi == null || Connection.Resolve(vdi.SR).GetSRType(true) == SR.SRTypes.iso);
|
|
|
|
|
return new CrossPoolMigrationStorageResourceContainer(vdis);
|
|
|
|
|
}
|
2013-11-19 18:02:02 +01:00
|
|
|
|
|
2018-03-09 00:55:50 +01:00
|
|
|
|
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
|
2013-11-19 18:02:02 +01:00
|
|
|
|
{
|
|
|
|
|
if (!CrossPoolMigrateWizard.AllVMsAvailable(VmMappings, Connection))
|
|
|
|
|
{
|
|
|
|
|
cancel = true;
|
|
|
|
|
SetButtonNextEnabled(false);
|
|
|
|
|
SetButtonPreviousEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-24 11:44:37 +01:00
|
|
|
|
|
2017-05-11 17:42:41 +02:00
|
|
|
|
/// <summary>
|
2020-07-22 16:12:02 +02:00
|
|
|
|
/// Add storage mappings for snapshots and CD-ROMs
|
2017-05-11 17:42:41 +02:00
|
|
|
|
/// </summary>
|
2020-07-22 16:12:02 +02:00
|
|
|
|
protected override void AddAdditionalMappings(Dictionary<string, VmMapping> vmMappings)
|
2017-05-11 17:42:41 +02:00
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-22 16:12:02 +02:00
|
|
|
|
|
|
|
|
|
if (suitableSr == null || suitableSr.Connection != vm.Connection)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
//CA-339584: for intra-pool migrations ensure any CDs (except guest tools)
|
|
|
|
|
//will remain in their drives
|
|
|
|
|
|
|
|
|
|
foreach (var vbdRef in vm.VBDs)
|
|
|
|
|
{
|
|
|
|
|
var vbd = vm.Connection.Resolve(vbdRef);
|
|
|
|
|
if (vbd == null || !vbd.IsCDROM())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
var vdi = vm.Connection.Resolve(vbd.VDI);
|
|
|
|
|
if (vdi == null || vdi.IsToolsIso())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
var sr = vm.Connection.Resolve(vdi.SR);
|
|
|
|
|
vmMapping.Storage[vdi.opaque_ref] = sr;
|
|
|
|
|
}
|
2017-05-11 17:42:41 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|