Skip to content

Commit a90dfeb

Browse files
author
Christian Lindig
committed
Add file-upload support to xe host-call-plugin
To pass file content to a plugin, vm-call-plugin supports passing the content of a client-side file as a parameter. This is missing for host-call-plugin - this patch adds it. Otherwise is difficult to pass anything beyond a short string to a plugin. Signed-off-by: Christian Lindig <[email protected]>
1 parent f75af5b commit a90dfeb

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

ocaml/xapi-cli-server/cli_frontend.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -958,8 +958,9 @@ let rec cmdtable_data : (string * cmd_spec) list =
958958
; optn= ["args:"]
959959
; help=
960960
"Calls the function within the plugin on the given host with \
961-
optional arguments."
962-
; implementation= No_fd Cli_operations.host_call_plugin
961+
optional arguments. The syntax args:key:file=/path/file.ext passes \
962+
the content of /path/file.ext under key to the plugin."
963+
; implementation= With_fd Cli_operations.host_call_plugin
963964
; flags= []
964965
}
965966
)

ocaml/xapi-cli-server/cli_operations.ml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6907,12 +6907,27 @@ let host_set_hostname_live _printer rpc session_id params =
69076907
let hostname = List.assoc "host-name" params in
69086908
Client.Host.set_hostname_live ~rpc ~session_id ~host ~hostname
69096909

6910-
let host_call_plugin printer rpc session_id params =
6910+
let host_call_plugin fd printer rpc session_id params =
69116911
let host_uuid = List.assoc "host-uuid" params in
69126912
let host = Client.Host.get_by_uuid ~rpc ~session_id ~uuid:host_uuid in
69136913
let plugin = List.assoc "plugin" params in
69146914
let fn = List.assoc "fn" params in
69156915
let args = read_map_params "args" params in
6916+
let convert ((k, v) as p) =
6917+
match Astring.String.cut ~sep:":" k with
6918+
| Some (key, "file") -> (
6919+
match get_client_file fd v with
6920+
| Some s ->
6921+
(key, s)
6922+
| None ->
6923+
marshal fd
6924+
(Command (PrintStderr (Printf.sprintf "Failed to read file %s\n" v))) ;
6925+
raise (ExitWithError 1)
6926+
)
6927+
| _ ->
6928+
p
6929+
in
6930+
let args = List.map convert args in
69166931
let result =
69176932
Client.Host.call_plugin ~rpc ~session_id ~host ~plugin ~fn ~args
69186933
in

0 commit comments

Comments
 (0)