Skip to content

Commit d349779

Browse files
committed
CP-53711: Apply SSH settings in joiner before update_non_vm_metadata
Signed-off-by: Gang Ji <[email protected]>
1 parent 31c2b3c commit d349779

File tree

1 file changed

+37
-20
lines changed

1 file changed

+37
-20
lines changed

ocaml/xapi/xapi_pool.ml

+37-20
Original file line numberDiff line numberDiff line change
@@ -943,29 +943,13 @@ 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
946+
let ssh_enabled = Db.Host.get_ssh_enabled ~__context ~self:host_ref in
950947
let ssh_enabled_timeout =
951-
Client.Host.get_ssh_enabled_timeout ~rpc ~session_id
952-
~self:remote_coordinator
948+
Db.Host.get_ssh_enabled_timeout ~__context ~self:host_ref
953949
in
954950
let console_idle_timeout =
955-
Client.Host.get_console_idle_timeout ~rpc ~session_id
956-
~self:remote_coordinator
951+
Db.Host.get_console_idle_timeout ~__context ~self:host_ref
957952
in
958-
(* Configure SSH service on local host *)
959-
Xapi_host.set_console_idle_timeout ~__context ~self:host_ref
960-
~value:console_idle_timeout ;
961-
Xapi_host.set_ssh_enabled_timeout ~__context ~self:host_ref
962-
~value:ssh_enabled_timeout ;
963-
( match ssh_enabled with
964-
| true ->
965-
Xapi_host.enable_ssh ~__context ~self:host_ref
966-
| false ->
967-
Xapi_host.disable_ssh ~__context ~self:host_ref
968-
) ;
969953
(* As ssh_expiry will be updated by host.enable_ssh and host.disable_ssh,
970954
there is a corner case when the joiner's SSH state will not match SSH
971955
service state in its new coordinator exactly: if the joiner joins when
@@ -1588,6 +1572,7 @@ let join_common ~__context ~master_address ~master_username ~master_password
15881572
)
15891573
in
15901574

1575+
let remote_coordinator = get_master ~rpc ~session_id in
15911576
(* If management is on a VLAN, then get the Pool master
15921577
management network bridge before we logout the session *)
15931578
let pool_master_bridge, mgmt_pif =
@@ -1598,7 +1583,7 @@ let join_common ~__context ~master_address ~master_username ~master_password
15981583
if Db.PIF.get_VLAN_master_of ~__context ~self:my_pif <> Ref.null then
15991584
let pif =
16001585
Client.Host.get_management_interface ~rpc ~session_id
1601-
~host:(get_master ~rpc ~session_id)
1586+
~host:remote_coordinator
16021587
in
16031588
let network = Client.PIF.get_network ~rpc ~session_id ~self:pif in
16041589
(Some (Client.Network.get_bridge ~rpc ~session_id ~self:network), my_pif)
@@ -1688,6 +1673,38 @@ let join_common ~__context ~master_address ~master_username ~master_password
16881673
"Unable to set the write the new pool certificates to the disk : %s"
16891674
(ExnHelper.string_of_exn e)
16901675
) ;
1676+
( try
1677+
let ssh_enabled_timeout =
1678+
Client.Host.get_ssh_enabled_timeout ~rpc ~session_id
1679+
~self:remote_coordinator
1680+
in
1681+
let console_idle_timeout =
1682+
Client.Host.get_console_idle_timeout ~rpc ~session_id
1683+
~self:remote_coordinator
1684+
in
1685+
(* Configure SSH service on local host to apply the settings which
1686+
will persisit after it joins the new pool.
1687+
Please note that ssh_enabled_timeout needs be set before
1688+
update_non_vm_metadata(), inside which ssh_expiry is queried to
1689+
set to host obj in remote coordinator DB.
1690+
*)
1691+
Xapi_host.set_console_idle_timeout ~__context ~self:me
1692+
~value:console_idle_timeout ;
1693+
Xapi_host.set_ssh_enabled_timeout ~__context ~self:me
1694+
~value:ssh_enabled_timeout ;
1695+
let ssh_enabled =
1696+
Client.Host.get_ssh_enabled ~rpc ~session_id
1697+
~self:remote_coordinator
1698+
in
1699+
match ssh_enabled with
1700+
| true ->
1701+
Xapi_host.enable_ssh ~__context ~self:me
1702+
| false ->
1703+
Xapi_host.disable_ssh ~__context ~self:me
1704+
with e ->
1705+
error "Unable to configure SSH service on local host: %s"
1706+
(ExnHelper.string_of_exn e)
1707+
) ;
16911708
(* this is where we try and sync up as much state as we can
16921709
with the master. This is "best effort" rather than
16931710
critical; if we fail part way through this then we carry

0 commit comments

Comments
 (0)