2023-01-24 15:29:31 +01:00
|
|
|
|
/* Copyright (c) Cloud Software Group, Inc.
|
2013-06-24 13:41:48 +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.Drawing;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using XenAdmin.Actions;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
|
2019-09-04 03:03:44 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
namespace XenAdmin.SettingsPanels
|
|
|
|
|
{
|
|
|
|
|
public partial class VDISizeLocationPage : UserControl, IEditPage
|
|
|
|
|
{
|
|
|
|
|
private VDI vdi;
|
2019-09-04 03:03:44 +02:00
|
|
|
|
private bool _validToSave;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
public VDISizeLocationPage()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
Text = Messages.SIZE_AND_LOCATION;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String SubText
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2020-10-25 14:01:56 +01:00
|
|
|
|
return string.Format(Messages.STRING_COMMA_SPACE_STRING,
|
2019-09-04 03:03:44 +02:00
|
|
|
|
Util.DiskSizeString(diskSpinner1.CanResize ? diskSpinner1.SelectedSize : vdi.virtual_size, 2),
|
2013-06-24 13:41:48 +02:00
|
|
|
|
vdi.Connection.Resolve<SR>(vdi.SR));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-18 02:20:29 +02:00
|
|
|
|
public Image Image => Images.StaticImages._000_VirtualStorage_h32bit_16;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2019-09-04 03:03:44 +02:00
|
|
|
|
public bool ValidToSave => _validToSave;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
public void SetXenObjects(IXenObject orig, IXenObject clone)
|
|
|
|
|
{
|
|
|
|
|
vdi = clone as VDI;
|
2019-09-04 03:03:44 +02:00
|
|
|
|
if (vdi == null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return;
|
2019-09-04 03:03:44 +02:00
|
|
|
|
|
2015-08-21 15:16:40 +02:00
|
|
|
|
SR sr = vdi.Connection.Resolve<SR>(vdi.SR);
|
2017-09-03 04:33:29 +02:00
|
|
|
|
labelLocationValueRO.Text = string.Format("'{0}'", sr.NameWithoutHost());
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2019-09-04 03:03:44 +02:00
|
|
|
|
diskSpinner1.Populate(vdi.virtual_size, vdi.virtual_size);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2019-09-04 03:03:44 +02:00
|
|
|
|
var canResize = vdi.allowed_operations.Contains(vdi_operations.resize) ||
|
|
|
|
|
vdi.allowed_operations.Contains(vdi_operations.resize_online);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2019-09-04 03:03:44 +02:00
|
|
|
|
diskSpinner1.CanResize = canResize;
|
|
|
|
|
tableLayoutPanelInfo.Visible = !canResize;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-04 03:03:44 +02:00
|
|
|
|
public bool HasChanged => diskSpinner1.CanResize && diskSpinner1.SelectedSize - vdi.virtual_size > 10 * Util.BINARY_MEGA;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
public void ShowLocalValidationMessages()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-23 11:34:46 +02:00
|
|
|
|
public void HideLocalValidationMessages()
|
|
|
|
|
{ }
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
public void Cleanup()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AsyncAction SaveSettings()
|
|
|
|
|
{
|
2019-09-04 03:03:44 +02:00
|
|
|
|
if (!HasChanged)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
if (vdi.allowed_operations.Contains(vdi_operations.resize))
|
|
|
|
|
return new DelegatedAsyncAction(
|
|
|
|
|
vdi.Connection,
|
|
|
|
|
Messages.ACTION_CHANGE_DISK_SIZE,
|
|
|
|
|
string.Format(Messages.ACTION_CHANGING_DISK_SIZE_FOR, vdi),
|
|
|
|
|
string.Format(Messages.ACTION_CHANGED_DISK_SIZE_FOR, vdi),
|
2019-09-04 03:03:44 +02:00
|
|
|
|
delegate(Session session) { VDI.resize(session, vdi.opaque_ref, diskSpinner1.SelectedSize); },
|
2014-07-21 12:19:04 +02:00
|
|
|
|
true,
|
2013-06-24 13:41:48 +02:00
|
|
|
|
"vdi.resize"
|
|
|
|
|
);
|
|
|
|
|
else
|
2019-09-04 03:03:44 +02:00
|
|
|
|
{
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return new DelegatedAsyncAction(
|
|
|
|
|
vdi.Connection,
|
|
|
|
|
Messages.ACTION_CHANGE_DISK_SIZE,
|
|
|
|
|
string.Format(Messages.ACTION_CHANGING_DISK_SIZE_FOR, vdi),
|
|
|
|
|
string.Format(Messages.ACTION_CHANGED_DISK_SIZE_FOR, vdi),
|
2019-09-04 03:03:44 +02:00
|
|
|
|
delegate(Session session) { VDI.resize_online(session, vdi.opaque_ref, diskSpinner1.SelectedSize); },
|
2014-07-21 12:19:04 +02:00
|
|
|
|
true,
|
2013-06-24 13:41:48 +02:00
|
|
|
|
"vdi.resize_online"
|
|
|
|
|
);
|
2019-09-04 03:03:44 +02:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-04 03:03:44 +02:00
|
|
|
|
private void diskSpinner1_SelectedSizeChanged()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2019-09-04 03:03:44 +02:00
|
|
|
|
if (!diskSpinner1.IsSizeValid)
|
|
|
|
|
{
|
|
|
|
|
_validToSave = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2019-09-04 03:03:44 +02:00
|
|
|
|
SR sr = vdi.Connection.Resolve(vdi.SR);
|
|
|
|
|
SM sm = sr == null ? null : sr.GetSM();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2019-09-04 03:03:44 +02:00
|
|
|
|
bool vdiSizeUnlimited = sm != null && Array.IndexOf(sm.capabilities, "LARGE_VDI") != -1;
|
|
|
|
|
if (!vdiSizeUnlimited && diskSpinner1.SelectedSize > SR.DISK_MAX_SIZE)
|
|
|
|
|
{
|
|
|
|
|
diskSpinner1.SetError(string.Format(Messages.DISK_TOO_BIG_MAX_SIZE, Util.DiskSizeString(SR.DISK_MAX_SIZE)));
|
|
|
|
|
_validToSave = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2019-09-04 03:03:44 +02:00
|
|
|
|
bool isThinlyProvisioned = sm != null && Array.IndexOf(sm.capabilities, "THIN_PROVISIONING") != -1;
|
|
|
|
|
if (!isThinlyProvisioned && sr != null && diskSpinner1.SelectedSize - vdi.virtual_size > sr.FreeSpace())
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2019-09-04 03:03:44 +02:00
|
|
|
|
diskSpinner1.SetError(Messages.DISK_TOO_BIG);
|
|
|
|
|
_validToSave = false;
|
|
|
|
|
return;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-04 03:03:44 +02:00
|
|
|
|
_validToSave = true;
|
|
|
|
|
diskSpinner1.SetError(null);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|