[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-API] [PATCH 2 of 4] Make License_check independent of License module
# HG changeset patch # User Rob Hoes <rob.hoes@xxxxxxxxxx> # Date 1279116492 -3600 # Node ID 6e38ba9d62d64a0067865d5fc754fff3f86e90fd # Parent 657b16d89d927a395a77db15f7bfaeb6157e2436 Make License_check independent of License module Rather, find the expiry date of a license in the host.license_params:expiry database field. If this key is absent, the license never expires. Signed-off-by: Rob Hoes <rob.hoes@xxxxxxxxxx> diff -r 657b16d89d92 -r 6e38ba9d62d6 ocaml/license/license.ml --- a/ocaml/license/license.ml +++ b/ocaml/license/license.ml @@ -155,7 +155,5 @@ (* Calls to obtain info about license *) let check_expiry l = - Unix.time () < l.expiry + Unix.time () < l.expiry -let license_valid () = check_expiry !license - diff -r 657b16d89d92 -r 6e38ba9d62d6 ocaml/license/license.mli --- a/ocaml/license/license.mli +++ b/ocaml/license/license.mli @@ -54,10 +54,6 @@ (** Check whether a given license is valid or expired. *) val check_expiry : license -> bool -(** Check whether the current license is valid or expired. - * Called from xapi/license_check.ml. *) -val license_valid : unit -> bool - (** Thrown if we fail to find a license param. *) exception Missing_license_param of string diff -r 657b16d89d92 -r 6e38ba9d62d6 ocaml/xapi/license_check.ml --- a/ocaml/xapi/license_check.ml +++ b/ocaml/xapi/license_check.ml @@ -16,8 +16,19 @@ open Stringext let vm ~__context vm = - (* Here we check that the license is still valid - this should be the only place where this happens *) - if not (License.license_valid ()) then raise (Api_errors.Server_error (Api_errors.license_expired, [])) + (* Here we check that the license is still valid - this should be the only place where this happens *) + let host = Helpers.get_localhost ~__context in + let license = Db.Host.get_license_params ~__context ~self:host in + let expired = + if List.mem_assoc "expiry" license = false then + (* No expiry date means no expiry :) *) + false + else begin + let expiry = (Date.to_float (Date.of_string (List.assoc "expiry" license))) in + Unix.time () > expiry + end + in + if expired then raise (Api_errors.Server_error (Api_errors.license_expired, [])) (* XXX: why use a "with_" style function here? *) let with_vm_license_check ~__context v f = diff -r 657b16d89d92 -r 6e38ba9d62d6 ocaml/xapi/license_check.mli --- a/ocaml/xapi/license_check.mli +++ b/ocaml/xapi/license_check.mli @@ -18,8 +18,8 @@ (** Raises {!Api_errors.license_expired} if the current license has expired. * The consequence would be that the VM is not allowed to start. *) -val vm : __context:'a -> API.ref_VM -> unit +val vm : __context:Context.t -> API.ref_VM -> unit (** Executes function [f] only if the current license has not yet expired. * If it has expired, it raises {!Api_errors.license_expired}. *) -val with_vm_license_check : __context:'a -> [`VM] Ref.t -> (unit -> 'b) -> 'b +val with_vm_license_check : __context:Context.t -> [`VM] Ref.t -> (unit -> 'b) -> 'b ocaml/license/license.ml | 4 +--- ocaml/license/license.mli | 4 ---- ocaml/xapi/license_check.ml | 15 +++++++++++++-- ocaml/xapi/license_check.mli | 4 ++-- 4 files changed, 16 insertions(+), 11 deletions(-) Attachment:
xen-api.hg-2.patch _______________________________________________ xen-api mailing list xen-api@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/mailman/listinfo/xen-api
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |