open D
let initialise address port edition =
- (* check edition *)
- if not (List.mem edition ["STD"; "ADV"; "ENT"; "XD"; "PLT"]) then
- failwith "unknown edition";
-
("real", Int32.of_int (-1))
let shutdown () =
let existing_license_params = Db.Host.get_license_params ~__context ~self:host in
let existing_edition = Db.Host.get_edition ~__context ~self:host in
let default = default () in
- let new_license = try
- let existing_license = of_assoc_list existing_license_params in
- match existing_edition with
- | "free" ->
- (* old Floodgate-free behaviour *)
- begin try
- License_file.do_parse_and_validate !License_file.filename;
- info "Existing free license with expiry date %s still in effect." (Date.to_string (Date.of_float !license.expiry));
- !license (* do_parse_and_validate already sets !license *)
- with
- | License_file.License_expired l -> l (* keep expired license *)
- | _ ->
- (* activation file does not exist or is invalid *)
- if existing_license.expiry < default.expiry then begin
- info "Existing free license with expiry date %s still in effect." (Date.to_string (Date.of_float existing_license.expiry));
- {default with expiry = existing_license.expiry}
- end else begin
- info "Generating new free license, which needs to be activated in 30 days.";
- default
+ let free = Edition.to_string Edition.Free in
+ let new_license =
+ try
+ let existing_license = of_assoc_list existing_license_params in
+ try match Edition.of_string existing_edition with
+ | Edition.Free ->
+ (* old Floodgate-free behaviour *)
+ begin try
+ License_file.do_parse_and_validate !License_file.filename;
+ info "Existing free license with expiry date %s still in effect." (Date.to_string (Date.of_float !license.expiry));
+ !license (* do_parse_and_validate already sets !license *)
+ with
+ | License_file.License_expired l -> l (* keep expired license *)
+ | _ ->
+ (* activation file does not exist or is invalid *)
+ if existing_license.expiry < default.expiry then begin
+ info "Existing free license with expiry date %s still in effect." (Date.to_string (Date.of_float existing_license.expiry));
+ {default with expiry = existing_license.expiry}
+ end else begin
+ info "Generating new free license, which needs to be activated in 30 days.";
+ default
+ end
end
- end
- | "enterprise" | "platinum" | "enterprise-xd" ->
- (* existing license is a v6 Essentials license -> try to check one out again *)
- begin try
- V6client.get_v6_license ~__context ~host ~edition:existing_edition;
- with _ -> error "The license-server connection details (address or port) were missing or incomplete." end;
- begin match !V6client.licensed with
- | None ->
- let upgrade_grace = read_grace_from_file () > Unix.time () in
- if upgrade_grace then begin
- info "No %s license is available, but we are still in the upgrade grace period." existing_edition;
- {existing_license with grace = "upgrade grace"}
- end else begin
- info "No %s license is available. Essentials features have been disabled." existing_edition;
- {existing_license with expiry = 0.} (* expiry date 0 means 01-01-1970, so always expired *)
+ | edition ->
+ (* existing license is a v6 Essentials license -> try to check one out again *)
+ begin try
+ V6client.get_v6_license ~__context ~host ~edition;
+ with _ -> error "The license-server connection details (address or port) were missing or incomplete." end;
+ begin match !V6client.licensed with
+ | None ->
+ let upgrade_grace = read_grace_from_file () > Unix.time () in
+ if upgrade_grace then begin
+ info "No %s license is available, but we are still in the upgrade grace period." existing_edition;
+ {existing_license with grace = "upgrade grace"}
+ end else begin
+ info "No %s license is available. Essentials features have been disabled." existing_edition;
+ {existing_license with expiry = 0.} (* expiry date 0 means 01-01-1970, so always expired *)
+ end
+ | Some license ->
+ info "Successfully checked out %s license." existing_edition;
+ (* delete upgrade-grace file, if it exists *)
+ Unixext.unlink_safe Xapi_globs.upgrade_grace_file;
+ if !V6client.grace then begin
+ Grace_retry.retry_periodically host existing_edition;
+ {existing_license with grace = "regular grace"; expiry = !V6client.expires}
+ end else
+ {existing_license with grace = "no"; expiry = !V6client.expires}
end
- | Some license ->
- info "Successfully checked out %s license." existing_edition;
- (* delete upgrade-grace file, if it exists *)
- Unixext.unlink_safe Xapi_globs.upgrade_grace_file;
- if !V6client.grace then begin
- Grace_retry.retry_periodically host existing_edition;
- {existing_license with grace = "regular grace"; expiry = !V6client.expires}
- end else
- {existing_license with grace = "no"; expiry = !V6client.expires}
- end
- | "" ->
- (* upgrade from pre-MNR *)
- if existing_license.sku = "XE Express" then begin
- info "Upgrade from free: set to free edition.";
- (* all existing license_params are kept; only fill in edition field *)
- Db.Host.set_edition ~__context ~self:host ~value:"free";
- {default with sku = "free"; expiry = existing_license.expiry}
- end else begin
- info "Upgrade from Essentials: transition to enterprise edition (30-day grace license).";
- Db.Host.set_edition ~__context ~self:host ~value:"enterprise";
- let expiry = upgrade_grace_expiry () in
- write_grace_to_file expiry;
- Unixext.unlink_safe !License_file.filename;
- V6alert.send_v6_upgrade_grace_license ();
- let name = Edition.to_marketing_name Edition.Enterprise in
- {default with sku = "enterprise"; expiry = expiry; grace = "upgrade grace"; sku_marketing_name = name}
- end
- | _ ->
- warn "Edition field corrupted; generating a new free license, which needs to be activated in 30 days.";
- default
- with _ ->
+ with Edition.Undefined_edition _ ->
+ warn "Edition field corrupted; generating a new free license, which needs to be activated in 30 days.";
+ default
+ with License.Missing_license_param _ ->
(* no license_params -> first boot *)
- Db.Host.set_edition ~__context ~self:host ~value:"free";
+ Db.Host.set_edition ~__context ~self:host ~value:free;
begin try
License_file.do_parse_and_validate !License_file.filename;
info "Found a free-license activation key with expiry date %s." (Date.to_string (Date.of_float !license.expiry));
let v6rpc xml = Xmlrpcclient.do_xml_rpc_unix ~version:"1.0" ~filename:socket ~path:"/" xml
(* conversion to v6 edition codes *)
-let editions = ["enterprise", "ENT"; "platinum", "PLT"; "enterprise-xd", "XD"]
+let editions = [Edition.Free, "FREE"]
(* reset to not-licensed state *)
let reset_state () =
if success then begin
match !licensed with
| None -> ()
- | Some l ->
- info "Checked %s license back in to license server." l;
+ | Some edition ->
+ info "Checked %s license back in to license server." (Edition.to_string edition);
reset_state ()
end
| _ ->
end;
(* check return status *)
if license = "real" then begin
- info "Checked out %s license from license server." edition;
+ info "Checked out %s license from license server." (Edition.to_string edition);
licensed := Some edition;
grace := false
end else if license = "grace" then begin
- info "Obtained %s grace license." edition;
+ info "Obtained %s grace license." (Edition.to_string edition);
licensed := Some edition;
grace := true;
if Xapi_fist.reduce_grace_period () then
let ls = Db.Host.get_license_server ~__context ~self:host in
let address = List.assoc "address" ls in
let port = int_of_string (List.assoc "port" ls) in
- debug "obtaining %s v6 license; license server address: %s; port: %d" edition address port;
+ debug "obtaining %s v6 license; license server address: %s; port: %d" (Edition.to_string edition) address port;
(* obtain v6 license *)
connect_and_get_license edition address port
with
(** {2 State variables} *)
-val licensed : string option ref
+val licensed : Edition.edition option ref
(** Equal to the edition string, if a license has been checked out,
* or None otherwise *)
val expires : float ref
(** {2 Obtaining and Releasing a License} *)
-val get_v6_license : __context:Context.t -> host:[`host] Ref.t -> edition:string -> unit
+val get_v6_license : __context:Context.t -> host:[`host] Ref.t -> edition:Edition.edition -> unit
(** Obtain a v6 license via the licensing daemon. The edition parameter is
* either "enterprise" or "platinum". Uses the contact details in host.license_server. *)
val release_v6_license : unit -> unit
let current_edition = Db.Host.get_edition ~__context ~self:host in
let current_license = !License.license in
let default = License.default () in
- let new_license = match edition with
- | "free" ->
- if current_edition = "free" then begin
- info "The host's edition is already 'free'. No change.";
- current_license
- end else begin
- info "Downgrading from %s to free edition." current_edition;
- (* CA-27011: if HA is enabled block the application from downgrading to free *)
- let pool = List.hd (Db.Pool.get_all ~__context) in
- if Db.Pool.get_ha_enabled ~__context ~self:pool then
- raise (Api_errors.Server_error (Api_errors.ha_is_enabled, []))
- else begin
- V6client.release_v6_license ();
- Unixext.unlink_safe !License_file.filename; (* delete activation key, if it exists *)
- default (* default is free edition with 30 day grace validity *)
+ let new_license =
+ try match Edition.of_string edition with
+ | Edition.Free ->
+ if Edition.of_string current_edition = Edition.Free then begin
+ info "The host's edition is already 'free'. No change.";
+ current_license
+ end else begin
+ info "Downgrading from %s to free edition." current_edition;
+ (* CA-27011: if HA is enabled block the application from downgrading to free *)
+ let pool = List.hd (Db.Pool.get_all ~__context) in
+ if Db.Pool.get_ha_enabled ~__context ~self:pool then
+ raise (Api_errors.Server_error (Api_errors.ha_is_enabled, []))
+ else begin
+ V6client.release_v6_license ();
+ Unixext.unlink_safe !License_file.filename; (* delete activation key, if it exists *)
+ default (* default is free edition with 30 day grace validity *)
+ end
end
- end
- | "enterprise" | "platinum" | "enterprise-xd" ->
- (* Try to get the a v6 license; if one has already been checked out,
- * it will be automatically checked back in. *)
- if current_edition = "free" then
- info "Upgrading from free to %s edition..." edition
- else
- info "(Re)applying %s license..." edition;
+ | e ->
+ (* Try to get the a v6 license; if one has already been checked out,
+ * it will be automatically checked back in. *)
+ if Edition.of_string current_edition = Edition.Free then
+ info "Upgrading from free to %s edition..." edition
+ else
+ info "(Re)applying %s license..." edition;
- begin try
- V6client.get_v6_license ~__context ~host ~edition
- with _ -> raise (Api_errors.Server_error (Api_errors.missing_connection_details, [])) end;
+ begin try
+ V6client.get_v6_license ~__context ~host ~edition:e
+ with _ -> raise (Api_errors.Server_error (Api_errors.missing_connection_details, [])) end;
- begin match !V6client.licensed with
- | None ->
- error "License could not be checked out. Edition is not changed.";
- V6client.release_v6_license ();
- raise (Api_errors.Server_error (Api_errors.license_checkout_error, [edition]))
- | Some license ->
- let name = Edition.to_marketing_name (Edition.of_string edition) in
- let basic = {default with License.sku = edition; License.sku_marketing_name = name;
- License.expiry = !V6client.expires} in
- if !V6client.grace then begin
- Grace_retry.retry_periodically host edition;
- {basic with License.grace = "regular grace"}
- end else
- basic
- end
- | _ ->
- error "Invalid edition ('%s')!" edition;
- raise (Api_errors.Server_error (Api_errors.invalid_edition, [edition]))
+ begin match !V6client.licensed with
+ | None ->
+ error "License could not be checked out. Edition is not changed.";
+ V6client.release_v6_license ();
+ raise (Api_errors.Server_error (Api_errors.license_checkout_error, [edition]))
+ | Some license ->
+ let name = Edition.to_marketing_name (Edition.of_string edition) in
+ let basic = {default with License.sku = edition; License.sku_marketing_name = name;
+ License.expiry = !V6client.expires} in
+ if !V6client.grace then begin
+ Grace_retry.retry_periodically host edition;
+ {basic with License.grace = "regular grace"}
+ end else
+ basic
+ end
+ with Edition.Undefined_edition e ->
+ error "Invalid edition ('%s')!" e;
+ raise (Api_errors.Server_error (Api_errors.invalid_edition, [e]))
in
License.license := new_license;
Db.Host.set_edition ~__context ~self:host ~value:edition;