WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-api

[Xen-API] [PATCH 3 of 4] Update code to change edition to use new module

To: xen-api@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-API] [PATCH 3 of 4] Update code to change edition to use new modules
From: Rob Hoes <rob.hoes@xxxxxxxxxx>
Date: Wed, 14 Jul 2010 15:18:22 +0100
Delivery-date: Wed, 14 Jul 2010 07:27:57 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1279117099@xxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-api-request@lists.xensource.com?subject=help>
List-id: Discussion of API issues surrounding Xen <xen-api.lists.xensource.com>
List-post: <mailto:xen-api@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-api>, <mailto:xen-api-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-api>, <mailto:xen-api-request@lists.xensource.com?subject=unsubscribe>
References: <patchbomb.1279117099@xxxxxxxxxxxxxxxxxxxxx>
Sender: xen-api-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.4.3
# HG changeset patch
# User Rob Hoes <rob.hoes@xxxxxxxxxx>
# Date 1279116492 -3600
# Node ID 5e1ae12e5f4531a3fdc1de93535dece93be62456
# Parent  6e38ba9d62d64a0067865d5fc754fff3f86e90fd
Update code to change edition to use new modules

Signed-off-by: Rob Hoes <rob.hoes@xxxxxxxxxx>

diff -r 6e38ba9d62d6 -r 5e1ae12e5f45 ocaml/license/fakev6.ml
--- a/ocaml/license/fakev6.ml
+++ b/ocaml/license/fakev6.ml
@@ -16,10 +16,6 @@
 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 () =
diff -r 6e38ba9d62d6 -r 5e1ae12e5f45 ocaml/license/license_init.ml
--- a/ocaml/license/license_init.ml
+++ b/ocaml/license/license_init.ml
@@ -32,75 +32,60 @@
        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));
diff -r 6e38ba9d62d6 -r 5e1ae12e5f45 ocaml/license/v6client.ml
--- a/ocaml/license/v6client.ml
+++ b/ocaml/license/v6client.ml
@@ -34,7 +34,7 @@
 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 () =
@@ -57,8 +57,8 @@
                                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
                        | _ -> 
@@ -123,11 +123,11 @@
                                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
@@ -153,7 +153,7 @@
                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
diff -r 6e38ba9d62d6 -r 5e1ae12e5f45 ocaml/license/v6client.mli
--- a/ocaml/license/v6client.mli
+++ b/ocaml/license/v6client.mli
@@ -18,7 +18,7 @@
 
 (** {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
@@ -29,7 +29,7 @@
 
 (** {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
diff -r 6e38ba9d62d6 -r 5e1ae12e5f45 ocaml/xapi/xapi_host.ml
--- a/ocaml/xapi/xapi_host.ml
+++ b/ocaml/xapi/xapi_host.ml
@@ -1214,53 +1214,54 @@
        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
+       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
+               | 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: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 ();
-                               Unixext.unlink_safe !License_file.filename; (* 
delete activation key, if it exists *)
-                               default (* default is free edition with 30 day 
grace validity *)
+                               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
-               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;
-               
-               begin try
-                       V6client.get_v6_license ~__context ~host ~edition
-               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]))
+               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;
 ocaml/license/fakev6.ml       |    4 -
 ocaml/license/license_init.ml |  117 ++++++++++++++++++-----------------------
 ocaml/license/v6client.ml     |   12 ++--
 ocaml/license/v6client.mli    |    4 +-
 ocaml/xapi/xapi_host.ml       |   91 ++++++++++++++++----------------
 5 files changed, 105 insertions(+), 123 deletions(-)


Attachment: xen-api.hg-3.patch
Description: Text Data

_______________________________________________
xen-api mailing list
xen-api@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/mailman/listinfo/xen-api