Is there a way to force virsh
to print information in a parseable way? like json
?
I want to write a one-liner shell command that gets the IP address of a VM but the way virsh prints it out is not very friendly to scripts:
# virsh domifaddr myvm
Name MAC address Protocol Address
-------------------------------------------------------------------------------
vnet1 52:54:00:b9:58:64 ipv4 192.168.130.156/24
I'm looking for a way to force it to not print the headers at least so I can get '192.168.130.156' from the output easily
This is the best I could do:
# virsh -q domifaddr myvm | awk '{print $4}' | cut -d/ -f 1
192.168.130.156
One option is to install
qemu-guest-agent
on the domains you would like to extract IP information from.From there, you can execute the following command on the host to get a detailed network interface listing in JSON:
Your json can be parsed however you'd like from there.