Skip to content

Commit e26e177

Browse files
committed
CP-54332 Update host/pool datamodel to support SSH auto mode
Add new host object fields: - ssh_auto_mode Add new host/pool API to enable to set auto mode - set_ssh_auto_mode Signed-off-by: Lunfan Zhang <[email protected]>
1 parent 779f8f7 commit e26e177

13 files changed

+71
-4
lines changed

ocaml/idl/datamodel_common.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ open Datamodel_roles
1010
to leave a gap for potential hotfixes needing to increment the schema version.*)
1111
let schema_major_vsn = 5
1212

13-
let schema_minor_vsn = 788
13+
let schema_minor_vsn = 789
1414

1515
(* Historical schema versions just in case this is useful later *)
1616
let rio_schema_major_vsn = 5

ocaml/idl/datamodel_errors.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,6 +2046,9 @@ let _ =
20462046
error Api_errors.set_console_timeout_partially_failed ["hosts"]
20472047
~doc:"Some hosts failed to set console timeout." () ;
20482048

2049+
error Api_errors.set_ssh_auto_mode_partially_failed ["hosts"]
2050+
~doc:"Some hosts failed to set SSH auto mode." () ;
2051+
20492052
error Api_errors.host_driver_no_hardware ["driver variant"]
20502053
~doc:"No hardware present for this host driver variant" () ;
20512054

@@ -2055,6 +2058,12 @@ let _ =
20552058
enable it in XC or run xe pool-enable-tls-verification instead."
20562059
() ;
20572060

2061+
error Api_errors.ssh_auto_mode_conflict []
2062+
~doc:
2063+
"Cannot enable SSH auto mode while SSH is already enabled, as it \
2064+
conflicts with the current SSH configuration."
2065+
() ;
2066+
20582067
message
20592068
(fst Api_messages.ha_pool_overcommitted)
20602069
~doc:

ocaml/idl/datamodel_host.ml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,6 +2440,16 @@ let set_console_idle_timeout =
24402440
]
24412441
~allowed_roles:_R_POOL_ADMIN ()
24422442

2443+
let set_ssh_auto_mode =
2444+
call ~name:"set_ssh_auto_mode" ~lifecycle:[]
2445+
~doc:"Set the SSH auto mode for the host"
2446+
~params:
2447+
[
2448+
(Ref _host, "self", "The host")
2449+
; (Bool, "value", "The SSH auto mode for the host")
2450+
]
2451+
~allowed_roles:_R_POOL_ADMIN ()
2452+
24432453
let latest_synced_updates_applied_state =
24442454
Enum
24452455
( "latest_synced_updates_applied_state"
@@ -2601,6 +2611,7 @@ let t =
26012611
; disable_ssh
26022612
; set_ssh_enabled_timeout
26032613
; set_console_idle_timeout
2614+
; set_ssh_auto_mode
26042615
]
26052616
~contents:
26062617
([
@@ -3056,6 +3067,10 @@ let t =
30563067
"console_idle_timeout"
30573068
"The timeout in seconds after which idle console will be \
30583069
automatically terminated (0 means never)"
3070+
; field ~qualifier:DynamicRO ~lifecycle:[] ~ty:Bool
3071+
~default_value:(Some (VBool Constants.default_ssh_auto_mode))
3072+
"ssh_auto_mode"
3073+
"Reflects whether SSH auto mode is enabled for the host"
30593074
]
30603075
)
30613076
()

ocaml/idl/datamodel_pool.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,16 @@ let set_console_idle_timeout =
16061606
]
16071607
~allowed_roles:_R_POOL_ADMIN ()
16081608

1609+
let set_ssh_auto_mode =
1610+
call ~name:"set_ssh_auto_mode" ~lifecycle:[]
1611+
~doc:"Set the SSH auto mode for all hosts in the pool"
1612+
~params:
1613+
[
1614+
(Ref _pool, "self", "The pool")
1615+
; (Bool, "value", "The SSH auto mode for all hosts in the pool")
1616+
]
1617+
~allowed_roles:_R_POOL_ADMIN ()
1618+
16091619
(** A pool class *)
16101620
let t =
16111621
create_obj ~in_db:true
@@ -1704,6 +1714,7 @@ let t =
17041714
; disable_ssh
17051715
; set_ssh_enabled_timeout
17061716
; set_console_idle_timeout
1717+
; set_ssh_auto_mode
17071718
]
17081719
~contents:
17091720
([

ocaml/idl/schematest.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ let hash x = Digest.string x |> Digest.to_hex
33
(* BEWARE: if this changes, check that schema has been bumped accordingly in
44
ocaml/idl/datamodel_common.ml, usually schema_minor_vsn *)
55

6-
let last_known_schema_hash = "8bf2b9ab509301baf138820cf34608d3"
6+
let last_known_schema_hash = "7c52d11789dea3ab3167c5d0e3e7fa89"
77

88
let current_schema_hash : string =
99
let open Datamodel_types in

ocaml/tests/common/test_common.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ let make_host2 ~__context ?(ref = Ref.make ()) ?(uuid = make_uuid ())
219219
~recommended_guidances:[] ~latest_synced_updates_applied:`unknown
220220
~pending_guidances_recommended:[] ~pending_guidances_full:[]
221221
~last_update_hash:"" ~ssh_enabled:true ~ssh_enabled_timeout:0L
222-
~ssh_expiry:Date.epoch ~console_idle_timeout:0L ;
222+
~ssh_expiry:Date.epoch ~console_idle_timeout:0L ~ssh_auto_mode:true ;
223223
ref
224224

225225
let make_pif ~__context ~network ~host ?(device = "eth0")

ocaml/xapi-consts/api_errors.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,12 @@ let set_ssh_timeout_partially_failed =
14261426
let set_console_timeout_partially_failed =
14271427
add_error "SET_CONSOLE_TIMEOUT_PARTIALLY_FAILED"
14281428

1429+
let set_ssh_auto_mode_partially_failed =
1430+
add_error "SET_SSH_AUTO_MODE_PARTIALLY_FAILED"
1431+
14291432
let host_driver_no_hardware = add_error "HOST_DRIVER_NO_HARDWARE"
14301433

14311434
let tls_verification_not_enabled_in_pool =
14321435
add_error "TLS_VERIFICATION_NOT_ENABLED_IN_POOL"
1436+
1437+
let ssh_auto_mode_conflict = add_error "SSH_AUTO_MODE_CONFLICT"

ocaml/xapi-consts/constants.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,3 +428,5 @@ let default_ssh_enabled = true
428428
let default_ssh_enabled_timeout = 0L
429429

430430
let default_console_idle_timeout = 0L
431+
432+
let default_ssh_auto_mode = true

ocaml/xapi/message_forwarding.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,12 @@ functor
11971197
(pool_uuid ~__context self)
11981198
value ;
11991199
Local.Pool.set_console_idle_timeout ~__context ~self ~value
1200+
1201+
let set_ssh_auto_mode ~__context ~self ~value =
1202+
info "Pool.set_ssh_auto_mode: pool='%s' value='%b'"
1203+
(pool_uuid ~__context self)
1204+
value ;
1205+
Local.Pool.set_ssh_auto_mode ~__context ~self ~value
12001206
end
12011207

12021208
module VM = struct
@@ -4063,6 +4069,14 @@ functor
40634069
let local_fn = Local.Host.set_console_idle_timeout ~self ~value in
40644070
let remote_fn = Client.Host.set_console_idle_timeout ~self ~value in
40654071
do_op_on ~local_fn ~__context ~host:self ~remote_fn
4072+
4073+
let set_ssh_auto_mode ~__context ~self ~value =
4074+
info "Host.set_ssh_auto_mode: host='%s' value='%b'"
4075+
(host_uuid ~__context self)
4076+
value ;
4077+
let local_fn = Local.Host.set_ssh_auto_mode ~self ~value in
4078+
let remote_fn = Client.Host.set_ssh_auto_mode ~self ~value in
4079+
do_op_on ~local_fn ~__context ~host:self ~remote_fn
40664080
end
40674081

40684082
module Host_crashdump = struct

ocaml/xapi/xapi_host.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,8 @@ let create ~__context ~uuid ~name_label ~name_description:_ ~hostname ~address
10441044
~tls_verification_enabled ~last_software_update ~last_update_hash
10451045
~recommended_guidances:[] ~latest_synced_updates_applied:`unknown
10461046
~pending_guidances_recommended:[] ~pending_guidances_full:[] ~ssh_enabled
1047-
~ssh_enabled_timeout ~ssh_expiry ~console_idle_timeout ;
1047+
~ssh_enabled_timeout ~ssh_expiry ~console_idle_timeout
1048+
~ssh_auto_mode:Constants.default_ssh_auto_mode ;
10481049
(* If the host we're creating is us, make sure its set to live *)
10491050
Db.Host_metrics.set_last_updated ~__context ~self:metrics ~value:(Date.now ()) ;
10501051
Db.Host_metrics.set_live ~__context ~self:metrics ~value:host_is_us ;
@@ -3243,3 +3244,5 @@ let set_console_idle_timeout ~__context ~self ~value =
32433244
error "Failed to configure console timeout: %s" (Printexc.to_string e) ;
32443245
Helpers.internal_error "Failed to set console timeout: %Ld: %s" value
32453246
(Printexc.to_string e)
3247+
3248+
let set_ssh_auto_mode ~__context ~self:_ ~value:_ = ()

0 commit comments

Comments
 (0)