Get list of VMs using a specific network interface

JRace

New Member
Nov 1, 2023
1
0
1
Is there a way to get a list of VMs using a specific network interface?
For example, in the VMWare vCenter GUI, you can click on a virtual network switch and get a list of all VMs that are using it.
I'm trying to get a handle on what VMs might be configured with one particular interface without having to go through each one and look at the network adapter config.
 
I don't think that there is a way to see them in the GUI.

Since every VM has a config file under /etc/pve/qemu-server you could grep them for the parts that marks the interface connected to a certain bridge, like so:
Code:
cd /etc/pve/qemu-server
grep 'bridge=vmbr0' *
 
Cluster wide search, with a bit more bells and wistles:

Code:
for vmid in $(grep -l vmbr2 /etc/pve/nodes/*/qemu-server/*.conf | sed -e's/.*\///;s/.conf//');do echo -n "$vmid: ";grep ^name: /etc/pve/nodes/*/qemu-server/${vmid}.conf|cut -d\  -f2;done|sort -k2

for vmid in $( grep -l vmbr2 /etc/pve/nodes/*/qemu-server/*.conf | sed -e's/.*\///;s/.conf//');
#              ^-- get config file matching interface              ^-- extract vmid from file name
do
  # display vmid / vm name (extrzcted from config file)
  echo -n "$vmid: ";
  grep ^name: /etc/pve/nodes/*/qemu-server/${vmid}.conf | cut -d\  -f2;
done | sort -k2
#      ^ -- sort result