| |

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"

Similar Posts

6 Comments

  1. 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. Correction:

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

    XenServer release 6.2.0-70446c (xenenterprise)

  3. Hey there just wanteԁ to give you a quick heads up.
    The text in your post sеem to be running ᧐ff thе screen in Opera.
    І’m not surе if this iѕ a format issue or sоmething to do
    wіth web browser compatibility ƅut I figured I’d post to ⅼеt you know.
    The design and style look great tһough! Hope yоu get the issue solved ѕoon. Many thanks

    1. Thanks for the heads up. I have checked it on several browsers. It is true that I need to fix something to the right of the screen (but I am a bit lazy here…), but the text seems fine on several browsers I’ve tested, following your comments. Anyhow – thanks!

Comments are closed.