2018-08-23 08:41:35 +02:00
|
|
|
|
/* Copyright (c) Citrix Systems, Inc.
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-08-31 03:02:33 +02:00
|
|
|
|
using System.ComponentModel;
|
2018-08-23 08:41:35 +02:00
|
|
|
|
using System.Windows.Forms;
|
2018-12-18 16:56:27 +01:00
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using XenAdmin.Network;
|
2018-08-23 08:41:35 +02:00
|
|
|
|
using XenAPI;
|
|
|
|
|
using BootMode = XenAdmin.Actions.VMActions.BootMode;
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Wizards
|
|
|
|
|
{
|
|
|
|
|
public partial class BootModesControl : UserControl
|
|
|
|
|
{
|
|
|
|
|
public BootModesControl()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-31 03:02:33 +02:00
|
|
|
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
2018-08-23 08:41:35 +02:00
|
|
|
|
public VM TemplateVM
|
|
|
|
|
{
|
|
|
|
|
get { return _templateVM; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_templateVM == value)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_templateVM = value;
|
2018-12-18 16:56:27 +01:00
|
|
|
|
|
|
|
|
|
if (_templateVM != null)
|
2018-08-23 08:41:35 +02:00
|
|
|
|
{
|
2018-12-18 16:56:27 +01:00
|
|
|
|
_connection = _templateVM.Connection;
|
2018-08-23 08:41:35 +02:00
|
|
|
|
}
|
2018-12-18 16:56:27 +01:00
|
|
|
|
UpdateControls();
|
2018-08-23 08:41:35 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private VM _templateVM;
|
|
|
|
|
|
2018-12-18 16:56:27 +01:00
|
|
|
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
|
|
|
|
public IXenConnection Connection
|
|
|
|
|
{
|
|
|
|
|
get { return _connection; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_connection == value)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_connection = value;
|
|
|
|
|
UpdateControls();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private IXenConnection _connection;
|
|
|
|
|
|
2018-08-23 08:41:35 +02:00
|
|
|
|
public BootMode SelectedOption
|
|
|
|
|
{
|
2018-08-31 03:02:33 +02:00
|
|
|
|
get { return radioButtonUEFISecureBoot.Checked ? BootMode.UEFI_SECURE_BOOT : (radioButtonUEFIBoot.Checked ? BootMode.UEFI_BOOT : BootMode.BIOS_BOOT); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CheckBIOSBootMode()
|
|
|
|
|
{
|
|
|
|
|
radioButtonBIOSBoot.Checked = true;
|
2018-08-23 08:41:35 +02:00
|
|
|
|
}
|
2018-12-18 16:56:27 +01:00
|
|
|
|
|
|
|
|
|
private void UpdateControls()
|
|
|
|
|
{
|
2019-10-31 15:03:36 +01:00
|
|
|
|
radioButtonBIOSBoot.Enabled = true;
|
2018-12-18 16:56:27 +01:00
|
|
|
|
radioButtonUEFIBoot.Visible = !Helpers.FeatureForbidden(_connection, Host.UefiBootDisabled);
|
|
|
|
|
radioButtonUEFISecureBoot.Visible = !Helpers.FeatureForbidden(_connection, Host.UefiSecureBootDisabled);
|
|
|
|
|
|
|
|
|
|
// ensure that a visible option is selected
|
|
|
|
|
if (radioButtonUEFIBoot.Checked && !radioButtonUEFIBoot.Visible)
|
|
|
|
|
radioButtonBIOSBoot.Checked = true;
|
|
|
|
|
|
|
|
|
|
if (radioButtonUEFISecureBoot.Checked && !radioButtonUEFISecureBoot.Visible)
|
|
|
|
|
radioButtonBIOSBoot.Checked = true;
|
|
|
|
|
|
|
|
|
|
if (_templateVM != null)
|
|
|
|
|
{
|
|
|
|
|
radioButtonUEFIBoot.Enabled = _templateVM.CanSupportUEFIBoot();
|
|
|
|
|
radioButtonUEFISecureBoot.Enabled = _templateVM.CanSupportUEFISecureBoot();
|
|
|
|
|
|
|
|
|
|
if (_templateVM.IsUEFIEnabled())
|
2019-10-31 15:03:36 +01:00
|
|
|
|
{
|
2018-12-18 16:56:27 +01:00
|
|
|
|
if (_templateVM.IsSecureBootEnabled())
|
|
|
|
|
radioButtonUEFISecureBoot.Checked = true;
|
|
|
|
|
else
|
|
|
|
|
radioButtonUEFIBoot.Checked = true;
|
2019-10-31 15:03:36 +01:00
|
|
|
|
|
|
|
|
|
if (!_templateVM.CanChangeBootMode())
|
|
|
|
|
radioButtonBIOSBoot.Enabled = false;
|
|
|
|
|
}
|
2018-12-18 16:56:27 +01:00
|
|
|
|
else
|
2019-10-31 15:03:36 +01:00
|
|
|
|
{
|
2018-12-18 16:56:27 +01:00
|
|
|
|
radioButtonBIOSBoot.Checked = true;
|
2019-10-31 15:03:36 +01:00
|
|
|
|
if (!_templateVM.CanChangeBootMode())
|
|
|
|
|
radioButtonUEFIBoot.Enabled = radioButtonUEFISecureBoot.Enabled = false;
|
|
|
|
|
}
|
2018-12-18 16:56:27 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
radioButtonBIOSBoot.Checked = true;
|
|
|
|
|
radioButtonUEFIBoot.Checked = false;
|
|
|
|
|
radioButtonUEFISecureBoot.Checked = false;
|
|
|
|
|
}
|
2019-02-15 15:30:39 +01:00
|
|
|
|
|
2018-12-18 16:56:27 +01:00
|
|
|
|
ShowTemplateWarning();
|
2019-02-15 15:30:39 +01:00
|
|
|
|
|
|
|
|
|
// show the experimental message
|
|
|
|
|
ShowExperimentalWarning();
|
2018-12-18 16:56:27 +01:00
|
|
|
|
}
|
|
|
|
|
private void ShowExperimentalWarning()
|
|
|
|
|
{
|
|
|
|
|
var uefiExperimental = Helpers.FeatureForbidden(_connection, Host.UefiBootExperimental);
|
|
|
|
|
var uefiSecureExperimental = Helpers.FeatureForbidden(_connection, Host.UefiSecureBootExperimental);
|
2019-02-15 15:30:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
radioButtonUEFIBoot.Text = uefiExperimental
|
|
|
|
|
? Messages.GUEFI_BOOT_MODE_EXPERIMENTAL_LABEL
|
|
|
|
|
: Messages.GUEFI_BOOT_MODE_LABEL;
|
|
|
|
|
radioButtonUEFISecureBoot.Text = uefiSecureExperimental
|
|
|
|
|
? Messages.GUEFI_SECURE_BOOT_MODE_EXPERIMENTAL_LABEL
|
|
|
|
|
: Messages.GUEFI_SECURE_BOOT_MODE_LABEL;
|
|
|
|
|
|
|
|
|
|
if ((uefiExperimental || uefiSecureExperimental) && (radioButtonUEFIBoot.Enabled || radioButtonUEFISecureBoot.Enabled))
|
2018-12-18 16:56:27 +01:00
|
|
|
|
{
|
2019-02-15 15:30:39 +01:00
|
|
|
|
imgExperimental.Visible = labelExperimental.Visible = radioButtonUEFIBoot.Enabled || radioButtonUEFISecureBoot.Enabled;
|
2018-12-18 16:56:27 +01:00
|
|
|
|
labelExperimental.Text = uefiExperimental && uefiSecureExperimental
|
2021-03-16 02:50:45 +01:00
|
|
|
|
? string.Format(Messages.GUEFI_BOOT_MODES_EXPERIMENTAL_WARNING, BrandManager.ProductBrand)
|
2018-12-18 16:56:27 +01:00
|
|
|
|
: uefiExperimental
|
2021-03-16 02:50:45 +01:00
|
|
|
|
? string.Format(Messages.GUEFI_BOOT_MODE_EXPERIMENTAL_WARNING, BrandManager.ProductBrand)
|
|
|
|
|
: string.Format(Messages.GUEFI_SECUREBOOT_MODE_EXPERIMENTAL_WARNING, BrandManager.ProductBrand);
|
2018-12-18 16:56:27 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
imgExperimental.Visible = labelExperimental.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ShowTemplateWarning()
|
|
|
|
|
{
|
|
|
|
|
if (_templateVM == null)
|
|
|
|
|
{
|
|
|
|
|
imgUnsupported.Visible = labelUnsupported.Visible = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-31 15:03:36 +01:00
|
|
|
|
if (radioButtonBIOSBoot.Visible && !radioButtonBIOSBoot.Enabled)
|
|
|
|
|
{
|
|
|
|
|
imgUnsupported.Visible = labelUnsupported.Visible = true;
|
|
|
|
|
labelUnsupported.Text = Messages.BIOS_BOOT_MODE_UNSUPPORTED_WARNING;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-18 16:56:27 +01:00
|
|
|
|
var uefiNotSupported = radioButtonUEFIBoot.Visible && !radioButtonUEFIBoot.Enabled;
|
|
|
|
|
var uefiSecureNotSupported = radioButtonUEFISecureBoot.Visible && !radioButtonUEFISecureBoot.Enabled;
|
|
|
|
|
if (uefiNotSupported || uefiSecureNotSupported)
|
|
|
|
|
{
|
|
|
|
|
imgUnsupported.Visible = labelUnsupported.Visible = true;
|
|
|
|
|
labelUnsupported.Text = uefiNotSupported && uefiSecureNotSupported
|
|
|
|
|
? Messages.GUEFI_BOOT_MODES_UNSUPPORTED_WARNING
|
|
|
|
|
: uefiNotSupported
|
|
|
|
|
? Messages.GUEFI_BOOT_MODE_UNSUPPORTED_WARNING
|
|
|
|
|
: Messages.GUEFI_SECUREBOOT_MODE_UNSUPPORTED_WARNING;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
imgUnsupported.Visible = labelUnsupported.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-02-15 15:30:39 +01:00
|
|
|
|
|
|
|
|
|
public static bool ShowBootModeOptions(IXenConnection connection)
|
|
|
|
|
{
|
|
|
|
|
return Helpers.NaplesOrGreater(connection) &&
|
|
|
|
|
(!Helpers.FeatureForbidden(connection, Host.UefiBootDisabled) || !Helpers.FeatureForbidden(connection, Host.UefiSecureBootDisabled));
|
|
|
|
|
}
|
2018-08-23 08:41:35 +02:00
|
|
|
|
}
|
|
|
|
|
}
|