Skip to content

Commit 209630b

Browse files
committed
CP-53723 Implement Console timeout configure API for Dom0 SSH control
Implemented XAPI APIs: - `host.set_console_idle_timeout` - `pool.set_console_idle_timeout` These APIs allow XAPI to configure timeout for idle console sessions. Signed-off-by: Lunfan Zhang <[email protected]>
1 parent 2f00a21 commit 209630b

File tree

5 files changed

+49
-2
lines changed

5 files changed

+49
-2
lines changed

ocaml/idl/datamodel_errors.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,6 +2040,9 @@ let _ =
20402040
error Api_errors.disable_ssh_partially_failed ["hosts"]
20412041
~doc:"Some of hosts failed to disable SSH access." () ;
20422042

2043+
error Api_errors.set_console_timeout_partially_failed ["hosts"]
2044+
~doc:"Some hosts failed to set console timeout." () ;
2045+
20432046
error Api_errors.host_driver_no_hardware ["driver variant"]
20442047
~doc:"No hardware present for this host driver variant" () ;
20452048

ocaml/xapi-consts/api_errors.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,9 @@ let enable_ssh_partially_failed = add_error "ENABLE_SSH_PARTIALLY_FAILED"
14201420

14211421
let disable_ssh_partially_failed = add_error "DISABLE_SSH_PARTIALLY_FAILED"
14221422

1423+
let set_console_timeout_partially_failed =
1424+
add_error "SET_CONSOLE_TIMEOUT_PARTIALLY_FAILED"
1425+
14231426
let host_driver_no_hardware = add_error "HOST_DRIVER_NO_HARDWARE"
14241427

14251428
let tls_verification_not_enabled_in_pool =

ocaml/xapi/xapi_globs.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,8 @@ let gpumon_stop_timeout = ref 10.0
12871287

12881288
let reboot_required_hfxs = ref "/run/reboot-required.hfxs"
12891289

1290+
let console_timeout_profile_path = ref "/etc/profile.d/xapi-console-timeout.sh"
1291+
12901292
(* Fingerprint of default patch key *)
12911293
let citrix_patch_key =
12921294
"NERDNTUzMDMwRUMwNDFFNDI4N0M4OEVCRUFEMzlGOTJEOEE5REUyNg=="

ocaml/xapi/xapi_host.ml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3136,4 +3136,36 @@ let disable_ssh ~__context ~self =
31363136

31373137
let set_ssh_enabled_timeout ~__context ~self:_ ~value:_ = ()
31383138

3139-
let set_console_idle_timeout ~__context ~self:_ ~value:_ = ()
3139+
let set_console_idle_timeout ~__context ~self ~value =
3140+
let assert_timeout_valid timeout =
3141+
if timeout < 0L then
3142+
raise
3143+
(Api_errors.Server_error
3144+
( Api_errors.invalid_value
3145+
, ["console_timeout"; Int64.to_string timeout]
3146+
)
3147+
)
3148+
in
3149+
3150+
assert_timeout_valid value ;
3151+
try
3152+
let content =
3153+
match value with
3154+
| 0L ->
3155+
"# Console timeout is disabled\n"
3156+
| timeout ->
3157+
Printf.sprintf "# Console timeout configuration\nexport TMOUT=%Ld\n"
3158+
timeout
3159+
in
3160+
3161+
Unixext.atomic_write_to_file !Xapi_globs.console_timeout_profile_path 0o0644
3162+
(fun fd ->
3163+
Unix.write fd (Bytes.of_string content) 0 (String.length content)
3164+
|> ignore
3165+
) ;
3166+
3167+
Db.Host.set_console_idle_timeout ~__context ~self ~value
3168+
with e ->
3169+
error "Failed to configure console timeout: %s" (Printexc.to_string e) ;
3170+
Helpers.internal_error "Failed to set console timeout: %Ld: %s" value
3171+
(Printexc.to_string e)

ocaml/xapi/xapi_pool.ml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4003,6 +4003,13 @@ module Ssh = struct
40034003
let disable ~__context ~self:_ =
40044004
operate ~__context ~action:Client.Host.disable_ssh
40054005
~error:Api_errors.disable_ssh_partially_failed
4006+
4007+
let set_console_timeout ~__context ~self:_ ~value =
4008+
operate ~__context
4009+
~action:(fun ~rpc ~session_id ~self ->
4010+
Client.Host.set_console_idle_timeout ~rpc ~session_id ~self ~value
4011+
)
4012+
~error:Api_errors.set_console_timeout_partially_failed
40064013
end
40074014

40084015
let enable_ssh = Ssh.enable
@@ -4011,4 +4018,4 @@ let disable_ssh = Ssh.disable
40114018

40124019
let set_ssh_enabled_timeout ~__context ~self:_ ~value:_ = ()
40134020

4014-
let set_console_idle_timeout ~__context ~self:_ ~value:_ = ()
4021+
let set_console_idle_timeout = Ssh.set_console_timeout

0 commit comments

Comments
 (0)