Skip to content

Commit 4f61269

Browse files
committed
CP-53721 Implement SSH set auto mode API for Dom0 SSH control
Implemented XAPI APIs for SSH auto mode configuration: - `host.set_ssh_auto_mode`: Configures SSH auto mode for a specific host. - `pool.set_ssh_auto_mode`: Configures SSH auto mode for all hosts in the pool. Additionally: - `host.enable_ssh` now automatically sets SSH auto mode to `false`. Signed-off-by: Lunfan Zhang <[email protected]>
1 parent d64fd12 commit 4f61269

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

ocaml/xapi/xapi_globs.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,8 @@ let job_for_disable_ssh = ref "Disable SSH"
12971297

12981298
let ssh_service = ref "sshd"
12991299

1300+
let ssh_monitor_service = ref "xapi-ssh-monitor"
1301+
13001302
(* Fingerprint of default patch key *)
13011303
let citrix_patch_key =
13021304
"NERDNTUzMDMwRUMwNDFFNDI4N0M4OEVCRUFEMzlGOTJEOEE5REUyNg=="

ocaml/xapi/xapi_host.ml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3158,6 +3158,33 @@ let schedule_disable_ssh_job ~__context ~self ~timeout =
31583158

31593159
Db.Host.set_ssh_expiry ~__context ~self ~value:expiry_time
31603160

3161+
let set_ssh_auto_mode ~__context ~self ~value =
3162+
debug "Setting SSH auto mode for host %s to %B"
3163+
(Helpers.get_localhost_uuid ())
3164+
value ;
3165+
3166+
if value && Db.Host.get_ssh_enabled ~__context ~self then
3167+
raise (Api_errors.Server_error (Api_errors.ssh_auto_mode_conflict, [])) ;
3168+
3169+
Db.Host.set_ssh_auto_mode ~__context ~self ~value ;
3170+
3171+
try
3172+
if value then (
3173+
Xapi_systemctl.enable ~wait_until_success:false
3174+
!Xapi_globs.ssh_monitor_service ;
3175+
Xapi_systemctl.start ~wait_until_success:false
3176+
!Xapi_globs.ssh_monitor_service
3177+
) else (
3178+
Xapi_systemctl.stop ~wait_until_success:false
3179+
!Xapi_globs.ssh_monitor_service ;
3180+
Xapi_systemctl.disable ~wait_until_success:false
3181+
!Xapi_globs.ssh_monitor_service
3182+
)
3183+
with e ->
3184+
error "Failed to configure SSH auto mode: %s" (Printexc.to_string e) ;
3185+
Helpers.internal_error "Failed to configure SSH auto mode: %s"
3186+
(Printexc.to_string e)
3187+
31613188
let enable_ssh ~__context ~self =
31623189
try
31633190
debug "Enabling SSH for host %s" (Helpers.get_localhost_uuid ()) ;
@@ -3174,7 +3201,9 @@ let enable_ssh ~__context ~self =
31743201
schedule_disable_ssh_job ~__context ~self ~timeout:t
31753202
) ;
31763203

3177-
Db.Host.set_ssh_enabled ~__context ~self ~value:true
3204+
Db.Host.set_ssh_enabled ~__context ~self ~value:true ;
3205+
(* Disable SSH auto mode when SSH is enabled manually *)
3206+
set_ssh_auto_mode ~__context ~self ~value:false
31783207
with e ->
31793208
error "Failed to enable SSH on host %s: %s" (Ref.string_of self)
31803209
(Printexc.to_string e) ;
@@ -3244,5 +3273,3 @@ let set_console_idle_timeout ~__context ~self ~value =
32443273
error "Failed to configure console timeout: %s" (Printexc.to_string e) ;
32453274
Helpers.internal_error "Failed to set console timeout: %Ld: %s" value
32463275
(Printexc.to_string e)
3247-
3248-
let set_ssh_auto_mode ~__context ~self:_ ~value:_ = ()

ocaml/xapi/xapi_pool.ml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4070,6 +4070,13 @@ module Ssh = struct
40704070
Client.Host.set_console_idle_timeout ~rpc ~session_id ~self ~value
40714071
)
40724072
~error:Api_errors.set_console_timeout_partially_failed
4073+
4074+
let set_ssh_auto_mode ~__context ~self:_ ~value =
4075+
operate ~__context
4076+
~action:(fun ~rpc ~session_id ~self ->
4077+
Client.Host.set_ssh_auto_mode ~rpc ~session_id ~self ~value
4078+
)
4079+
~error:Api_errors.set_ssh_auto_mode_partially_failed
40734080
end
40744081

40754082
let enable_ssh = Ssh.enable
@@ -4080,4 +4087,4 @@ let set_ssh_enabled_timeout = Ssh.set_enabled_timeout
40804087

40814088
let set_console_idle_timeout = Ssh.set_console_timeout
40824089

4083-
let set_ssh_auto_mode ~__context ~self:_ ~value:_ = ()
4090+
let set_ssh_auto_mode = Ssh.set_ssh_auto_mode

0 commit comments

Comments
 (0)