summaryrefslogtreecommitdiffstats
path: root/cobbler/utils.py
diff options
context:
space:
mode:
authorMichael DeHaan <mdehaan@redhat.com>2008-05-08 10:09:08 -0400
committerMichael DeHaan <mdehaan@redhat.com>2008-05-08 10:09:08 -0400
commit072204fb8d3e351c2c6e67beb52de175cad0c979 (patch)
tree94cdd595ccace67f915e8467deb8570390783add /cobbler/utils.py
parente9cba0c5d8ca7356621a737a09b6a22d8b00e9fc (diff)
downloadthird_party-cobbler-072204fb8d3e351c2c6e67beb52de175cad0c979.tar.gz
third_party-cobbler-072204fb8d3e351c2c6e67beb52de175cad0c979.tar.xz
third_party-cobbler-072204fb8d3e351c2c6e67beb52de175cad0c979.zip
Apply John Eckersberg's patch to allow random mac usage from the command line.
Diffstat (limited to 'cobbler/utils.py')
-rw-r--r--cobbler/utils.py21
1 files changed, 21 insertions, 0 deletions
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):
"""