Skip to content

Commit 741b7a0

Browse files
committed
CP-53802: Restore SSH service to default state in pool eject
After being ejected from a pool, a new host obj will be created with default settings in DB. This commit configures SSH service in the ejected host to default state during pool eject. Signed-off-by: Gang Ji <[email protected]>
1 parent 49f8128 commit 741b7a0

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

ocaml/idl/datamodel_host.ml

+10-8
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,7 @@ let create_params =
13051305
; param_name= "ssh_enabled"
13061306
; param_doc= "True if SSH access is enabled for the host"
13071307
; param_release= numbered_release "25.14.0-next"
1308-
; param_default= Some (VBool true)
1308+
; param_default= Some (VBool Constants.default_ssh_enabled)
13091309
}
13101310
; {
13111311
param_type= Int
@@ -1315,7 +1315,7 @@ let create_params =
13151315
disabled (0 means never), this setting will be applied every time the \
13161316
SSH is enabled by XAPI"
13171317
; param_release= numbered_release "25.14.0-next"
1318-
; param_default= Some (VInt 0L)
1318+
; param_default= Some (VInt Constants.default_ssh_enabled_timeout)
13191319
}
13201320
; {
13211321
param_type= DateTime
@@ -1333,7 +1333,7 @@ let create_params =
13331333
"The timeout in seconds after which idle console will be automatically \
13341334
terminated (0 means never)"
13351335
; param_release= numbered_release "25.14.0-next"
1336-
; param_default= Some (VInt 0L)
1336+
; param_default= Some (VInt Constants.default_console_idle_timeout)
13371337
}
13381338
]
13391339

@@ -2436,7 +2436,7 @@ let set_console_idle_timeout =
24362436
~params:
24372437
[
24382438
(Ref _host, "self", "The host")
2439-
; (Int, "value", "The idle console timeout in seconds")
2439+
; (Int, "value", "The console idle timeout in seconds")
24402440
]
24412441
~allowed_roles:_R_POOL_ADMIN ()
24422442

@@ -3039,10 +3039,11 @@ let t =
30393039
"The SHA256 checksum of updateinfo of the most recently applied \
30403040
update on the host"
30413041
; field ~qualifier:DynamicRO ~lifecycle:[] ~ty:Bool
3042-
~default_value:(Some (VBool true)) "ssh_enabled"
3043-
"True if SSH access is enabled for the host"
3042+
~default_value:(Some (VBool Constants.default_ssh_enabled))
3043+
"ssh_enabled" "True if SSH access is enabled for the host"
30443044
; field ~qualifier:DynamicRO ~lifecycle:[] ~ty:Int
3045-
~default_value:(Some (VInt 0L)) "ssh_enabled_timeout"
3045+
~default_value:(Some (VInt Constants.default_ssh_enabled_timeout))
3046+
"ssh_enabled_timeout"
30463047
"The timeout in seconds after which SSH access will be \
30473048
automatically disabled (0 means never), this setting will be \
30483049
applied every time the SSH is enabled by XAPI"
@@ -3051,7 +3052,8 @@ let t =
30513052
"The time in UTC after which the SSH access will be automatically \
30523053
disabled"
30533054
; field ~qualifier:DynamicRO ~lifecycle:[] ~ty:Int
3054-
~default_value:(Some (VInt 0L)) "console_idle_timeout"
3055+
~default_value:(Some (VInt Constants.default_console_idle_timeout))
3056+
"console_idle_timeout"
30553057
"The timeout in seconds after which idle console will be \
30563058
automatically terminated (0 means never)"
30573059
]

ocaml/xapi-consts/constants.ml

+6
Original file line numberDiff line numberDiff line change
@@ -422,3 +422,9 @@ let observer_components_all =
422422
let tgroups_enabled = ref false
423423

424424
let when_tgroups_enabled f = if !tgroups_enabled then f () else ()
425+
426+
let default_ssh_enabled = true
427+
428+
let default_ssh_enabled_timeout = 0L
429+
430+
let default_console_idle_timeout = 0L

ocaml/xapi/xapi_pool.ml

+17
Original file line numberDiff line numberDiff line change
@@ -2045,6 +2045,23 @@ let eject_self ~__context ~host =
20452045
control_domains_to_destroy
20462046
with _ -> ()
20472047
) ;
2048+
( try
2049+
(* Restore console idle timeout *)
2050+
Xapi_host.set_console_idle_timeout ~__context ~self:host
2051+
~value:Constants.default_console_idle_timeout ;
2052+
(* Restore SSH service to default state *)
2053+
Xapi_host.set_ssh_enabled_timeout ~__context ~self:host
2054+
~value:Constants.default_ssh_enabled_timeout ;
2055+
match Constants.default_ssh_enabled with
2056+
| true ->
2057+
Xapi_host.enable_ssh ~__context ~self:host
2058+
| false ->
2059+
Xapi_host.disable_ssh ~__context ~self:host
2060+
with e ->
2061+
warn "Caught %s while restoring ssh service. Ignoring"
2062+
(Printexc.to_string e)
2063+
) ;
2064+
20482065
debug "Pool.eject: setting our role to be master" ;
20492066
Xapi_pool_transition.set_role Pool_role.Master ;
20502067
debug "Pool.eject: forgetting pool secret" ;

0 commit comments

Comments
 (0)