Hello all, There''s been many posts lately about problems that stem from either duplicate macs, non static macs and other networking issues that would be averted if a mac was specified upon vm creation. I''ve been using this little function I wrote in my shell scripts that setup dom-u''s from a csv file and its worked rather well, lets you control the prefix and characters used in making the mac. As far as I know there is no "standard" mac prefix to denote a virtual nic. Anyway here''s the snippet / function which is very self explanatory and should work with bash / dash / etc. This can be accomplished with python using only a few lines of code, but bash seems more widely used when creating back end helpers. Hope someone finds it of use. Best, -Tim # creates a random mac address and sets a global _MAC variable # to contain it. makemac() { # edit prefix to suit, ideally matches the manufacturer # prefix of the type of nic your using. local prefix="00:00:6d" local hextet[3]="" local hextet[4]="" local hextet[5]="" local tmp="" local i=3; # these characters are used in making the mac 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 } # When done, the variable $_MAC will contain the generated mac address. Sample use : #!/bin/sh echo "I will make a mac address." makemac echo "The MAC address is ${_MAC}, Have a nice day." unset _MAC exit 0 _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users
Tim Post wrote:> Hello all, > > There''s been many posts lately about problems that stem from either > duplicate macs, non static macs and other networking issues that would > be averted if a mac was specified upon vm creation. > > I''ve been using this little function I wrote in my shell scripts that > setup dom-u''s from a csv file and its worked rather well, lets you > control the prefix and characters used in making the mac. > > As far as I know there is no "standard" mac prefix to denote a virtual > nic. >I seem to recall that the xen folks requested a mac prefix for virtuals and was awarded "00:16:3e:xx:xx:xx".> Anyway here''s the snippet / function which is very self explanatory and > should work with bash / dash / etc. This can be accomplished with python > using only a few lines of code, but bash seems more widely used when > creating back end helpers. > > Hope someone finds it of use. > > Best, > -Tim > > # creates a random mac address and sets a global _MAC variable > # to contain it. > > makemac() > { > # edit prefix to suit, ideally matches the manufacturer > # prefix of the type of nic your using. > local prefix="00:00:6d" > local hextet[3]="" > local hextet[4]="" > local hextet[5]="" > local tmp="" > local i=3; > # these characters are used in making the mac > 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 > } > > # When done, the variable $_MAC will contain the generated mac address. > > Sample use : > > #!/bin/sh > > echo "I will make a mac address." > makemac > echo "The MAC address is ${_MAC}, Have a nice day." > unset _MAC > > exit 0 >_______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users
Tim Post wrote:> Hello all, > > There''s been many posts lately about problems that stem from either > duplicate macs, non static macs and other networking issues that would > be averted if a mac was specified upon vm creation.One point coming to my mind would be, to implement this in python and directly put it into the vm config files. (unfotunately I had some troubles including code in vm config files, so it needed to be copied in each file manually...) O.K., these are rather generic thoughts on how to add functionality to vm config scripts... Henning _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users
On Fri, 2006-12-01 at 19:28 +0100, Henning Sprang wrote:> > One point coming to my mind would be, to implement this in python and > directly put it into the vm config files. >I do things centrally. 1 dom-u controls literally hundreds of xen servers. I put everything into a sqlite DB, then use simple php to enable me to : lynx --source http://domain.com/get.php?domname=xyz > domu.cfg from the nodes. This allows me to signal any node to pick up a config file, and signal my nas to create the appropriate LVM backends and viola :) My bash scripts help create the info in the sqlite db. If python was a spoken language I''d studder horribly, but I know it can be accomplished with 1 or 2 lines of code. Then again I studder with most spoken languages anyway.> (unfotunately I had some troubles including code in vm config files, so > it needed to be copied in each file manually...)Me too :)> O.K., these are rather generic thoughts on how to add functionality to > vm config scripts...There''s always ways to make something better, but stick with what you know .. until you know better :) The end result : it needs to work for you. Best, -Tim _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users