[SOLVED] Using qemu agent from command line

shantanu

Renowned Member
Mar 30, 2012
112
12
83
Hi,

For quite some time, I have been experimenting with using the QEMU Agent from the commandline.
I have enabled the agent from the web gui and installed the qemu-agent package in my guest.
I am getting the results but I am not able to the same in a scripted manner.

# pveversion -v
proxmox-ve: 4.4-77 (running kernel: 4.4.35-1-pve)
pve-manager: 4.4-5 (running version: 4.4-5/c43015a5)
pve-kernel-4.4.35-1-pve: 4.4.35-77
pve-kernel-4.2.6-1-pve: 4.2.6-36
lvm2: 2.02.116-pve3
corosync-pve: 2.4.0-1
libqb0: 1.0-1
pve-cluster: 4.0-48
qemu-server: 4.0-102
pve-firmware: 1.1-10
libpve-common-perl: 4.0-85
libpve-access-control: 4.0-19
libpve-storage-perl: 4.0-71
pve-libspice-server1: 0.12.8-1
vncterm: 1.2-1
pve-docs: 4.4-1
pve-qemu-kvm: 2.7.0-10
pve-container: 1.0-90
pve-firewall: 2.0-33
pve-ha-manager: 1.0-38
ksm-control-daemon: 1.2-1
glusterfs-client: 3.5.2-2+deb8u2
lxc-pve: 2.0.6-5
lxcfs: 2.0.5-pve2
criu: 1.6.0-1
novnc-pve: 0.5-8
smartmontools: 6.5+svn4324-1~pve80
zfsutils: 0.6.5.8-pve13~bpo80

Here is what I am doing and hope to produce output:
Code:
# echo '{"execute":"guest-network-get-interfaces"}' | socat /var/run/qemu-server/100.qga -

Unfortunately, this outputs nothing!!! :mad::(

But now, if I just type:
Code:
# socat /var/run/qemu-server/100.qga -

I suddenly get the output on screen: (trimmed)
Code:
{"return": [{"name": "lo", "ip-addresses": [{"ip-address-type": "ipv4", "ip-address": "127.0.0.1", "prefix": 8}, {"ip-address-type": "ipv6", "ip-address": "::1", <...trimmed...>

The complete output is correct and I ran it through "jq" as well.

My question is how to to get the output correctly in a scripted manner?

Thanks and Regards,
Shantanu
 
First, you can use the new 'agent' command with 'qm':

# qm agent 100 network-get-interfaces

The output is JSON. Any reasonable scripting language can read that (beside unix shell).
 
First, you can use the new 'agent' command with 'qm':

# qm agent 100 network-get-interfaces

The output is JSON. Any reasonable scripting language can read that (beside unix shell).
Thank you!!!! This is indeed good news!
 
First, you can use the new 'agent' command with 'qm':

# qm agent 100 network-get-interfaces

The output is JSON. Any reasonable scripting language can read that (beside unix shell).

"jq" is a nice CLI json parser that allows parsing / filtering / .. json in bash (or other sh) scripts