Commit Graph

15 Commits

Author SHA1 Message Date
Thomas Lamprecht
2944acf97e pvesh: code clean-ups
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2023-10-21 16:32:46 +02:00
Thomas Lamprecht
6d7deac70d pvesh: code cleanups for streamed response handling
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2023-10-19 15:26:08 +02:00
Christoph Heiss
86f9a0acea pvesh: decode streamed responses
This allows to use `pvesh` on endpoints like /nodes/{node}/journal,
which return streamed (and possibly gzip'd) responses.

Currently, e.g. `pvesh get /nodes/localhost/journal --lastentries 10`
fails with:

  gzip: stdout: Broken pipe
  got hash object, but result schema specified array!

Using e.g. `--output-format yaml` resulted in:

  ---
  download:
    content-encoding: gzip
    content-type: application/json
    fh: &1 !!perl/ref
      =: *1
    stream: 1

  gzip: stdout: Broken pipe
  Failed to write

This is due the API call returning a "download" object (as seen above),
which contains (among some other things) a file handle to read the
response from.

With this patch, the response from such endpoints is now correctly read
and displayed. Only handles combinations of `Content-Encoding` == 'gzip'
and either 'text/plain' or 'application/json' for `Content-Type`.

This tries to mimic the behavior of the API server implementation when
encountering `download` objects.

Tested this with all four output formats 'text', 'json', 'json-pretty'
and 'yaml', as well as "cross-node" in a local test cluster.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
2023-10-19 10:08:54 +02:00
Dominik Csapak
0fe0a2dd2b pvesh: fix parameters for proxyto_callback
in pve-http-server the proxyto_callback always has a complete list of
parameters, not only the ones in the url, so adapt the implementation
here to do the same

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2023-06-16 11:22:27 +02:00
Thomas Lamprecht
e07c055df4 revert "fix #4333: redirect API handler output to STDERR"
Redirecting stdout is not a feasible approach, as that also affects
all run_commands and other command executions/forks done by the API
handler, and thus breaks parsing outputs of such command executions
in the API handlers.

We plan to add a `--result-fd` option instead, allowing users to pass
their own file, open FD or named pipe to the pvesh, so that they can
process the output in streaming or in full afterward afterwards.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2023-03-14 11:21:29 +01:00
Thomas Lamprecht
5ea98762aa pvesh: don't bloat the code on comments
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2023-03-11 18:10:09 +01:00
Fabian Grünbichler
89fba14715 fix #4333: redirect API handler output to STDERR
otherwise, print/warn statements by the API endpoint are included in the
output, which breaks JSON parsing in case of output-format == json*.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2023-03-11 18:08:00 +01:00
Moayad Almalat
7d8a9a99fc fix #3037: include the split_list to shell_qoute
Based to the suggestion of Wolfgang, in regard to `split_list()`,
 I converted the `split_list()` to `split(/\0/, $param->{$key});`
 this will split the `$param->{$key}` null characters and push each
 element to the `$args` array along with the key value.

 changes since v1:
 * get rid of the `use PVE::Tools qw(split_list);` since not need it anymore.
 * replace the split_list to split(/\0/).

Signed-off-by: Moayad Almalat <m.almalat@proxmox.com>
2023-01-25 09:30:13 +01:00
Fabian Ebner
5ae4718fbe Add all standard output options that are not yet defined
When a property description already contained an option, no standard
output options at all would be added to it, e.g. '/nodes/NODE/vzdump'
already defines its own 'quiet'. Now all not yet defined options are
added to the description, this is done by using the fact that we can
pass a explicit list of std options to add to
add_standard_output_properties, so we filter all already defined ones
out and just pass that as list.

Fixes
pvesh create /nodes/NODE/vzdump -vmid ID -storage STORAGE
issued from a different node and
pvesh create /nodes/NODE/vzdump -vmid ID -storage STORAGE --output-format json
and maybe other calls.

Reported here: https://forum.proxmox.com/threads/output-format-error-with-pvesh-create.47711/

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-03-02 20:17:53 +01:00
Thomas Lamprecht
43b72913ac pvesh: refactor and cleanup
use $res as variable name, as $json which may not be JSON is a bit
confusing.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-02-10 11:37:37 +01:00
Alexandre Derumier
a84a2ae8c5 pvesh: proxy : display result if not json
When a remote node not return a json, we got and error.

This is fixing this:

pvesh set /nodes/localname/network
UPID:kvmformation2:0034937B:09352894:5E41106C:srvreload:networking:root@pam:

pvesh set /nodes/remotenode/network
JSON text must be an object or array (but found number, string, true, false or null, use allow_nonref to allow this) at /usr/share/perl5/PVE/CLI/pvesh.pm line 125.

This patch simply return raw result if it's not a json

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
2020-02-10 11:20:55 +01:00
Christian Ebner
0abe2e035e Fix #1982: pvesh: check if a handler exists for path
Checks that the handler for the API call even exists before verifying the
parameter schema. By this the reported error message is more descriptive.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
2019-01-15 18:57:49 +01:00
Dietmar Maurer
ddc9c56c4d pvesh: fix bug #1942 - add standard options conditional
Do not add/extract standard options if the method itself defined properties
using the same names (like 'quiet').

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-10-16 11:41:26 +02:00
Dietmar Maurer
4d3822cc75 pvesh: add standard_output_properties to set/create/delete
Most of those API calls return simple strings, so it does not really matter.
Nethertheless, some calls return complex data structures and we want to set
output format for them.
2018-07-27 07:34:49 +02:00
Dietmar Maurer
ece19ae214 pvesh cleanup: use a handler class - PVE/CLI/pvesh.pm 2018-07-26 15:20:15 +02:00