|
|
|
|
|
|
|
|
|
|
xen-users
Re: [Xen-users] handling mac addresses and guid's
On Sun, 2007-02-18 at 04:09 +0100, Florian Heigl wrote:
> Hi,
>
> I like Xen's feature of autogenerating those values if they are not supplied
> in
> a config file, but for sake of persistency I want to inherit the
> once-generated
> values and reuse them after the first creation of a domU.
>
> I found it possible to query the values at runtime using xm list
> --long but I'm not sure I'm going the most elegant route with that, it
> would mean either wrapping around xm create or hacking a script to be
> executed after domU creation to edit the configfile. This sounds messy
> to me.
>
> How are You handling this?
>
> Thanks!
> Florian
>
I use the following shell function to generate macs. The following is my
own code which I'm hereby donating to the public domain. It may be used
for any purpose without credit to the author. This code is not
copyrighted and comes with no warranty.
# Sets a global _MAC , usage :
# makemac
# echo ${_MAC}
makemac()
{
local prefix="00:00:6d"
local hextet[3]=""
local hextet[4]=""
local hextet[5]=""
local tmp=""
local i=3;
local digi='0a1b2c3d4e5f6789h'
local offset=$((${#digi} - 1))
_MAC="$prefix"
while [ "$i" -le 5 ]; do
tmp[1]="${digi:$(($RANDOM%${offset})):1}"
tmp[2]="${digi:$(($RANDOM%${offset})):1}"
hextet[$i]="${tmp[1]}${tmp[2]}"
_MAC="${_MAC}:${hextet[i]}"
let "i += 1"
done
unset octet
unset tmp
unset prefix
unset i
}
Change $prefix to match what you want, I believe that is the prefix Xen
was granted to indicate a 'virtual' nic.
This should be used when creating the guest, so that it keeps its mac.
Hope this helps.
Best,
--Tim
_______________________________________________
Xen-users mailing list
Xen-users@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-users
|
|
|
|
|