mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2025-01-20 07:19:18 +01:00
CP-14822: UI: New VM Creation: update code to apply recommendations
This changeset implements the followings: On creation of a new VM, * XenCenter will use licensed state of the host to determine whether it should obey/apply the template-recommendation regarding the vendor device. * If the host is licensed, and the selected template's recommendations suggest that has_vendor_device can be set/should be set to true, as part of VM creation, XenCenter will set the vm's has_vendor_device based on the recommendation using set_has_vendor_device API call (after it has cloned the template and before calling vm.provision). * XenCenter will not expose details whether 1G or 2G VM is going to be created. Signed-off-by: Gabor Apati-Nagy <gabor.apati-nagy@citrix.com>
This commit is contained in:
parent
0ea26f0a85
commit
274c98d8d9
@ -198,6 +198,7 @@ namespace XenAdmin.Actions.VMActions
|
||||
|
||||
VM = Connection.WaitForCache(new XenRef<VM>(Result));
|
||||
|
||||
ApplyRecommendationsForVendorDevice();
|
||||
CopyBiosStrings();
|
||||
SetXenCenterProperties();
|
||||
ProvisionVM();
|
||||
@ -223,6 +224,25 @@ namespace XenAdmin.Actions.VMActions
|
||||
Description = Messages.VM_SUCCESSFULLY_CREATED;
|
||||
}
|
||||
|
||||
private void ApplyRecommendationsForVendorDevice()
|
||||
{
|
||||
if (Template.HasVendorDeviceRecommendation && !Helpers.FeatureForbidden(VM, Host.RestrictVendorDevice))
|
||||
{
|
||||
log.DebugFormat("Recommendation (has-vendor-device = true) has been found on the template ({0}) and the host is licensed, so applying it on VM ({1}) being created.", Template.opaque_ref, VM.opaque_ref);
|
||||
VM.set_has_vendor_device(Connection.Session, VM.opaque_ref, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
log.DebugFormat("Recommendation (has-vendor-device = true) has not been applied on the VM ({0}) being created.", VM.opaque_ref);
|
||||
|
||||
if (!Template.HasVendorDeviceRecommendation)
|
||||
log.InfoFormat("Recommendation (has-vendor-device) is not set or false on the template ({0}).", Template.opaque_ref);
|
||||
|
||||
if (Helpers.FeatureForbidden(VM, Host.RestrictVendorDevice))
|
||||
log.InfoFormat("Helpers.FeatureForbidden(VM, Host.RestrictVendorDevice) returned {0}", Helpers.FeatureForbidden(VM, Host.RestrictVendorDevice));
|
||||
}
|
||||
}
|
||||
|
||||
private void CloudCreateConfigDrive()
|
||||
{
|
||||
if (Template.CanHaveCloudConfigDrive && !string.IsNullOrEmpty(cloudConfigDriveTemplateText))
|
||||
|
@ -253,6 +253,16 @@ namespace XenAPI
|
||||
get { return BoolKeyPreferTrue(license_params, "restrict_cifs"); }
|
||||
}
|
||||
|
||||
public static bool RestrictVendorDevice(Host h)
|
||||
{
|
||||
return h._RestrictVendorDevice;
|
||||
}
|
||||
|
||||
private bool _RestrictVendorDevice
|
||||
{
|
||||
get { return BoolKeyPreferTrue(license_params, "restrict_pci_device_for_auto_update"); }
|
||||
}
|
||||
|
||||
private bool _RestrictWLB
|
||||
{
|
||||
get { return BoolKeyPreferTrue(license_params, "restrict_wlb"); }
|
||||
|
@ -501,6 +501,35 @@ namespace XenAPI
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasVendorDeviceRecommendation
|
||||
{
|
||||
get
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
XmlDocument xd = GetRecommendations();
|
||||
|
||||
if (xd == null)
|
||||
return result;
|
||||
|
||||
try
|
||||
{
|
||||
XmlNode xn = xd.SelectSingleNode(@"restrictions/restriction[@field='has-vendor-device']");
|
||||
if (xn == null || xn.Attributes == null)
|
||||
return result;
|
||||
|
||||
bool.TryParse(xn.Attributes["value"].Value, out result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Error("Error parsing has-vendor-device on the template.", ex);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>Returns true if
|
||||
/// 1) the guest is HVM and
|
||||
/// 2a) the allow-vgpu restriction is absent or
|
||||
|
Loading…
Reference in New Issue
Block a user