CA-209281: Check pool.policy_no_vendor_device on VM create before setting VM's has_vendor_device property

Signed-off-by: Mihaela Stoica <Mihaela.Stoica@citrix.com>
This commit is contained in:
Mihaela Stoica 2016-04-27 09:58:33 +01:00
parent c3e0fd082e
commit 219209f1fe
3 changed files with 73 additions and 5 deletions

View File

@ -226,7 +226,10 @@ namespace XenAdmin.Actions.VMActions
private void ApplyRecommendationsForVendorDevice()
{
if (Template.HasVendorDeviceRecommendation && !Helpers.FeatureForbidden(VM, Host.RestrictVendorDevice))
var pool = Helpers.GetPoolOfOne(Connection);
bool poolPolicyNoVendorDevice = pool == null || pool.policy_no_vendor_device;
if (Template.HasVendorDeviceRecommendation && !poolPolicyNoVendorDevice && !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);
@ -236,10 +239,13 @@ namespace XenAdmin.Actions.VMActions
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);
log.DebugFormat("Recommendation (has-vendor-device) is not set or false on the template ({0}).", Template.opaque_ref);
if (poolPolicyNoVendorDevice)
log.DebugFormat("pool.policy_no_vendor_device returned {0}", poolPolicyNoVendorDevice);
if (Helpers.FeatureForbidden(VM, Host.RestrictVendorDevice))
log.InfoFormat("Helpers.FeatureForbidden(VM, Host.RestrictVendorDevice) returned {0}", Helpers.FeatureForbidden(VM, Host.RestrictVendorDevice));
log.DebugFormat("Helpers.FeatureForbidden(VM, Host.RestrictVendorDevice) returned {0}", Helpers.FeatureForbidden(VM, Host.RestrictVendorDevice));
}
}

View File

@ -80,7 +80,8 @@ namespace XenAPI
List<pool_allowed_operations> allowed_operations,
Dictionary<string, pool_allowed_operations> current_operations,
Dictionary<string, string> guest_agent_config,
Dictionary<string, string> cpu_info)
Dictionary<string, string> cpu_info,
bool policy_no_vendor_device)
{
this.uuid = uuid;
this.name_label = name_label;
@ -115,6 +116,7 @@ namespace XenAPI
this.current_operations = current_operations;
this.guest_agent_config = guest_agent_config;
this.cpu_info = cpu_info;
this.policy_no_vendor_device = policy_no_vendor_device;
}
/// <summary>
@ -161,6 +163,7 @@ namespace XenAPI
current_operations = update.current_operations;
guest_agent_config = update.guest_agent_config;
cpu_info = update.cpu_info;
policy_no_vendor_device = update.policy_no_vendor_device;
}
internal void UpdateFromProxy(Proxy_Pool proxy)
@ -198,6 +201,7 @@ namespace XenAPI
current_operations = proxy.current_operations == null ? null : Maps.convert_from_proxy_string_pool_allowed_operations(proxy.current_operations);
guest_agent_config = proxy.guest_agent_config == null ? null : Maps.convert_from_proxy_string_string(proxy.guest_agent_config);
cpu_info = proxy.cpu_info == null ? null : Maps.convert_from_proxy_string_string(proxy.cpu_info);
policy_no_vendor_device = (bool)proxy.policy_no_vendor_device;
}
public Proxy_Pool ToProxy()
@ -236,6 +240,7 @@ namespace XenAPI
result_.current_operations = Maps.convert_to_proxy_string_pool_allowed_operations(current_operations);
result_.guest_agent_config = Maps.convert_to_proxy_string_string(guest_agent_config);
result_.cpu_info = Maps.convert_to_proxy_string_string(cpu_info);
result_.policy_no_vendor_device = policy_no_vendor_device;
return result_;
}
@ -278,6 +283,7 @@ namespace XenAPI
current_operations = Maps.convert_from_proxy_string_pool_allowed_operations(Marshalling.ParseHashTable(table, "current_operations"));
guest_agent_config = Maps.convert_from_proxy_string_string(Marshalling.ParseHashTable(table, "guest_agent_config"));
cpu_info = Maps.convert_from_proxy_string_string(Marshalling.ParseHashTable(table, "cpu_info"));
policy_no_vendor_device = Marshalling.ParseBool(table, "policy_no_vendor_device");
}
public bool DeepEquals(Pool other, bool ignoreCurrentOperations)
@ -321,7 +327,8 @@ namespace XenAPI
Helper.AreEqual2(this._ha_cluster_stack, other._ha_cluster_stack) &&
Helper.AreEqual2(this._allowed_operations, other._allowed_operations) &&
Helper.AreEqual2(this._guest_agent_config, other._guest_agent_config) &&
Helper.AreEqual2(this._cpu_info, other._cpu_info);
Helper.AreEqual2(this._cpu_info, other._cpu_info) &&
Helper.AreEqual2(this._policy_no_vendor_device, other._policy_no_vendor_device);
}
public override string SaveChanges(Session session, string opaqueRef, Pool server)
@ -381,6 +388,10 @@ namespace XenAPI
{
Pool.set_wlb_verify_cert(session, opaqueRef, _wlb_verify_cert);
}
if (!Helper.AreEqual2(_policy_no_vendor_device, server._policy_no_vendor_device))
{
Pool.set_policy_no_vendor_device(session, opaqueRef, _policy_no_vendor_device);
}
return null;
}
@ -770,6 +781,17 @@ namespace XenAPI
return Maps.convert_from_proxy_string_string(session.proxy.pool_get_cpu_info(session.uuid, (_pool != null) ? _pool : "").parse());
}
/// <summary>
/// Get the policy_no_vendor_device field of the given pool.
/// First published in XenServer Dundee.
/// </summary>
/// <param name="session">The session</param>
/// <param name="_pool">The opaque_ref of the given pool</param>
public static bool get_policy_no_vendor_device(Session session, string _pool)
{
return (bool)session.proxy.pool_get_policy_no_vendor_device(session.uuid, (_pool != null) ? _pool : "").parse();
}
/// <summary>
/// Set the name_label field of the given pool.
/// First published in XenServer 4.0.
@ -1013,6 +1035,18 @@ namespace XenAPI
session.proxy.pool_set_wlb_verify_cert(session.uuid, (_pool != null) ? _pool : "", _wlb_verify_cert).parse();
}
/// <summary>
/// Set the policy_no_vendor_device field of the given pool.
/// First published in XenServer Dundee.
/// </summary>
/// <param name="session">The session</param>
/// <param name="_pool">The opaque_ref of the given pool</param>
/// <param name="_policy_no_vendor_device">New value to set</param>
public static void set_policy_no_vendor_device(Session session, string _pool, bool _policy_no_vendor_device)
{
session.proxy.pool_set_policy_no_vendor_device(session.uuid, (_pool != null) ? _pool : "", _policy_no_vendor_device).parse();
}
/// <summary>
/// Instruct host to join a new pool
/// First published in XenServer 4.0.
@ -2646,5 +2680,24 @@ namespace XenAPI
}
}
private Dictionary<string, string> _cpu_info;
/// <summary>
/// The pool-wide policy for clients on whether to use the vendor device or not on newly created VMs. This field will also be consulted if the 'has_vendor_device' field is not specified in the VM.create call.
/// First published in XenServer Dundee.
/// </summary>
public virtual bool policy_no_vendor_device
{
get { return _policy_no_vendor_device; }
set
{
if (!Helper.AreEqual(value, _policy_no_vendor_device))
{
_policy_no_vendor_device = value;
Changed = true;
NotifyPropertyChanged("policy_no_vendor_device");
}
}
}
private bool _policy_no_vendor_device;
}
}

View File

@ -592,6 +592,10 @@ namespace XenAPI
Response<Object>
pool_get_cpu_info(string session, string _pool);
[XmlRpcMethod("pool.get_policy_no_vendor_device")]
Response<bool>
pool_get_policy_no_vendor_device(string session, string _pool);
[XmlRpcMethod("pool.set_name_label")]
Response<string>
pool_set_name_label(string session, string _pool, string _name_label);
@ -672,6 +676,10 @@ namespace XenAPI
Response<string>
pool_set_wlb_verify_cert(string session, string _pool, bool _wlb_verify_cert);
[XmlRpcMethod("pool.set_policy_no_vendor_device")]
Response<string>
pool_set_policy_no_vendor_device(string session, string _pool, bool _policy_no_vendor_device);
[XmlRpcMethod("pool.join")]
Response<string>
pool_join(string session, string _master_address, string _master_username, string _master_password);
@ -6954,6 +6962,7 @@ namespace XenAPI
public Object current_operations;
public Object guest_agent_config;
public Object cpu_info;
public bool policy_no_vendor_device;
}
[XmlRpcMissingMapping(MappingAction.Ignore)]