2017-01-16 20:59:50 +01:00
|
|
|
|
/* Copyright (c) Citrix Systems, Inc.
|
2015-03-31 16:13:46 +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;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using XenAdmin.Controls;
|
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
using XenAdmin.Actions;
|
|
|
|
|
using XenAdmin.Actions.VMActions;
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Wizards.CrossPoolMigrateWizard
|
|
|
|
|
{
|
|
|
|
|
public partial class IntraPoolCopyPage : XenTabPage
|
|
|
|
|
{
|
|
|
|
|
public readonly VM TheVM;
|
|
|
|
|
|
|
|
|
|
public IntraPoolCopyPage(List<VM> selectedVMs)
|
|
|
|
|
{
|
|
|
|
|
this.TheVM = selectedVMs[0];
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool _buttonNextEnabled;
|
2017-01-16 20:59:50 +01:00
|
|
|
|
private bool _buttonPreviousEnabled;
|
|
|
|
|
|
|
|
|
|
public bool CloneVM
|
|
|
|
|
{
|
|
|
|
|
get { return !srPicker1.Enabled || CloneRadioButton.Checked; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SR SelectedSR
|
|
|
|
|
{
|
|
|
|
|
get { return srPicker1.SR; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string NewVmName
|
|
|
|
|
{
|
|
|
|
|
get { return NameTextBox.Text; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string NewVMmDescription
|
|
|
|
|
{
|
|
|
|
|
get { return DescriptionTextBox.Text; }
|
2016-09-29 13:40:35 +02:00
|
|
|
|
}
|
2015-03-31 16:13:46 +02:00
|
|
|
|
|
|
|
|
|
#region Base class (XenTabPage) overrides
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the page's title (headline)
|
|
|
|
|
/// </summary>
|
2015-03-31 18:40:05 +02:00
|
|
|
|
public override string PageTitle { get { return 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>
|
2015-03-31 18:40:05 +02:00
|
|
|
|
public override string Text { get { return 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>
|
|
|
|
|
public override string HelpID { get { return "IntraPoolCopy"; } }
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
SetButtonsEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void PopulatePage()
|
|
|
|
|
{
|
|
|
|
|
srPicker1.Usage = SrPicker.SRPickerType.MoveOrCopy;
|
2016-06-27 11:20:23 +02:00
|
|
|
|
srPicker1.ItemSelectionNotNull += srPicker1_ItemSelectionNotNull;
|
|
|
|
|
srPicker1.ItemSelectionNull += srPicker1_ItemSelectionNull;
|
2015-03-31 16:13:46 +02:00
|
|
|
|
Host affinity = TheVM.Home();
|
|
|
|
|
srPicker1.Connection = TheVM.Connection;
|
2017-09-03 04:33:29 +02:00
|
|
|
|
srPicker1.DiskSize = TheVM.TotalVMSize();
|
2016-09-29 13:40:35 +02:00
|
|
|
|
srPicker1.SrHint.Text = TheVM.is_a_template ? Messages.COPY_TEMPLATE_SELECT_SR : Messages.COPY_VM_SELECT_SR;
|
2015-03-31 16:13:46 +02:00
|
|
|
|
srPicker1.SetAffinity(affinity);
|
|
|
|
|
Pool pool = Helpers.GetPoolOfOne(TheVM.Connection);
|
|
|
|
|
if (pool != null)
|
|
|
|
|
srPicker1.DefaultSR = TheVM.Connection.Resolve(pool.default_SR);
|
|
|
|
|
|
|
|
|
|
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;
|
2015-03-31 16:13:46 +02:00
|
|
|
|
if (!FastClonePanel.Enabled)
|
|
|
|
|
{
|
|
|
|
|
CloneRadioButton.Checked = false;
|
|
|
|
|
}
|
2017-09-03 04:33:29 +02:00
|
|
|
|
toolTipContainer1.SetToolTip(Messages.FAST_CLONE_UNAVAILABLE);
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!CloneRadioButton.Enabled)
|
|
|
|
|
CopyRadioButton.Checked = true;
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
srPicker1.srListBox.Invalidate();
|
|
|
|
|
srPicker1.selectDefaultSROrAny();
|
|
|
|
|
|
|
|
|
|
srPicker1.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;
|
2015-03-31 16:13:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool EnableNext()
|
|
|
|
|
{
|
|
|
|
|
return _buttonNextEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool EnablePrevious()
|
|
|
|
|
{
|
|
|
|
|
return _buttonPreviousEnabled;
|
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
|
|
|
|
{
|
|
|
|
|
var l = new List<VM>();
|
|
|
|
|
l.Add(TheVM);
|
|
|
|
|
if (!CrossPoolMigrateWizard.AllVMsAvailable(l))
|
|
|
|
|
{
|
|
|
|
|
cancel = true;
|
|
|
|
|
SetButtonsEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
2016-09-29 13:40:35 +02:00
|
|
|
|
private void SetButtonsEnabled(bool enabled)
|
2015-03-31 16:13:46 +02:00
|
|
|
|
{
|
|
|
|
|
_buttonNextEnabled = enabled;
|
|
|
|
|
_buttonPreviousEnabled = enabled;
|
|
|
|
|
OnPageUpdated();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-27 11:20:23 +02:00
|
|
|
|
private void srPicker1_ItemSelectionNull()
|
2015-03-31 16:13:46 +02:00
|
|
|
|
{
|
|
|
|
|
EnableMoveButton();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-27 11:20:23 +02:00
|
|
|
|
private void srPicker1_ItemSelectionNotNull()
|
2015-03-31 16:13:46 +02:00
|
|
|
|
{
|
|
|
|
|
EnableMoveButton();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void NameTextBox_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
EnableMoveButton();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void EnableMoveButton()
|
|
|
|
|
{
|
|
|
|
|
_buttonNextEnabled = NameTextBox.Text.Trim().Length > 0 && srPicker1.SR != null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CopyRadioButton_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
srPicker1.Enabled = CopyRadioButton.Checked;
|
|
|
|
|
// Since the radiobuttons aren't in the same panel, we have to do manual mutual exclusion
|
|
|
|
|
CloneRadioButton.Checked = !CopyRadioButton.Checked;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|