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

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/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: , , ,

6 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

  5. pratique orientale Says:

    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

  6. etzion Says:

    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!

Leave a Reply