Skip to content

Commit f1a993e

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 f1a993e

15 files changed

+88
-10
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: 3 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

ocaml/idl/datamodel_host.ml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,13 @@ let create_params =
13351335
; param_release= numbered_release "25.14.0-next"
13361336
; param_default= Some (VInt Constants.default_console_idle_timeout)
13371337
}
1338+
; {
1339+
param_type= Bool
1340+
; param_name= "ssh_auto_mode"
1341+
; param_doc= "True if SSH auto mode is enabled for the host"
1342+
; param_release= numbered_release "25.14.0-next"
1343+
; param_default= Some (VBool Constants.default_ssh_auto_mode)
1344+
}
13381345
]
13391346

13401347
let create =
@@ -1350,8 +1357,8 @@ let create =
13501357
; ( Changed
13511358
, "25.14.0-next"
13521359
, "Added --ssh_enabled --ssh_enabled_timeout --ssh_expiry \
1353-
--console_idle_timeout options to allow them to be configured for \
1354-
new host"
1360+
--console_idle_timeout --ssh_auto_mode options to allow them to be \
1361+
configured for new host"
13551362
)
13561363
]
13571364
~versioned_params:create_params ~doc:"Create a new host record"
@@ -2440,6 +2447,21 @@ let set_console_idle_timeout =
24402447
]
24412448
~allowed_roles:_R_POOL_ADMIN ()
24422449

2450+
let set_ssh_auto_mode =
2451+
call ~name:"set_ssh_auto_mode" ~lifecycle:[]
2452+
~doc:"Set the SSH auto mode for the host"
2453+
~params:
2454+
[
2455+
(Ref _host, "self", "The host")
2456+
; ( Bool
2457+
, "value"
2458+
, "The SSH auto mode for the host,when set to true, SSH to normally be \
2459+
disabled and SSH to be enabled only in case of emergency e.g., xapi \
2460+
is down"
2461+
)
2462+
]
2463+
~allowed_roles:_R_POOL_ADMIN ()
2464+
24432465
let latest_synced_updates_applied_state =
24442466
Enum
24452467
( "latest_synced_updates_applied_state"
@@ -2601,6 +2623,7 @@ let t =
26012623
; disable_ssh
26022624
; set_ssh_enabled_timeout
26032625
; set_console_idle_timeout
2626+
; set_ssh_auto_mode
26042627
]
26052628
~contents:
26062629
([
@@ -3056,6 +3079,10 @@ let t =
30563079
"console_idle_timeout"
30573080
"The timeout in seconds after which idle console will be \
30583081
automatically terminated (0 means never)"
3082+
; field ~qualifier:DynamicRO ~lifecycle:[] ~ty:Bool
3083+
~default_value:(Some (VBool Constants.default_ssh_auto_mode))
3084+
"ssh_auto_mode"
3085+
"Reflects whether SSH auto mode is enabled for the host"
30593086
]
30603087
)
30613088
()

ocaml/idl/datamodel_pool.ml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,21 @@ 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
1616+
, "value"
1617+
, "The SSH auto mode for all hosts in the pool,when set to true, SSH \
1618+
to normally be disabled and SSH to be enabled only in case of \
1619+
emergency e.g., xapi is down"
1620+
)
1621+
]
1622+
~allowed_roles:_R_POOL_ADMIN ()
1623+
16091624
(** A pool class *)
16101625
let t =
16111626
create_obj ~in_db:true
@@ -1704,6 +1719,7 @@ let t =
17041719
; disable_ssh
17051720
; set_ssh_enabled_timeout
17061721
; set_console_idle_timeout
1722+
; set_ssh_auto_mode
17071723
]
17081724
~contents:
17091725
([

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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,14 @@ let make_host ~__context ?(uuid = make_uuid ()) ?(name_label = "host")
172172
?(local_cache_sr = Ref.null) ?(chipset_info = []) ?(ssl_legacy = false)
173173
?(last_software_update = Date.epoch) ?(last_update_hash = "")
174174
?(ssh_enabled = true) ?(ssh_enabled_timeout = 0L) ?(ssh_expiry = Date.epoch)
175-
?(console_idle_timeout = 0L) () =
175+
?(console_idle_timeout = 0L) ?(ssh_auto_mode = false) () =
176176
let host =
177177
Xapi_host.create ~__context ~uuid ~name_label ~name_description ~hostname
178178
~address ~external_auth_type ~external_auth_service_name
179179
~external_auth_configuration ~license_params ~edition ~license_server
180180
~local_cache_sr ~chipset_info ~ssl_legacy ~last_software_update
181181
~last_update_hash ~ssh_enabled ~ssh_enabled_timeout ~ssh_expiry
182-
~console_idle_timeout
182+
~console_idle_timeout ~ssh_auto_mode
183183
in
184184
Db.Host.set_cpu_info ~__context ~self:host ~value:default_cpu_info ;
185185
host
@@ -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:false ;
223223
ref
224224

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

ocaml/tests/test_host.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ let add_host __context name =
2525
~local_cache_sr:Ref.null ~chipset_info:[] ~ssl_legacy:false
2626
~last_software_update:Clock.Date.epoch ~last_update_hash:""
2727
~ssh_enabled:true ~ssh_enabled_timeout:0L ~ssh_expiry:Clock.Date.epoch
28-
~console_idle_timeout:0L
28+
~console_idle_timeout:0L ~ssh_auto_mode:false
2929
)
3030

3131
(* Creates an unlicensed pool with the maximum number of hosts *)

ocaml/xapi-consts/api_errors.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,9 @@ 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 =

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 = false

ocaml/xapi/dbsync_slave.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ let create_localhost ~__context info =
6464
~ssh_enabled_timeout:Constants.default_ssh_enabled_timeout
6565
~ssh_expiry:Date.epoch
6666
~console_idle_timeout:Constants.default_console_idle_timeout
67+
~ssh_auto_mode:Constants.default_ssh_auto_mode
6768
in
6869
()
6970

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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ let create ~__context ~uuid ~name_label ~name_description:_ ~hostname ~address
979979
~external_auth_type ~external_auth_service_name ~external_auth_configuration
980980
~license_params ~edition ~license_server ~local_cache_sr ~chipset_info
981981
~ssl_legacy:_ ~last_software_update ~last_update_hash ~ssh_enabled
982-
~ssh_enabled_timeout ~ssh_expiry ~console_idle_timeout =
982+
~ssh_enabled_timeout ~ssh_expiry ~console_idle_timeout ~ssh_auto_mode =
983983
(* fail-safe. We already test this on the joining host, but it's racy, so multiple concurrent
984984
pool-join might succeed. Note: we do it in this order to avoid a problem checking restrictions during
985985
the initial setup of the database *)
@@ -1044,7 +1044,7 @@ 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 ~ssh_auto_mode ;
10481048
(* If the host we're creating is us, make sure its set to live *)
10491049
Db.Host_metrics.set_last_updated ~__context ~self:metrics ~value:(Date.now ()) ;
10501050
Db.Host_metrics.set_live ~__context ~self:metrics ~value:host_is_us ;
@@ -3243,3 +3243,5 @@ let set_console_idle_timeout ~__context ~self ~value =
32433243
error "Failed to configure console timeout: %s" (Printexc.to_string e) ;
32443244
Helpers.internal_error "Failed to set console timeout: %Ld: %s" value
32453245
(Printexc.to_string e)
3246+
3247+
let set_ssh_auto_mode ~__context ~self:_ ~value:_ = ()

ocaml/xapi/xapi_host.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ val create :
134134
-> ssh_enabled_timeout:int64
135135
-> ssh_expiry:API.datetime
136136
-> console_idle_timeout:int64
137+
-> ssh_auto_mode:bool
137138
-> [`host] Ref.t
138139

139140
val destroy : __context:Context.t -> self:API.ref_host -> unit
@@ -580,3 +581,6 @@ val set_console_idle_timeout :
580581

581582
val schedule_disable_ssh_job :
582583
__context:Context.t -> self:API.ref_host -> timeout:int64 -> unit
584+
585+
val set_ssh_auto_mode :
586+
__context:Context.t -> self:API.ref_host -> value:bool -> unit

ocaml/xapi/xapi_pool.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,7 @@ let rec create_or_get_host_on_master __context rpc session_id (host_ref, host) :
967967
~ssh_enabled_timeout:host.API.host_ssh_enabled_timeout
968968
~ssh_expiry:host.API.host_ssh_expiry
969969
~console_idle_timeout:host.API.host_console_idle_timeout
970+
~ssh_auto_mode:host.API.host_ssh_auto_mode
970971
in
971972
(* Copy other-config into newly created host record: *)
972973
no_exn
@@ -4079,3 +4080,5 @@ let disable_ssh = Ssh.disable
40794080
let set_ssh_enabled_timeout = Ssh.set_enabled_timeout
40804081

40814082
let set_console_idle_timeout = Ssh.set_console_timeout
4083+
4084+
let set_ssh_auto_mode ~__context ~self:_ ~value:_ = ()

ocaml/xapi/xapi_pool.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,3 +443,6 @@ val set_ssh_enabled_timeout :
443443

444444
val set_console_idle_timeout :
445445
__context:Context.t -> self:API.ref_pool -> value:int64 -> unit
446+
447+
val set_ssh_auto_mode :
448+
__context:Context.t -> self:API.ref_pool -> value:bool -> unit

0 commit comments

Comments
 (0)