[dundee] Virtual Xen Network Interfaces

gordon dunlop astrozubenel at googlemail.com
Wed Oct 29 15:50:40 UTC 2008


When a Xen virtual machine is created a virtual MAC address is
generated into the Xen virtual machine configuration file. Some people
like to do configure this virtual MAC address for different reasons.
All Xen virtual MAC addresses are 00:16:3e:xxx:xx:xx, potentially
approx 12 million MAC addresses. I was looking in how to produce a
python script that could randomly generate these virtual addresses
with a user input defining the number of addresses to generate. I am
stuck as I can only produce copies of the one MAC address due to the
random generator only executing once. I have tried to use loops and
iterations to produce the different MAC addresses but to no avail.
Here is what I have got to so far in my Python script.

#!/usr/bin/python
# xenvirtualmac.py - Generating virtual MAC Addresses with user input
#
import random
mac = [ 0x00, 0x16, 0x3e,
random.randint(0x00, 0x7f),
random.randint(0x00, 0xff),
random.randint(0x00, 0xff) ]
n = int(raw_input('Enter number of MAC Addresses: '))
i = iter(mac)
for j in range(1,n + 1):
     print 'MAC Addresses', j, ':'.join(map(lambda x: "%02x" % x, mac))

If anyone has ideas please let me know.
p.s. I am a Python noob, so if I have missed the obvious, be easy on me.

Gordon



More information about the dundee mailing list