Skip to content

Commit

Permalink
Merge pool licensing feature (#6277)
Browse files Browse the repository at this point in the history
  • Loading branch information
minglumlu authored Feb 6, 2025
2 parents 073373f + 10bb483 commit 7cc6ea9
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ocaml/idl/datamodel_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ open Datamodel_roles
to leave a gap for potential hotfixes needing to increment the schema version.*)
let schema_major_vsn = 5

let schema_minor_vsn = 785
let schema_minor_vsn = 786

(* Historical schema versions just in case this is useful later *)
let rio_schema_major_vsn = 5
Expand Down
2 changes: 2 additions & 0 deletions ocaml/idl/datamodel_lifecycle.ml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ let prototyped_of_field = function
Some "23.18.0"
| "VM", "actions__after_softreboot" ->
Some "23.1.0"
| "pool", "license_server" ->
Some "25.5.0-next"
| "pool", "recommendations" ->
Some "24.19.1"
| "pool", "update_sync_enabled" ->
Expand Down
4 changes: 4 additions & 0 deletions ocaml/idl/datamodel_pool.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2153,6 +2153,10 @@ let t =
~default_value:(Some (VMap [])) "recommendations"
"The recommended pool properties for clients to respect for \
optimal performance. e.g. max-vm-group=5"
; field ~writer_roles:_R_POOL_OP ~qualifier:RW ~lifecycle:[]
~ty:(Map (String, String))
~default_value:(Some (VMap [])) "license_server"
"Licensing data shared within the whole pool"
]
)
()
2 changes: 1 addition & 1 deletion ocaml/idl/schematest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ let hash x = Digest.string x |> Digest.to_hex
(* BEWARE: if this changes, check that schema has been bumped accordingly in
ocaml/idl/datamodel_common.ml, usually schema_minor_vsn *)

let last_known_schema_hash = "458f20f5270a5615c7ee92be8a383172"
let last_known_schema_hash = "6f6230f87a92572b68ebd742196ffd0e"

let current_schema_hash : string =
let open Datamodel_types in
Expand Down
4 changes: 2 additions & 2 deletions ocaml/tests/common/test_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ let make_pool ~__context ~master ?(name_label = "") ?(name_description = "")
?(telemetry_next_collection = API.Date.epoch)
?(last_update_sync = API.Date.epoch) ?(update_sync_frequency = `daily)
?(update_sync_day = 0L) ?(update_sync_enabled = false)
?(recommendations = []) () =
?(recommendations = []) ?(license_server = []) () =
let pool_ref = Ref.make () in
Db.Pool.create ~__context ~ref:pool_ref ~uuid:(make_uuid ()) ~name_label
~name_description ~master ~default_SR ~suspend_image_SR ~crash_dump_SR
Expand All @@ -320,7 +320,7 @@ let make_pool ~__context ~master ?(name_label = "") ?(name_description = "")
~local_auth_max_threads:8L ~ext_auth_max_threads:8L
~ext_auth_cache_enabled:false ~ext_auth_cache_size:50L
~ext_auth_cache_expiry:300L ~update_sync_frequency ~update_sync_day
~update_sync_enabled ~recommendations ;
~update_sync_enabled ~recommendations ~license_server ;
pool_ref

let default_sm_features =
Expand Down
12 changes: 12 additions & 0 deletions ocaml/xapi-cli-server/records.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,18 @@ let pool_record rpc session_id pool =
~value:(Int64.of_string v)
)
()
; make_field ~name:"license-server"
~get:(fun () -> get_from_map (x ()).API.pool_license_server)
~add_to_map:(fun key value ->
Client.Pool.add_to_license_server ~rpc ~session_id ~self:pool ~key
~value
)
~remove_from_map:(fun key ->
Client.Pool.remove_from_license_server ~rpc ~session_id ~self:pool
~key
)
~get_map:(fun () -> (x ()).API.pool_license_server)
()
]
}

Expand Down
1 change: 1 addition & 0 deletions ocaml/xapi/dbsync_master.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ let create_pool_record ~__context =
~update_sync_enabled:false ~local_auth_max_threads:8L
~ext_auth_max_threads:1L ~ext_auth_cache_enabled:false
~ext_auth_cache_size:50L ~ext_auth_cache_expiry:300L ~recommendations:[]
~license_server:[]

let set_master_ip ~__context =
let ip =
Expand Down
14 changes: 13 additions & 1 deletion ocaml/xapi/xapi_host.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2022,9 +2022,21 @@ let set_license_params ~__context ~self ~value =
Db.Host.set_license_params ~__context ~self ~value ;
Pool_features_helpers.update_pool_features ~__context

let collect_license_server_data ~__context ~host =
let pool = Helpers.get_pool ~__context in
let host_license_server = Db.Host.get_license_server ~__context ~self:host in
let pool_license_server = Db.Pool.get_license_server ~__context ~self:pool in
(* If there are same keys both in host and pool, use host level data. *)
let list_assoc_union l1 l2 =
List.fold_left
(fun acc (k, v) -> if List.mem_assoc k l1 then acc else (k, v) :: acc)
l1 l2
in
list_assoc_union host_license_server pool_license_server

let apply_edition_internal ~__context ~host ~edition ~additional =
(* Get localhost's current license state. *)
let license_server = Db.Host.get_license_server ~__context ~self:host in
let license_server = collect_license_server_data ~__context ~host in
let current_edition = Db.Host.get_edition ~__context ~self:host in
let current_license_params =
Db.Host.get_license_params ~__context ~self:host
Expand Down

0 comments on commit 7cc6ea9

Please # to comment.