]> xenbits.xensource.com Git - xcp/xen-api.git/commitdiff
Update pool join code to use new modules
authorRob Hoes <rob.hoes@citrix.com>
Wed, 14 Jul 2010 15:43:35 +0000 (16:43 +0100)
committerRob Hoes <rob.hoes@citrix.com>
Wed, 14 Jul 2010 15:43:35 +0000 (16:43 +0100)
Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
ocaml/license/edition.ml
ocaml/license/edition.mli
ocaml/xapi/xapi_pool.ml

index 54c9c91c4f92487f94fff2b1c0d9937f596e26d8..f048706e2e6e780fde2cd33b722d41d4f5929e52 100644 (file)
@@ -36,3 +36,12 @@ let to_marketing_name = function
 let to_features = function
        | Free -> all_features
 
+let edition_to_int = function
+       | Free | _ -> 0
+
+let equal e0 e1 =
+       edition_to_int e0 = edition_to_int e1
+       
+let min l =
+       Free
+
index 5baea405eb76b0907b93f08ae93d8d40070994be..c2106732883e1864f8afa7cce73c5d551e252b7c 100644 (file)
@@ -19,7 +19,7 @@
 type edition =
        | Free (** Default Edition *)
 
-(** Raised by {!edition_of_string} if the given string does not map to an edition. *)
+(** Raised by {!of_string} if the given string does not map to an edition. *)
 exception Undefined_edition of string
 
 (** Convert a string to an {!edition}. *)
@@ -37,3 +37,9 @@ val to_marketing_name : edition -> string
 (** Get the list of {!feature}s enabled for a given {!edition}. *)
 val to_features : edition -> Features.feature list
 
+(** Compare two editions for equality (used before pool join). *)
+val equal : edition -> edition -> bool
+
+(** Return the "least capable" edition (used to determine the pool edition). *)
+val min : edition list -> edition
+
index f28cf45c0679ccc480ceba77dd442ba7a7a89d69..1e6a8323293c7acd40e96bb8deb00160074fd1a8 100644 (file)
@@ -61,23 +61,13 @@ let pre_join_checks ~__context ~rpc ~session_id ~force =
        let assert_restrictions_match () =
                let host_records = List.map snd (Client.Host.get_all_records ~rpc ~session_id) in
                (* check pool edition *)
-               let pool_editions = List.map (fun host_r -> host_r.API.host_edition) host_records in
-               let edition_to_int = function
-               | "platinum" -> 2
-               | "enterprise" | "enterprise-xd" -> 1
-               | "free" | _ -> 0
-               in
-               let int_to_edition = function
-               | 2 -> "platinum"
-               | 1 -> "enterprise"
-               | 0 | _ -> "free"
-               in
-               let pool_edition = List.fold_left (fun m e -> min m (edition_to_int e)) 2 pool_editions in
-               let my_edition = edition_to_int (Db.Host.get_edition ~__context ~self:(Helpers.get_localhost ~__context)) in
-               if pool_edition <> my_edition then begin
+               let pool_editions = List.map (fun host_r -> Edition.of_string host_r.API.host_edition) host_records in
+               let pool_edition = Edition.min pool_editions in
+               let my_edition = Edition.of_string (Db.Host.get_edition ~__context ~self:(Helpers.get_localhost ~__context)) in
+               if not (Edition.equal pool_edition my_edition) then begin
                        error "Pool.join failed because of editions mismatch";
-                       error "Remote has %s" (int_to_edition pool_edition);
-                       error "Local has  %s" (int_to_edition my_edition);
+                       error "Remote has %s" (Edition.to_string pool_edition);
+                       error "Local has  %s" (Edition.to_string my_edition);
                        raise (Api_errors.Server_error(Api_errors.license_restriction, []))
                end
        in