Skip to content

Commit a09a2ed

Browse files
committed
CP-53711: Copy SSH settings from pool coordinator in pool join
During pool join, create a new host obj in the remote pool coordinator DB with the same SSH settings as pool coordinator. Set up SSH service locally by configuring SSH settings in local DB although the local DB will be dropped soon. Signed-off-by: Gang Ji <[email protected]>
1 parent db38cb0 commit a09a2ed

File tree

7 files changed

+94
-8
lines changed

7 files changed

+94
-8
lines changed

ocaml/idl/datamodel_host.ml

+41
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,41 @@ let create_params =
13001300
; param_release= numbered_release "24.40.0"
13011301
; param_default= Some (VString "")
13021302
}
1303+
; {
1304+
param_type= Bool
1305+
; param_name= "ssh_enabled"
1306+
; param_doc= "True if SSH access is enabled for the host"
1307+
; param_release= numbered_release "25.14.0-next"
1308+
; param_default= Some (VBool true)
1309+
}
1310+
; {
1311+
param_type= Int
1312+
; param_name= "ssh_enabled_timeout"
1313+
; param_doc=
1314+
"The timeout in seconds after which SSH access will be automatically \
1315+
disabled (0 means never), this setting will be applied every time the \
1316+
SSH is enabled by XAPI"
1317+
; param_release= numbered_release "25.14.0-next"
1318+
; param_default= Some (VInt 0L)
1319+
}
1320+
; {
1321+
param_type= DateTime
1322+
; param_name= "ssh_expiry"
1323+
; param_doc=
1324+
"The time in UTC after which the SSH access will be automatically \
1325+
disabled"
1326+
; param_release= numbered_release "25.14.0-next"
1327+
; param_default= Some (VDateTime Date.epoch)
1328+
}
1329+
; {
1330+
param_type= Int
1331+
; param_name= "console_idle_timeout"
1332+
; param_doc=
1333+
"The timeout in seconds after which idle console will be automatically \
1334+
terminated (0 means never)"
1335+
; param_release= numbered_release "25.14.0-next"
1336+
; param_default= Some (VInt 0L)
1337+
}
13031338
]
13041339

13051340
let create =
@@ -1312,6 +1347,12 @@ let create =
13121347
, "Added --last_update_hash option to allow last_update_hash to be \
13131348
kept for host joined a pool"
13141349
)
1350+
; ( Changed
1351+
, "25.14.0-next"
1352+
, "Added --ssh_enabled --ssh_enabled_timeout --ssh_expiry \
1353+
--console_idle_timeout options to allow them to be configured for \
1354+
new host"
1355+
)
13151356
]
13161357
~versioned_params:create_params ~doc:"Create a new host record"
13171358
~result:(Ref _host, "Reference to the newly created host object.")

ocaml/tests/common/test_common.ml

+5-2
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,16 @@ let make_host ~__context ?(uuid = make_uuid ()) ?(name_label = "host")
170170
?(external_auth_service_name = "") ?(external_auth_configuration = [])
171171
?(license_params = []) ?(edition = "free") ?(license_server = [])
172172
?(local_cache_sr = Ref.null) ?(chipset_info = []) ?(ssl_legacy = false)
173-
?(last_software_update = Date.epoch) ?(last_update_hash = "") () =
173+
?(last_software_update = Date.epoch) ?(last_update_hash = "")
174+
?(ssh_enabled = true) ?(ssh_enabled_timeout = 0L) ?(ssh_expiry = Date.epoch)
175+
?(console_idle_timeout = 0L) () =
174176
let host =
175177
Xapi_host.create ~__context ~uuid ~name_label ~name_description ~hostname
176178
~address ~external_auth_type ~external_auth_service_name
177179
~external_auth_configuration ~license_params ~edition ~license_server
178180
~local_cache_sr ~chipset_info ~ssl_legacy ~last_software_update
179-
~last_update_hash
181+
~last_update_hash ~ssh_enabled ~ssh_enabled_timeout ~ssh_expiry
182+
~console_idle_timeout
180183
in
181184
Db.Host.set_cpu_info ~__context ~self:host ~value:default_cpu_info ;
182185
host

ocaml/tests/test_host.ml

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ let add_host __context name =
2424
~license_params:[] ~edition:"" ~license_server:[]
2525
~local_cache_sr:Ref.null ~chipset_info:[] ~ssl_legacy:false
2626
~last_software_update:Clock.Date.epoch ~last_update_hash:""
27+
~ssh_enabled:true ~ssh_enabled_timeout:0L ~ssh_expiry:Clock.Date.epoch
28+
~console_idle_timeout:0L
2729
)
2830

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

ocaml/xapi/dbsync_slave.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ let create_localhost ~__context info =
5959
~external_auth_configuration:[] ~license_params:[] ~edition:""
6060
~license_server:[("address", "localhost"); ("port", "27000")]
6161
~local_cache_sr:Ref.null ~chipset_info:[] ~ssl_legacy:false
62-
~last_software_update:Date.epoch ~last_update_hash:""
62+
~last_software_update:Date.epoch ~last_update_hash:"" ~ssh_enabled:true
63+
~ssh_enabled_timeout:0L ~ssh_expiry:Date.epoch ~console_idle_timeout:0L
6364
in
6465
()
6566

ocaml/xapi/xapi_host.ml

+4-4
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,8 @@ let is_host_alive ~__context ~host =
978978
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
981-
~ssl_legacy:_ ~last_software_update ~last_update_hash =
981+
~ssl_legacy:_ ~last_software_update ~last_update_hash ~ssh_enabled
982+
~ssh_enabled_timeout ~ssh_expiry ~console_idle_timeout =
982983
(* fail-safe. We already test this on the joining host, but it's racy, so multiple concurrent
983984
pool-join might succeed. Note: we do it in this order to avoid a problem checking restrictions during
984985
the initial setup of the database *)
@@ -1042,9 +1043,8 @@ let create ~__context ~uuid ~name_label ~name_description:_ ~hostname ~address
10421043
~multipathing:false ~uefi_certificates:"" ~editions:[] ~pending_guidances:[]
10431044
~tls_verification_enabled ~last_software_update ~last_update_hash
10441045
~recommended_guidances:[] ~latest_synced_updates_applied:`unknown
1045-
~pending_guidances_recommended:[] ~pending_guidances_full:[]
1046-
~ssh_enabled:true ~ssh_enabled_timeout:0L ~ssh_expiry:Date.epoch
1047-
~console_idle_timeout:0L ;
1046+
~pending_guidances_recommended:[] ~pending_guidances_full:[] ~ssh_enabled
1047+
~ssh_enabled_timeout ~ssh_expiry ~console_idle_timeout ;
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 ;

ocaml/xapi/xapi_host.mli

+4
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ val create :
130130
-> ssl_legacy:bool
131131
-> last_software_update:API.datetime
132132
-> last_update_hash:string
133+
-> ssh_enabled:bool
134+
-> ssh_enabled_timeout:int64
135+
-> ssh_expiry:API.datetime
136+
-> console_idle_timeout:int64
133137
-> [`host] Ref.t
134138

135139
val destroy : __context:Context.t -> self:API.ref_host -> unit

ocaml/xapi/xapi_pool.ml

+36-1
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,40 @@ let rec create_or_get_host_on_master __context rpc session_id (host_ref, host) :
943943
create_or_get_sr_on_master __context rpc session_id
944944
(my_local_cache_sr, my_local_cache_sr_rec)
945945
in
946+
let remote_coordinator = get_master ~rpc ~session_id in
947+
let ssh_enabled =
948+
Client.Host.get_ssh_enabled ~rpc ~session_id ~self:remote_coordinator
949+
in
950+
let ssh_enabled_timeout =
951+
Client.Host.get_ssh_enabled_timeout ~rpc ~session_id
952+
~self:remote_coordinator
953+
in
954+
let console_idle_timeout =
955+
Client.Host.get_console_idle_timeout ~rpc ~session_id
956+
~self:remote_coordinator
957+
in
958+
(* Configure SSH service parameters in local DB to set up local SSH
959+
service although the local DB will be dropped soon. *)
960+
Db.Host.set_ssh_enabled ~__context ~self:host_ref ~value:ssh_enabled ;
961+
Db.Host.set_ssh_enabled_timeout ~__context ~self:host_ref
962+
~value:ssh_enabled_timeout ;
963+
Db.Host.set_console_idle_timeout ~__context ~self:host_ref
964+
~value:console_idle_timeout ;
965+
( match ssh_enabled with
966+
| true ->
967+
Xapi_host.enable_ssh ~__context ~self:host_ref
968+
| false ->
969+
Xapi_host.disable_ssh ~__context ~self:host_ref
970+
) ;
971+
(* As ssh_expiry will be updated by host.enable_ssh and host.disable_ssh,
972+
there is a corner case when the joiner's SSH state will not match SSH
973+
service state in its new coordinator exactly: if the joiner joins when
974+
SSH service has been enabled in the new coordinator, while not timed
975+
out yet, the joiner will start SSH service with timeout
976+
host.ssh_enabled_timeout, which means SSH service in the joiner will
977+
be disabled later than in the new coordinator. *)
978+
let ssh_expiry = Db.Host.get_ssh_expiry ~__context ~self:host_ref in
979+
946980
debug "Creating host object on master" ;
947981
let ref =
948982
Client.Host.create ~rpc ~session_id ~uuid:my_uuid
@@ -962,7 +996,8 @@ let rec create_or_get_host_on_master __context rpc session_id (host_ref, host) :
962996
~local_cache_sr ~chipset_info:host.API.host_chipset_info
963997
~ssl_legacy:false
964998
~last_software_update:host.API.host_last_software_update
965-
~last_update_hash:host.API.host_last_update_hash
999+
~last_update_hash:host.API.host_last_update_hash ~ssh_enabled
1000+
~ssh_enabled_timeout ~ssh_expiry ~console_idle_timeout
9661001
in
9671002
(* Copy other-config into newly created host record: *)
9681003
no_exn

0 commit comments

Comments
 (0)