Pages

Monday, April 27, 2015

determine which virtual interface belongs to a virtual machine in a kvm host

Determine which virtual interface belongs to a virtual machine in a kvm host

This topic is really interesting. Say I have 'N' number of Virtual Interfaces in my KVM System. How shall I find which virtual interface belong with which guest machine ?

The following script will help to achieve this.

VNET=vnet13; 
for vm in $(virsh list | grep running | awk '{print $2}');
 do 
         virsh dumpxml $vm|grep -q "$VNET" && echo $vm; 
done

where VNET corresponds to virtual interface.

Based on the Virtual Interface, we shall determine to which guest machine it belongs to.

I got this script from here.

http://serverfault.com/questions/396105/is-there-a-way-to-determine-which-virtual-interface-belongs-to-a-virtual-machine

The same script shall be modified to find the MAC Addresses of all the Guest Machine(s).

The following script will print the MAC Address and Name of the Guest Machine.

#!/bin/bash

for i in `virsh list |grep running | awk {'print $2'}`
do
mac=`virsh dumpxml $i |grep "mac address" |cut -d "=" -f 2| tr -d "'/>"`
echo "$i,$mac"
done


No comments:

Post a Comment