[GH-ISSUE #64] proxmoxer agent exec-status and "out-data" #32

Closed
opened 2026-02-27 15:46:06 +03:00 by kerem · 4 comments
Owner

Originally created by @enimath on GitHub (Aug 2, 2021).
Original GitHub issue: https://github.com/proxmoxer/proxmoxer/issues/64

Hello

How can i type "out-data" to see output of command ?

code :

def agent_get_swap(targetnode,vmid):
  command = 'blkid -o value -L swap'
  agent = []
  agent = proxmox.nodes(targetnode).qemu(vmid).agent.exec.post(command=command)
  pid = agent['pid']
  swap = proxmox.nodes(targetnode).qemu(vmid).agent("exec-status").get(pid=pid)
  return swap

test = agent_get_swap(local-15,101)
print (test)

it only print {'exited': 0} without "out-data" which I need (it should be /dev/sdb)

I can read that in exec-status out-data is optional so I thing I need to turn it on somehow.
https://pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}/qemu/{vmid}/agent/exec-status

Originally created by @enimath on GitHub (Aug 2, 2021). Original GitHub issue: https://github.com/proxmoxer/proxmoxer/issues/64 Hello How can i type "out-data" to see output of command ? code : ``` def agent_get_swap(targetnode,vmid): command = 'blkid -o value -L swap' agent = [] agent = proxmox.nodes(targetnode).qemu(vmid).agent.exec.post(command=command) pid = agent['pid'] swap = proxmox.nodes(targetnode).qemu(vmid).agent("exec-status").get(pid=pid) return swap test = agent_get_swap(local-15,101) print (test) ``` it only print {'exited': 0} without "out-data" which I need (it should be /dev/sdb) I can read that in exec-status out-data is optional so I thing I need to turn it on somehow. https://pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}/qemu/{vmid}/agent/exec-status
kerem closed this issue 2026-02-27 15:46:06 +03:00
Author
Owner

@enimath commented on GitHub (Aug 2, 2021):

pvesh show everything :

root@local-14:~# pvesh get /nodes/local-14/qemu/101/agent/exec-status --pid=10943
┌──────────┬──────────┐
│ key      │ value    │
╞══════════╪══════════╡
│ exitcode │ 0        │
├──────────┼──────────┤
│ exited   │ 1        │
├──────────┼──────────┤
│ out-data │ /dev/sdb │
└──────────┴──────────┘
root@local-14:~#
<!-- gh-comment-id:891038170 --> @enimath commented on GitHub (Aug 2, 2021): pvesh show everything : ``` root@local-14:~# pvesh get /nodes/local-14/qemu/101/agent/exec-status --pid=10943 ┌──────────┬──────────┐ │ key │ value │ ╞══════════╪══════════╡ │ exitcode │ 0 │ ├──────────┼──────────┤ │ exited │ 1 │ ├──────────┼──────────┤ │ out-data │ /dev/sdb │ └──────────┴──────────┘ root@local-14:~# ```
Author
Owner

@enimath commented on GitHub (Aug 18, 2021):

I thing there should be some python workaround to omit this "-" in "out-data". Anyone ?

<!-- gh-comment-id:900860204 --> @enimath commented on GitHub (Aug 18, 2021): I thing there should be some python workaround to omit this "-" in "out-data". Anyone ?
Author
Owner

@jhollowe commented on GitHub (Sep 7, 2021):

This is an issue with usage. The exited: 0 means that the command has not completed yet. You need to either poll the API until you get exited: 1 and all the data, or let whatever is calling the function handle the incomplete data.

Below is a version of the function that defaults to blocking (waiting) for the results but can be given an argument to be non-blocking. I've used the sleep command to show a program that we know will take some time to complete, just replace with your command and it should be fine.

def agent_get_swap(targetnode,vmid,blocking=True):
  command = 'sleep 5'
  agent = proxmox.nodes(targetnode).qemu(vmid).agent.exec.post(command=command)
  pid = agent['pid']
  swap = proxmox.nodes(targetnode).qemu(vmid).agent("exec-status").get(pid=pid)
  if blocking:
    while swap["exited"] != 1:
        swap = proxmox.nodes(targetnode).qemu(vmid).agent("exec-status").get(pid=pid)

  return swap

and running print(test = agent_get_swap("node_name",103)) shows {'exitcode': 0, 'exited': 1} (there is no output thus no out-data, but a command with output will include out-data)

If this solved your problem, please close the issue; if you have further questions, please ask!

<!-- gh-comment-id:914440890 --> @jhollowe commented on GitHub (Sep 7, 2021): This is an issue with usage. The `exited: 0` means that the command has not completed yet. You need to either poll the API until you get `exited: 1` and all the data, or let whatever is calling the function handle the incomplete data. Below is a version of the function that defaults to blocking (waiting) for the results but can be given an argument to be non-blocking. I've used the `sleep` command to show a program that we know will take some time to complete, just replace with your command and it should be fine. ```python def agent_get_swap(targetnode,vmid,blocking=True): command = 'sleep 5' agent = proxmox.nodes(targetnode).qemu(vmid).agent.exec.post(command=command) pid = agent['pid'] swap = proxmox.nodes(targetnode).qemu(vmid).agent("exec-status").get(pid=pid) if blocking: while swap["exited"] != 1: swap = proxmox.nodes(targetnode).qemu(vmid).agent("exec-status").get(pid=pid) return swap ``` and running `print(test = agent_get_swap("node_name",103))` shows `{'exitcode': 0, 'exited': 1}` (there is no output thus no `out-data`, but a command with output will include `out-data`) *If this solved your problem, please close the issue; if you have further questions, please ask!*
Author
Owner

@jhollowe commented on GitHub (Oct 2, 2021):

Assuming this is resolved. Please reopen if it is not.

<!-- gh-comment-id:932773434 --> @jhollowe commented on GitHub (Oct 2, 2021): Assuming this is resolved. Please reopen if it is not.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/proxmoxer#32
No description provided.