API BUG: `pvesh create /nodes/{node}/qemu --output-format=json` response format broken.

reitermarkus

Member
Nov 6, 2021
7
0
6
The API documentation says that this request returns a string. It did previously, but it seems some update broke this.

It should return the Task ID as a JSON string. It now returns a plain text string before the JSON string, e.g. running

Bash:
pvesh create /nodes/net2-pve/qemu -vmid 7777 -name yolo -memory 2048 -cpu kvm64 -cores 4 -sockets 1 -balloon 0 -agent 0 -onboot true -numa true -boot 'order=virtio0;ide0' -args '-cpu kvm64,+ssse3,+sse4.1,+sse4.2' -net0 virtio=40:40:40:40:0f:a9 -scsihw virtio-scsi-pci -virtio0 'local-zfs:4,discard=on,iothread=1' -ide0 'local:iso/talos-1.0.6-amd64.iso,media=cdrom' --output-format=json

produces

JSON:
virtio0: successfully created disk 'local-zfs:vm-7777-disk-0,discard=on,iothread=1,size=4G'
"UPID:net2-pve:002605B4:00FB48C2:62B9E7EB:qmcreate:7777:root@pam:"


This is on PVE 7.2-5.
 
Last edited:
I'll try on another node, but all nodes are on the same version already.

Last time I know it worked was in February, so probably whichever 7.1 version was the latest in February would work.
 
For context, I came across this while implementing https://github.com/ansible-collections/community.general/pull/4027. It is much more convenient to use pvesh when you're already SSH'd into a node via Ansible rather than having to provide separate credentials, so it would be great if it was supported for this automation use case.
you could always use pveum ticket :)
PVE 7.1-7 works.
PVE 7.2-3 does not work.
thanks - I'll see whether it's possible to figure out what's going on :)
 
@fabian, any update on this?

I could have a look myself, but last time I checked I couldn't quite figure out where the source code for the pvesh command is located. Would be great if you could point me to it.
 
Commit 3e7d9fac in the qemu-server.git repo added the message. There are some other printed messages printed to STDOUT however, so I don't think this is a new issue.

I guess the simplest solution would be to redirect STDOUT to STDERR in pvesh.pm during the API call. Something like this in sub call_api_method:

Perl:
    do {
        local *STDOUT;
        open(STDOUT, '>&', STDERR);

        if ($node) {
            $data = proxy_handler($node, $remip, $path, $cmd, $param);
        } else {
            foreach my $p (keys %$uri_param) {
                $param->{$p} = $uri_param->{$p};
            }
            $data = $handler->handle($info, $param);
        }
    };

That way STDOUT only contains the JSON output, as expected.
 
Last edited:

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!