Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLEARWATER: Second wave of commits for PR-1589 #1131

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion ocaml/license/license_init.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@
module D = Debug.Debugger(struct let name="license" end)
open D

let v6_initialise ~__context ~edition ~params =
try
V6client.apply_edition ~__context edition params
with Api_errors.Server_error (code, []) when code = Api_errors.v6d_failure ->
(* Couldn't communicate with v6d, so fall back to running in free mode,
* with all standard features enabled and no additional features advertised. *)
"free", Features.all_features, []

(* xapi calls this function upon startup *)
let initialise ~__context ~host =
try
let edition = Db.Host.get_edition ~__context ~self:host in
let edition', features, additional =
V6client.apply_edition ~__context edition ["startup", "true"] in
v6_initialise ~__context ~edition ~params:["startup", "true"] in
Db.Host.set_edition ~__context ~self:host ~value:edition';
(* Copy resulting license to the database *)
Xapi_host.copy_license_to_db ~__context ~host ~features ~additional
Expand Down
11 changes: 11 additions & 0 deletions ocaml/license/v6client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
module D=Debug.Debugger(struct let name="v6client" end)
open D

open Listext

exception V6DaemonFailure

let retry = ref true
Expand All @@ -26,10 +28,19 @@ let v6rpc call =
XMLRPC_protocol.rpc ~srcstr:"xapi" ~dststr:"v6d" ~transport:(Unix socket) ~http:(xmlrpc ~version:"1.0" "/") call

let rec apply_edition ~__context edition additional =
(* Get localhost's current license state. *)
let host = Helpers.get_localhost ~__context in
let license_server = Db.Host.get_license_server ~__context ~self: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 in
(* Make sure the socket count in license_params is correct.
* At first boot, the key won't exist, and it may be wrong if we've restored
* a database dump from a different host. *)
let cpu_info = Db.Host.get_cpu_info ~__context ~self:host in
let socket_count = List.assoc "socket_count" cpu_info in
let current_license_params =
List.replace_assoc "sockets" socket_count current_license_params in
(* Construct the RPC params to be sent to v6d *)
let additional = ("current_edition", current_edition) ::
license_server @ current_license_params @ additional in
let params = [ Rpc.rpc_of_string (Context.string_of_task __context)
Expand Down
12 changes: 10 additions & 2 deletions ocaml/xapi/create_misc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,17 @@ let make_packs_info () =
let make_software_version () =
let option_to_list k o = match o with None -> [] | Some x -> [ k, x ] in
let info = read_localhost_info () in
let v6_version = V6client.get_version "make_software_version" in
let v6_version =
(* Best-effort attempt to read the date-based version from v6d *)
try
match V6client.get_version "make_software_version" with
| "" -> []
| dbv -> ["dbv", dbv]
with Api_errors.Server_error (code, []) when code = Api_errors.v6d_failure ->
[]
in
Xapi_globs.software_version @
(if v6_version = "" then [] else ["dbv", v6_version]) @
v6_version @
[
"xapi", get_xapi_verstring ();
"xen", info.xen_verstring;
Expand Down
5 changes: 1 addition & 4 deletions ocaml/xapi/xapi_host.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1234,11 +1234,8 @@ let apply_edition ~__context ~host ~edition =
if Db.Pool.get_ha_enabled ~__context ~self:pool then
raise (Api_errors.Server_error (Api_errors.ha_is_enabled, []))
else begin
let cpu_info = Db.Host.get_cpu_info ~__context ~self:host in
let socket_count = List.assoc "socket_count" cpu_info in
let edition', features, additional =
V6client.apply_edition ~__context edition
["sockets", socket_count]
V6client.apply_edition ~__context edition []
in
Db.Host.set_edition ~__context ~self:host ~value:edition';
copy_license_to_db ~__context ~host ~features ~additional
Expand Down
55 changes: 20 additions & 35 deletions ocaml/xapi/xapi_vm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,7 @@ let pause ~__context ~vm =
Xapi_xenops.pause ~__context ~self:vm

let unpause ~__context ~vm =
License_check.with_vm_license_check ~__context vm
(fun () ->
Xapi_xenops.unpause ~__context ~self:vm
)
Xapi_xenops.unpause ~__context ~self:vm

let set_xenstore_data ~__context ~self ~value =
Xapi_xenops.set_xenstore_data ~__context ~self value
Expand All @@ -194,18 +191,15 @@ let set_xenstore_data ~__context ~self ~value =
*)

let start ~__context ~vm ~start_paused ~force =
License_check.with_vm_license_check ~__context vm
(fun () ->
let vmr = Db.VM.get_record ~__context ~self:vm in
Vgpuops.create_vgpus ~__context (vm, vmr) (Helpers.will_boot_hvm ~__context ~self:vm);

if vmr.API.vM_ha_restart_priority = Constants.ha_restart
then begin
Xapi_ha_vm_failover.assert_new_vm_preserves_ha_plan ~__context vm;
Db.VM.set_ha_always_run ~__context ~self:vm ~value:true
end;
Xapi_xenops.start ~__context ~self:vm start_paused
)
let vmr = Db.VM.get_record ~__context ~self:vm in
Vgpuops.create_vgpus ~__context (vm, vmr) (Helpers.will_boot_hvm ~__context ~self:vm);

if vmr.API.vM_ha_restart_priority = Constants.ha_restart
then begin
Xapi_ha_vm_failover.assert_new_vm_preserves_ha_plan ~__context vm;
Db.VM.set_ha_always_run ~__context ~self:vm ~value:true
end;
Xapi_xenops.start ~__context ~self:vm start_paused

(** For VM.start_on and VM.resume_on the message forwarding layer should only forward here
if 'host' = localhost *)
Expand All @@ -224,10 +218,7 @@ let start_on ~__context ~vm ~host ~start_paused ~force =
start ~__context ~vm ~start_paused ~force

let hard_reboot ~__context ~vm =
License_check.with_vm_license_check ~__context vm
(fun () ->
Xapi_xenops.reboot ~__context ~self:vm None
)
Xapi_xenops.reboot ~__context ~self:vm None

let hard_shutdown ~__context ~vm =
Db.VM.set_ha_always_run ~__context ~self:vm ~value:false;
Expand All @@ -246,10 +237,7 @@ let hard_shutdown ~__context ~vm =
Xapi_xenops.shutdown ~__context ~self:vm None

let clean_reboot ~__context ~vm =
License_check.with_vm_license_check ~__context vm
(fun () ->
Xapi_xenops.reboot ~__context ~self:vm (Some 1200.0)
)
Xapi_xenops.reboot ~__context ~self:vm (Some 1200.0)

let clean_shutdown ~__context ~vm =
Db.VM.set_ha_always_run ~__context ~self:vm ~value:false;
Expand Down Expand Up @@ -316,19 +304,16 @@ let suspend ~__context ~vm =
Xapi_xenops.suspend ~__context ~self:vm

let resume ~__context ~vm ~start_paused ~force =
License_check.with_vm_license_check ~__context vm
(fun () ->
if Db.VM.get_ha_restart_priority ~__context ~self:vm = Constants.ha_restart
then begin
Xapi_ha_vm_failover.assert_new_vm_preserves_ha_plan ~__context vm;
Db.VM.set_ha_always_run ~__context ~self:vm ~value:true
end;
if Db.VM.get_ha_restart_priority ~__context ~self:vm = Constants.ha_restart
then begin
Xapi_ha_vm_failover.assert_new_vm_preserves_ha_plan ~__context vm;
Db.VM.set_ha_always_run ~__context ~self:vm ~value:true
end;

let host = Helpers.get_localhost ~__context in
if not force then Cpuid_helpers.assert_vm_is_compatible ~__context ~vm ~host ();
let host = Helpers.get_localhost ~__context in
if not force then Cpuid_helpers.assert_vm_is_compatible ~__context ~vm ~host ();

Xapi_xenops.resume ~__context ~self:vm ~start_paused ~force
)
Xapi_xenops.resume ~__context ~self:vm ~start_paused ~force

let resume_on ~__context ~vm ~host ~start_paused ~force =
(* If we modify this to support resume_on other-than-localhost,
Expand Down