From 072204fb8d3e351c2c6e67beb52de175cad0c979 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Thu, 8 May 2008 10:09:08 -0400 Subject: Apply John Eckersberg's patch to allow random mac usage from the command line. --- cobbler/utils.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'cobbler/utils.py') diff --git a/cobbler/utils.py b/cobbler/utils.py index 7bd37ad..14019e8 100644 --- a/cobbler/utils.py +++ b/cobbler/utils.py @@ -17,6 +17,7 @@ import os import re import socket import glob +import random import sub_process import shutil import string @@ -111,6 +112,26 @@ def is_mac(strdata): return True return False +def get_random_mac(api_handle): + """ + Generate a random MAC address. + from xend/server/netif.py + Generate a random MAC address. + Uses OUI 00-16-3E, allocated to + Xensource, Inc. Last 3 fields are random. + return: MAC address string + """ + mac = [ 0x00, 0x16, 0x3e, + random.randint(0x00, 0x7f), + random.randint(0x00, 0xff), + random.randint(0x00, 0xff) ] + 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 resolve_ip(strdata): """ -- cgit