@@ -3112,18 +3112,43 @@ let emergency_clear_mandatory_guidance ~__context =
3112
3112
) ;
3113
3113
Db.Host. set_pending_guidances ~__context ~self ~value: []
3114
3114
3115
+ let set_ssh_auto_mode ~__context ~self ~value =
3116
+ debug " Setting SSH auto mode for host %s to %B"
3117
+ (Helpers. get_localhost_uuid () )
3118
+ value ;
3119
+
3120
+ Db.Host. set_ssh_auto_mode ~__context ~self ~value ;
3121
+
3122
+ try
3123
+ if value then (
3124
+ Xapi_systemctl. enable ~wait_until_success: false
3125
+ ! Xapi_globs. ssh_monitor_service ;
3126
+ Xapi_systemctl. start ~wait_until_success: false
3127
+ ! Xapi_globs. ssh_monitor_service
3128
+ ) else (
3129
+ Xapi_systemctl. stop ~wait_until_success: false
3130
+ ! Xapi_globs. ssh_monitor_service ;
3131
+ Xapi_systemctl. disable ~wait_until_success: false
3132
+ ! Xapi_globs. ssh_monitor_service
3133
+ )
3134
+ with e ->
3135
+ error " Failed to configure SSH auto mode: %s" (Printexc. to_string e) ;
3136
+ Helpers. internal_error " Failed to configure SSH auto mode: %s"
3137
+ (Printexc. to_string e)
3138
+
3115
3139
let disable_ssh_internal ~__context ~self =
3116
3140
try
3117
3141
debug " Disabling SSH for host %s" (Helpers. get_localhost_uuid () ) ;
3118
- Xapi_systemctl. disable ~wait_until_success: false ! Xapi_globs. ssh_service ;
3142
+ if Db.Host. get_ssh_auto_mode ~__context ~self = false then
3143
+ Xapi_systemctl. disable ~wait_until_success: false ! Xapi_globs. ssh_service ;
3119
3144
Xapi_systemctl. stop ~wait_until_success: false ! Xapi_globs. ssh_service ;
3120
3145
Db.Host. set_ssh_enabled ~__context ~self ~value: false
3121
3146
with e ->
3122
3147
error " Failed to disable SSH for host %s: %s" (Ref. string_of self)
3123
3148
(Printexc. to_string e) ;
3124
3149
Helpers. internal_error " Failed to disable SSH: %s" (Printexc. to_string e)
3125
3150
3126
- let schedule_disable_ssh_job ~__context ~self ~timeout =
3151
+ let schedule_disable_ssh_job ~__context ~self ~timeout ~ auto_mode =
3127
3152
let host_uuid = Helpers. get_localhost_uuid () in
3128
3153
let expiry_time =
3129
3154
match
@@ -3152,7 +3177,11 @@ let schedule_disable_ssh_job ~__context ~self ~timeout =
3152
3177
Xapi_stdext_threads_scheduler.Scheduler. add_to_queue
3153
3178
! Xapi_globs. job_for_disable_ssh
3154
3179
Xapi_stdext_threads_scheduler.Scheduler. OneShot (Int64. to_float timeout)
3155
- (fun () -> disable_ssh_internal ~__context ~self
3180
+ (fun () ->
3181
+ disable_ssh_internal ~__context ~self ;
3182
+ (* re-enable SSH auto mode if it was enabled before calling host.enable_ssh *)
3183
+ if auto_mode then
3184
+ set_ssh_auto_mode ~__context ~self ~value: true
3156
3185
) ;
3157
3186
3158
3187
Db.Host. set_ssh_expiry ~__context ~self ~value: expiry_time
@@ -3161,6 +3190,10 @@ let enable_ssh ~__context ~self =
3161
3190
try
3162
3191
debug " Enabling SSH for host %s" (Helpers. get_localhost_uuid () ) ;
3163
3192
3193
+ let cached_ssh_auto_mode = Db.Host. get_ssh_auto_mode ~__context ~self in
3194
+ (* Disable SSH auto mode when SSH is enabled manually *)
3195
+ set_ssh_auto_mode ~__context ~self ~value: false ;
3196
+
3164
3197
Xapi_systemctl. enable ~wait_until_success: false ! Xapi_globs. ssh_service ;
3165
3198
Xapi_systemctl. start ~wait_until_success: false ! Xapi_globs. ssh_service ;
3166
3199
@@ -3171,6 +3204,7 @@ let enable_ssh ~__context ~self =
3171
3204
! Xapi_globs. job_for_disable_ssh
3172
3205
| t ->
3173
3206
schedule_disable_ssh_job ~__context ~self ~timeout: t
3207
+ ~auto_mode: cached_ssh_auto_mode
3174
3208
) ;
3175
3209
3176
3210
Db.Host. set_ssh_enabled ~__context ~self ~value: true
@@ -3208,7 +3242,7 @@ let set_ssh_enabled_timeout ~__context ~self ~value =
3208
3242
! Xapi_globs. job_for_disable_ssh ;
3209
3243
Db.Host. set_ssh_expiry ~__context ~self ~value: Date. epoch
3210
3244
| t ->
3211
- schedule_disable_ssh_job ~__context ~self ~timeout: t
3245
+ schedule_disable_ssh_job ~__context ~self ~timeout: t ~auto_mode: false
3212
3246
3213
3247
let set_console_idle_timeout ~__context ~self ~value =
3214
3248
let assert_timeout_valid timeout =
@@ -3243,5 +3277,3 @@ let set_console_idle_timeout ~__context ~self ~value =
3243
3277
error " Failed to configure console timeout: %s" (Printexc. to_string e) ;
3244
3278
Helpers. internal_error " Failed to set console timeout: %Ld: %s" value
3245
3279
(Printexc. to_string e)
3246
-
3247
- let set_ssh_auto_mode ~__context ~self :_ ~value :_ = ()
0 commit comments