Skip to content

Commit cb9277d

Browse files
committed
CP-53725 Create SSH-related xe CLI for Dom0 SSH control
Updated `records.ml` file to support `host-param-set/get/list` and `pool-param-set/get/list` for SSH-related fields. Signed-off-by: Lunfan Zhang <[email protected]>
1 parent a3bc84d commit cb9277d

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

Diff for: ocaml/xapi-cli-server/records.ml

+89
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ let nullref = Ref.string_of Ref.null
2020

2121
let nid = "<not in database>"
2222

23+
let inconsistent = "<inconsistent>"
24+
2325
let unknown_time = "<unknown time>"
2426

2527
let string_of_float f = Printf.sprintf "%.3f" f
@@ -204,6 +206,37 @@ let get_pbds_host rpc session_id pbds =
204206
let get_sr_host rpc session_id record =
205207
get_pbds_host rpc session_id record.API.sR_PBDs
206208

209+
(** Get consistent field from all hosts, or return a default value if the field
210+
is not the same on all hosts. *)
211+
let get_consistent_field_or_default ~rpc ~session_id ~getter ~transform ~default
212+
=
213+
match Client.Host.get_all ~rpc ~session_id with
214+
| [] ->
215+
default
216+
| hosts -> (
217+
let result =
218+
List.fold_left
219+
(fun acc host ->
220+
match acc with
221+
| `Inconsistent ->
222+
`Inconsistent
223+
| `NotSet ->
224+
`Value (getter ~rpc ~session_id ~self:host |> transform)
225+
| `Value v ->
226+
let current = getter ~rpc ~session_id ~self:host |> transform in
227+
if v = current then `Value v else `Inconsistent
228+
)
229+
`NotSet hosts
230+
in
231+
match result with
232+
| `Value v ->
233+
v
234+
| `Inconsistent ->
235+
default
236+
| `NotSet ->
237+
default
238+
)
239+
207240
let bond_record rpc session_id bond =
208241
let _ref = ref bond in
209242
let empty_record =
@@ -1506,6 +1539,42 @@ let pool_record rpc session_id pool =
15061539
)
15071540
~get_map:(fun () -> (x ()).API.pool_license_server)
15081541
()
1542+
; make_field ~name:"ssh-enabled"
1543+
~get:(fun () ->
1544+
get_consistent_field_or_default ~rpc ~session_id
1545+
~getter:Client.Host.get_ssh_enabled ~transform:string_of_bool
1546+
~default:inconsistent
1547+
)
1548+
()
1549+
; make_field ~name:"ssh-enabled-timeout"
1550+
~get:(fun () ->
1551+
get_consistent_field_or_default ~rpc ~session_id
1552+
~getter:Client.Host.get_ssh_enabled_timeout
1553+
~transform:Int64.to_string ~default:inconsistent
1554+
)
1555+
~set:(fun value ->
1556+
Client.Pool.set_ssh_enabled_timeout ~rpc ~session_id ~self:pool
1557+
~value:(safe_i64_of_string "ssh-enabled-timeout" value)
1558+
)
1559+
()
1560+
; make_field ~name:"ssh-expiry"
1561+
~get:(fun () ->
1562+
get_consistent_field_or_default ~rpc ~session_id
1563+
~getter:Client.Host.get_ssh_expiry ~transform:Date.to_rfc3339
1564+
~default:inconsistent
1565+
)
1566+
()
1567+
; make_field ~name:"console-idle-timeout"
1568+
~get:(fun () ->
1569+
get_consistent_field_or_default ~rpc ~session_id
1570+
~getter:Client.Host.get_console_idle_timeout
1571+
~transform:Int64.to_string ~default:inconsistent
1572+
)
1573+
~set:(fun value ->
1574+
Client.Pool.set_console_idle_timeout ~rpc ~session_id ~self:pool
1575+
~value:(safe_i64_of_string "console-idle-timeout" value)
1576+
)
1577+
()
15091578
]
15101579
}
15111580

@@ -3265,6 +3334,26 @@ let host_record rpc session_id host =
32653334
; make_field ~name:"last-update-hash"
32663335
~get:(fun () -> (x ()).API.host_last_update_hash)
32673336
()
3337+
; make_field ~name:"ssh-enabled"
3338+
~get:(fun () -> string_of_bool (x ()).API.host_ssh_enabled)
3339+
()
3340+
; make_field ~name:"ssh-enabled-timeout"
3341+
~get:(fun () -> Int64.to_string (x ()).API.host_ssh_enabled_timeout)
3342+
~set:(fun value ->
3343+
Client.Host.set_ssh_enabled_timeout ~rpc ~session_id ~self:host
3344+
~value:(safe_i64_of_string "ssh-enabled-timeout" value)
3345+
)
3346+
()
3347+
; make_field ~name:"ssh-expiry"
3348+
~get:(fun () -> Date.to_rfc3339 (x ()).API.host_ssh_expiry)
3349+
()
3350+
; make_field ~name:"console-idle-timeout"
3351+
~get:(fun () -> Int64.to_string (x ()).API.host_console_idle_timeout)
3352+
~set:(fun value ->
3353+
Client.Host.set_console_idle_timeout ~rpc ~session_id ~self:host
3354+
~value:(safe_i64_of_string "console-idle-timeout" value)
3355+
)
3356+
()
32683357
]
32693358
}
32703359

0 commit comments

Comments
 (0)