def get_random_mac(api_handle, virt_type='xenpv'):
 if virt_type.startswith('vmware'):
  mac = [0, 80, 86, random.randint(0, 63), random.randint(0, 255), random.randint(0, 255)]
 elif (virt_type.startswith('xen') or virt_type.startswith('qemu') or virt_type.startswith('kvm')):
  mac = [0, 22, 62, random.randint(0, 127), random.randint(0, 255), random.randint(0, 255)]
 else:
  raise CX('virt mac assignment not yet supported')
 mac = ':'.join(map((lambda x: ('%02x' % x)), mac))
 systems = api_handle.systems()
 while systems.find(mac_address=mac):
  mac = get_random_mac(api_handle)
 return mac

def get_random_mac ( api_handle , virt_type = 'xenpv' ) : if virt_type . startswith ( 'vmware' ) : mac = [ 0 , 80 , 86 , random . randint ( 0 , 63 ) , random . randint ( 0 , 255 ) , random . randint ( 0 , 255 ) ] elif ( virt_type . startswith ( 'xen' ) or virt_type . startswith ( 'qemu' ) or virt_type . startswith ( 'kvm' ) ) : mac = [ 0 , 22 , 62 , random . randint ( 0 , 127 ) , random . randint ( 0 , 255 ) , random . randint ( 0 , 255 ) ] else : raise CX ( 'virt mac assignment not yet supported' ) mac = ':' . join ( map ( ( lambda x : ( '%02x' % x ) ) , mac ) ) systems = api_handle . systems ( ) while systems . find ( mac_address = mac ) : mac = get_random_mac ( api_handle ) return mac
generate a random mac address starting with fe:16:3e .