2023-01-24 15:29:31 +01:00
|
|
|
|
/* Copyright (c) Cloud Software Group, Inc.
|
2015-03-31 16:13:46 +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;
|
|
|
|
|
using System.Collections.Generic;
|
2020-05-21 16:25:56 +02:00
|
|
|
|
using System.Linq;
|
2015-03-31 16:13:46 +02:00
|
|
|
|
using XenAdmin.Controls;
|
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using XenAPI;
|
2018-10-09 12:03:36 +02:00
|
|
|
|
|
2015-03-31 16:13:46 +02:00
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Wizards.CrossPoolMigrateWizard
|
|
|
|
|
{
|
|
|
|
|
public partial class IntraPoolCopyPage : XenTabPage
|
|
|
|
|
{
|
2022-11-29 23:59:01 +01:00
|
|
|
|
private bool _buttonNextEnabled;
|
2015-03-31 16:13:46 +02:00
|
|
|
|
|
|
|
|
|
public IntraPoolCopyPage(List<VM> selectedVMs)
|
|
|
|
|
{
|
2022-11-29 23:59:01 +01:00
|
|
|
|
TheVM = selectedVMs[0];
|
2015-03-31 16:13:46 +02:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-29 23:59:01 +01:00
|
|
|
|
public VM TheVM { get; }
|
2017-01-16 20:59:50 +01:00
|
|
|
|
|
2019-09-04 01:05:33 +02:00
|
|
|
|
public bool CloneVM => !tableLayoutPanelSrPicker.Enabled || CloneRadioButton.Checked;
|
2017-01-16 20:59:50 +01:00
|
|
|
|
|
2019-09-04 01:05:33 +02:00
|
|
|
|
public SR SelectedSR => srPicker1.SR;
|
2017-01-16 20:59:50 +01:00
|
|
|
|
|
2019-09-04 01:05:33 +02:00
|
|
|
|
public string NewVmName => NameTextBox.Text;
|
2017-01-16 20:59:50 +01:00
|
|
|
|
|
2019-09-04 01:05:33 +02:00
|
|
|
|
public string NewVMmDescription => DescriptionTextBox.Text;
|
2015-03-31 16:13:46 +02:00
|
|
|
|
|
|
|
|
|
#region Base class (XenTabPage) overrides
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the page's title (headline)
|
|
|
|
|
/// </summary>
|
2019-09-04 01:05:33 +02:00
|
|
|
|
public override string PageTitle => Messages.CPM_WIZARD_INTRA_POOL_COPY_TITLE;
|
2015-03-31 16:13:46 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the page's label in the (left hand side) wizard progress panel
|
|
|
|
|
/// </summary>
|
2019-09-04 01:05:33 +02:00
|
|
|
|
public override string Text => Messages.CPM_WIZARD_INTRA_POOL_COPY_TAB_TITLE;
|
2015-03-31 16:13:46 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the value by which the help files section for this page is identified
|
|
|
|
|
/// </summary>
|
2019-09-04 01:05:33 +02:00
|
|
|
|
public override string HelpID => "IntraPoolCopy";
|
2015-03-31 16:13:46 +02:00
|
|
|
|
|
|
|
|
|
protected override bool ImplementsIsDirty()
|
|
|
|
|
{
|
|
|
|
|
return false;
|
2018-03-09 01:31:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PageLoadedCore(PageLoadedDirection direction)
|
2015-03-31 16:13:46 +02:00
|
|
|
|
{
|
2019-09-04 01:05:33 +02:00
|
|
|
|
UpdateButtons();
|
2015-03-31 16:13:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void PopulatePage()
|
|
|
|
|
{
|
2018-10-09 12:03:36 +02:00
|
|
|
|
labelSrHint.Text = TheVM.is_a_template ? Messages.COPY_TEMPLATE_SELECT_SR : Messages.COPY_VM_SELECT_SR;
|
2015-03-31 16:13:46 +02:00
|
|
|
|
|
|
|
|
|
NameTextBox.Text = GetDefaultCopyName(TheVM);
|
|
|
|
|
|
|
|
|
|
bool allow_copy = !TheVM.is_a_template || TheVM.allowed_operations.Contains(vm_operations.copy);
|
2017-09-03 04:33:29 +02:00
|
|
|
|
bool anyDiskFastCloneable = TheVM.AnyDiskFastClonable();
|
|
|
|
|
bool hasAtLeastOneDisk = TheVM.HasAtLeastOneDisk();
|
|
|
|
|
|
|
|
|
|
CopyRadioButton.Enabled = allow_copy && hasAtLeastOneDisk;
|
|
|
|
|
FastClonePanel.Enabled = !allow_copy || anyDiskFastCloneable || !hasAtLeastOneDisk;
|
2020-03-30 00:49:06 +02:00
|
|
|
|
|
2015-03-31 16:13:46 +02:00
|
|
|
|
if (!FastClonePanel.Enabled)
|
|
|
|
|
CloneRadioButton.Checked = false;
|
2020-03-30 00:49:06 +02:00
|
|
|
|
|
|
|
|
|
if (!CloneRadioButton.Enabled)
|
|
|
|
|
CopyRadioButton.Checked = true;
|
|
|
|
|
|
2017-09-03 04:33:29 +02:00
|
|
|
|
toolTipContainer1.SetToolTip(Messages.FAST_CLONE_UNAVAILABLE);
|
2020-03-30 00:49:06 +02:00
|
|
|
|
|
2017-09-03 04:33:29 +02:00
|
|
|
|
if (TheVM.is_a_template && !(anyDiskFastCloneable || allow_copy))
|
2015-03-31 16:13:46 +02:00
|
|
|
|
{
|
|
|
|
|
CloneRadioButton.Text = Messages.COPY_VM_CLONE_TEMPLATE_SLOW;
|
|
|
|
|
FastCloneDescription.Text = Messages.COPY_VM_SLOW_CLONE_DESCRIPTION;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
FastCloneDescription.Text = !TheVM.is_a_template ? Messages.COPY_VM_FAST_CLONE_DESCRIPTION : Messages.COPY_TEMPLATE_FAST_CLONE_DESCRIPTION;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:33:29 +02:00
|
|
|
|
if (TheVM.DescriptionType() != VM.VmDescriptionType.None)
|
|
|
|
|
DescriptionTextBox.Text = TheVM.Description();
|
2015-03-31 16:13:46 +02:00
|
|
|
|
|
2018-10-09 12:03:36 +02:00
|
|
|
|
tableLayoutPanelSrPicker.Enabled = CopyRadioButton.Enabled && CopyRadioButton.Checked;
|
2015-03-31 18:40:05 +02:00
|
|
|
|
|
|
|
|
|
labelRubric.Text = TheVM.is_a_template
|
|
|
|
|
? Messages.COPY_TEMPLATE_INTRA_POOL_RUBRIC
|
|
|
|
|
: Messages.COPY_VM_INTRA_POOL_RUBRIC;
|
2020-03-30 00:49:06 +02:00
|
|
|
|
|
|
|
|
|
UpdateButtons();
|
2020-05-21 16:25:56 +02:00
|
|
|
|
|
|
|
|
|
var vdis = (from VBD vbd in TheVM.Connection.ResolveAll(TheVM.VBDs)
|
|
|
|
|
where vbd.type != vbd_type.CD
|
|
|
|
|
let vdi = TheVM.Connection.Resolve(vbd.VDI)
|
|
|
|
|
where vdi != null
|
|
|
|
|
select vdi).ToArray();
|
|
|
|
|
|
2022-11-29 23:59:01 +01:00
|
|
|
|
srPicker1.Populate(SrPicker.SRPickerType.Copy, TheVM.Connection, TheVM.Home(), null, vdis);
|
2015-03-31 16:13:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool EnableNext()
|
|
|
|
|
{
|
|
|
|
|
return _buttonNextEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-09 00:55:50 +01:00
|
|
|
|
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
|
2015-03-31 16:13:46 +02:00
|
|
|
|
{
|
2019-09-04 01:05:33 +02:00
|
|
|
|
if (direction != PageLoadedDirection.Forward)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var l = new List<VM> {TheVM};
|
2015-03-31 16:13:46 +02:00
|
|
|
|
if (!CrossPoolMigrateWizard.AllVMsAvailable(l))
|
|
|
|
|
cancel = true;
|
|
|
|
|
}
|
2022-11-29 23:59:01 +01:00
|
|
|
|
|
2015-03-31 16:13:46 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
2019-09-04 01:05:33 +02:00
|
|
|
|
private void UpdateButtons()
|
2015-03-31 16:13:46 +02:00
|
|
|
|
{
|
2019-09-04 01:05:33 +02:00
|
|
|
|
if (string.IsNullOrEmpty(NameTextBox.Text.Trim()))
|
|
|
|
|
_buttonNextEnabled = false;
|
|
|
|
|
else if (CopyRadioButton.Checked)
|
|
|
|
|
_buttonNextEnabled = srPicker1.SR != null;
|
|
|
|
|
else
|
|
|
|
|
_buttonNextEnabled = true;
|
|
|
|
|
|
2015-03-31 16:13:46 +02:00
|
|
|
|
OnPageUpdated();
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-29 23:59:01 +01:00
|
|
|
|
private void EnableRescanButton()
|
|
|
|
|
{
|
|
|
|
|
buttonRescan.Enabled = tableLayoutPanelSrPicker.Enabled && srPicker1.CanBeScanned;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-04 01:05:33 +02:00
|
|
|
|
private void srPicker1_SelectedIndexChanged(object sender, EventArgs e)
|
2015-03-31 16:13:46 +02:00
|
|
|
|
{
|
2019-09-04 01:05:33 +02:00
|
|
|
|
UpdateButtons();
|
2015-03-31 16:13:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-29 23:59:01 +01:00
|
|
|
|
private void srPicker1_CanBeScannedChanged()
|
|
|
|
|
{
|
|
|
|
|
EnableRescanButton();
|
|
|
|
|
UpdateButtons();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonRescan_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
srPicker1.ScanSRs();
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-31 16:13:46 +02:00
|
|
|
|
private void NameTextBox_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2019-09-04 01:05:33 +02:00
|
|
|
|
UpdateButtons();
|
2015-03-31 16:13:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetDefaultCopyName(VM vmToCopy)
|
|
|
|
|
{
|
|
|
|
|
List<string> takenNames = new List<string>();
|
|
|
|
|
foreach (VM vm in vmToCopy.Connection.Cache.VMs)
|
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
takenNames.Add(vm.Name());
|
2015-03-31 16:13:46 +02:00
|
|
|
|
}
|
2017-09-03 04:33:29 +02:00
|
|
|
|
return Helpers.MakeUniqueName(string.Format(Messages.ACTION_TEMPLATE_CLONE_NEW_NAME, vmToCopy.Name()), takenNames);
|
2015-03-31 16:13:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CloneRadioButton_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// Since the radiobuttons aren't in the same panel, we have to do manual mutual exclusion
|
|
|
|
|
CopyRadioButton.Checked = !CloneRadioButton.Checked;
|
2019-09-04 01:05:33 +02:00
|
|
|
|
UpdateButtons();
|
2015-03-31 16:13:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CopyRadioButton_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2018-10-09 12:03:36 +02:00
|
|
|
|
tableLayoutPanelSrPicker.Enabled = CopyRadioButton.Checked;
|
2022-11-29 23:59:01 +01:00
|
|
|
|
EnableRescanButton();
|
2015-03-31 16:13:46 +02:00
|
|
|
|
// Since the radiobuttons aren't in the same panel, we have to do manual mutual exclusion
|
|
|
|
|
CloneRadioButton.Checked = !CopyRadioButton.Checked;
|
2019-09-04 01:05:33 +02:00
|
|
|
|
UpdateButtons();
|
2015-03-31 16:13:46 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|