mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2025-01-20 15:29:26 +01:00
CP-43000: Add Host
extension methods to check if upselling messages are needed
Signed-off-by: Danilo Del Busso <danilo.delbusso@cloud.com>
This commit is contained in:
parent
c439f3de41
commit
3bf6a88f9c
@ -350,7 +350,7 @@ namespace XenAdmin
|
||||
public const long TicksBefore1970 = 621355968000000000;
|
||||
|
||||
public static readonly string[] Iso8601DateFormats = {"yyyyMMddTHH:mm:ssZ", "yyyy-MM-ddTHH:mm:ssZ"};
|
||||
public static readonly string[] NonIso8601DateFormats = { "yyyy-MM-dd" };
|
||||
public static readonly string[] NonIso8601DateFormats = { "yyyy-MM-dd", "yyyy.mmdd" };
|
||||
|
||||
public static DateTime GetUnixMinDateTime()
|
||||
{
|
||||
|
@ -44,7 +44,7 @@ namespace XenAPI
|
||||
{
|
||||
public partial class Host : IComparable<Host>, IEquatable<Host>
|
||||
{
|
||||
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod()?.DeclaringType);
|
||||
|
||||
public enum Edition
|
||||
{
|
||||
@ -143,6 +143,7 @@ namespace XenAPI
|
||||
case Edition.Standard:
|
||||
return "standard";
|
||||
default:
|
||||
// CP-43000: For some hosts "trial" works, too. However, "express" is valid from Naples onwards
|
||||
return Helpers.NaplesOrGreater(this) ? "express" : "free";
|
||||
}
|
||||
}
|
||||
@ -187,6 +188,7 @@ namespace XenAPI
|
||||
|
||||
/// <summary>
|
||||
/// The expiry date of this host's license in UTC.
|
||||
/// Defaults to 2030-01-01 if not found.
|
||||
/// </summary>
|
||||
public virtual DateTime LicenseExpiryUTC()
|
||||
{
|
||||
@ -196,6 +198,25 @@ namespace XenAPI
|
||||
return new DateTime(2030, 1, 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The CSS expiry date of this host's license.
|
||||
/// The time component is always set to midnight.
|
||||
/// Returns null if the value doesn't exist.
|
||||
/// </summary>
|
||||
public virtual DateTime? LicenseCssExpiry()
|
||||
{
|
||||
if(license_params != null &&
|
||||
license_params.TryGetValue("css_expiry", out var cssExpiryValue) &&
|
||||
!string.IsNullOrEmpty(cssExpiryValue) &&
|
||||
Util.TryParseNonIso8601DateTime(cssExpiryValue, out var result))
|
||||
{
|
||||
// css_expiry is not a datetime object
|
||||
return result.Date;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static bool RestrictRBAC(Host h)
|
||||
{
|
||||
return BoolKeyPreferTrue(h.license_params, "restrict_rbac");
|
||||
@ -293,7 +314,7 @@ namespace XenAPI
|
||||
|
||||
public virtual bool IsFreeLicense()
|
||||
{
|
||||
return edition == "free" || edition == "express";
|
||||
return edition == "free" || edition == "express" || edition == "trial";
|
||||
}
|
||||
|
||||
public virtual bool IsFreeLicenseOrExpired()
|
||||
@ -303,6 +324,44 @@ namespace XenAPI
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// True if host qualifies for showing an upselling message based on its license and version.
|
||||
/// <br />
|
||||
/// Used to decide whether or not to show the upselling message from trial or express edition.
|
||||
/// <br />
|
||||
/// See CP-43000 for more info.
|
||||
/// </summary>
|
||||
public virtual bool CanShowTrialEditionUpsell()
|
||||
{
|
||||
if (IsFreeLicense() &&
|
||||
software_version.TryGetValue("is_preview_release", out var isPreviewReleaseString) &&
|
||||
bool.TryParse(isPreviewReleaseString, out var isPreviewRelease) && !isPreviewRelease)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the CSS license has expired, regardless of what edition is shown.
|
||||
/// <br />
|
||||
/// Do not rely on this method for enforcing restrictions as the user can circumvent this method
|
||||
/// by updating the system date.
|
||||
/// </summary>
|
||||
public virtual bool CssLicenseHasExpired()
|
||||
{
|
||||
var cssExpiry = LicenseCssExpiry();
|
||||
|
||||
if (cssExpiry != null)
|
||||
{
|
||||
// User can circumvent this by changing system date
|
||||
return DateTime.Now > cssExpiry;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool RestrictHA(Host h)
|
||||
{
|
||||
return !BoolKey(h.license_params, "enable_xha");
|
||||
|
Loading…
Reference in New Issue
Block a user