XenServer get VM by MAC

Using the GUI, it could be somewhat complex identifying a VM based on its MAC address. There are several solutions on the network using PowerShell, but I will demonstrate it using a simple bash script, below. Save, make executable, and run.

Enjoy

 

#!/bin/bash
if [ -z "$1" ]
then
	echo "Requires parameter - MAC address"
	exit 1
fi

MAC=$1
# You might want to check MAC correctness here. Enjoy doing it. RegExp, man!

# XenServer is agnostic to case for MAC addresses, so we don't care
VIF_UUID=`xe vif-list MAC=$MAC | grep ^uuid | awk '{print $NF}'`

VM=`xe vif-param-list uuid=$VIF_UUID | grep vm-name-label | awk '{print $NF}'`

echo "MAC $MAC has VM $VM"

Tags: , , ,

4 Responses to “XenServer get VM by MAC”

  1. Todor Petkov Says:

    Hi,

    you can try this:

    xe vif-param MAC=$MAC params=all

    It will produce some unneeded data, but still you can find it useful. Or if you don’t need the whole package, you can play with the params option:

    xe vif-param MAC=$MAC params=uuid,vm-name-label

    Regards,

  2. ez-aton Says:

    Thanks! Noted.

  3. Todor Petkov Says:

    Correction:

    xe vif-list params=vm-name-label,MAC MAC=96:f4:60:b2:f7:f7

    XenServer release 6.2.0-70446c (xenenterprise)

  4. ez-aton Says:

    Thanks!
    Ez

Leave a Reply