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;
|
|
|
|
|
using System.Collections.Generic;
|
2020-03-30 00:49:06 +02:00
|
|
|
|
using System.Linq;
|
2018-10-09 12:03:36 +02:00
|
|
|
|
using XenAdmin.Actions.VMActions;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using XenAdmin.Controls;
|
|
|
|
|
using XenAdmin.Core;
|
2018-10-09 12:03:36 +02:00
|
|
|
|
using XenAPI;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Dialogs
|
|
|
|
|
{
|
|
|
|
|
public partial class CopyVMDialog : XenDialogBase
|
|
|
|
|
{
|
2020-03-30 00:49:06 +02:00
|
|
|
|
private readonly VM _vm;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
public CopyVMDialog(VM vm)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2020-03-30 00:49:06 +02:00
|
|
|
|
_vm = vm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnLoad(e);
|
|
|
|
|
|
|
|
|
|
labelSrHint.Text = _vm.is_a_template ? Messages.COPY_TEMPLATE_SELECT_SR : Messages.COPY_VM_SELECT_SR;
|
|
|
|
|
|
|
|
|
|
NameTextBox.Text = GetDefaultCopyName(_vm);
|
|
|
|
|
|
|
|
|
|
Text = _vm.is_a_template ? Messages.COPY_TEMPLATE : Messages.COPY_VM;
|
|
|
|
|
|
|
|
|
|
bool allowCopy = !_vm.is_a_template || _vm.allowed_operations.Contains(vm_operations.copy);
|
|
|
|
|
bool anyDiskFastCloneable = _vm.AnyDiskFastClonable();
|
|
|
|
|
bool hasAtLeastOneDisk = _vm.HasAtLeastOneDisk();
|
|
|
|
|
|
|
|
|
|
CopyRadioButton.Enabled = allowCopy && hasAtLeastOneDisk;
|
|
|
|
|
FastClonePanel.Enabled = !allowCopy || anyDiskFastCloneable || !hasAtLeastOneDisk;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (!FastClonePanel.Enabled)
|
|
|
|
|
CloneRadioButton.Checked = false;
|
2020-03-30 00:49:06 +02:00
|
|
|
|
|
|
|
|
|
if (!CloneRadioButton.Enabled)
|
|
|
|
|
CopyRadioButton.Checked = true;
|
|
|
|
|
|
|
|
|
|
tableLayoutPanelSrPicker.Enabled = CopyRadioButton.Enabled && CopyRadioButton.Checked;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
toolTipContainer1.SetToolTip(Messages.FAST_CLONE_UNAVAILABLE);
|
2020-03-30 00:49:06 +02:00
|
|
|
|
|
|
|
|
|
if (_vm.is_a_template && !(anyDiskFastCloneable || allowCopy))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
CloneRadioButton.Text = Messages.COPY_VM_CLONE_TEMPLATE_SLOW;
|
|
|
|
|
FastCloneDescription.Text = Messages.COPY_VM_SLOW_CLONE_DESCRIPTION;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-03-30 00:49:06 +02:00
|
|
|
|
FastCloneDescription.Text = !_vm.is_a_template
|
|
|
|
|
? Messages.COPY_VM_FAST_CLONE_DESCRIPTION
|
|
|
|
|
: Messages.COPY_TEMPLATE_FAST_CLONE_DESCRIPTION;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 00:49:06 +02:00
|
|
|
|
if (_vm.DescriptionType() != VM.VmDescriptionType.None)
|
|
|
|
|
DescriptionTextBox.Text = _vm.Description();
|
|
|
|
|
|
|
|
|
|
EnableMoveButton();
|
|
|
|
|
srPicker1.PopulateAsync(SrPicker.SRPickerType.MoveOrCopy, _vm.Connection,
|
|
|
|
|
_vm.Home(), null, null, _vm.TotalVMSize());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void EnableMoveButton()
|
|
|
|
|
{
|
|
|
|
|
MoveButton.Enabled = NameTextBox.Text.Trim().Length > 0 && srPicker1.SR != null;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-03-30 00:49:06 +02:00
|
|
|
|
private static string GetDefaultCopyName(VM vmToCopy)
|
|
|
|
|
{
|
|
|
|
|
var takenNames = vmToCopy.Connection.Cache.VMs.Select(vm => vm.Name()).ToList();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-03-30 00:49:06 +02:00
|
|
|
|
return Helpers.MakeUniqueName(string.Format(Messages.ACTION_TEMPLATE_CLONE_NEW_NAME, vmToCopy.Name()), takenNames);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 00:49:06 +02:00
|
|
|
|
#region Control event handlers
|
|
|
|
|
|
2019-09-04 01:05:33 +02:00
|
|
|
|
private void srPicker1_SelectedIndexChanged(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
EnableMoveButton();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void NameTextBox_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
EnableMoveButton();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CloseButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MoveButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2018-10-09 12:03:36 +02:00
|
|
|
|
if (!tableLayoutPanelSrPicker.Enabled || CloneRadioButton.Checked)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-03-30 00:49:06 +02:00
|
|
|
|
new VMCloneAction(_vm,NameTextBox.Text, DescriptionTextBox.Text).RunAsync();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
Close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (srPicker1.SR == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-03-30 00:49:06 +02:00
|
|
|
|
var action = new VMCopyAction(_vm, _vm.GetStorageHost(false), srPicker1.SR, NameTextBox.Text, DescriptionTextBox.Text);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-03-30 00:49:06 +02:00
|
|
|
|
action.RunAsync();
|
|
|
|
|
Close();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 00:49:06 +02:00
|
|
|
|
private void CopyRadioButton_CheckedChanged(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-10-09 12:03:36 +02:00
|
|
|
|
tableLayoutPanelSrPicker.Enabled = CopyRadioButton.Checked;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
// Since the radiobuttons aren't in the same panel, we have to do manual mutual exclusion
|
|
|
|
|
CloneRadioButton.Checked = !CopyRadioButton.Checked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 00:49:06 +02:00
|
|
|
|
#endregion
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|