summaryrefslogtreecommitdiffstats
path: root/cobbler
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
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')
-rw-r--r--cobbler/modules/cli_system.py8
-rw-r--r--cobbler/remote.py20
-rw-r--r--cobbler/utils.py21
-rw-r--r--cobbler/webui/master.py4
4 files changed, 33 insertions, 20 deletions
diff --git a/cobbler/modules/cli_system.py b/cobbler/modules/cli_system.py
index 0c9a5b8..419b561 100644
--- a/cobbler/modules/cli_system.py
+++ b/cobbler/modules/cli_system.py
@@ -19,7 +19,7 @@ plib = distutils.sysconfig.get_python_lib()
mod_path="%s/cobbler" % plib
sys.path.insert(0, mod_path)
-from utils import _
+from utils import _, get_random_mac
import commands
import cexceptions
@@ -98,7 +98,11 @@ class SystemFunction(commands.CobblerFunction):
my_interface = "intf0"
if self.options.hostname: obj.set_hostname(self.options.hostname, my_interface)
- if self.options.mac: obj.set_mac_address(self.options.mac, my_interface)
+ if self.options.mac:
+ if self.options.mac.lower() == 'random':
+ obj.set_mac_address(get_random_mac(self.api), my_interface)
+ else:
+ obj.set_mac_address(self.options.mac, my_interface)
if self.options.ip: obj.set_ip_address(self.options.ip, my_interface)
if self.options.subnet: obj.set_subnet(self.options.subnet, my_interface)
if self.options.gateway: obj.set_gateway(self.options.gateway, my_interface)
diff --git a/cobbler/remote.py b/cobbler/remote.py
index 18c3947..749298e 100644
--- a/cobbler/remote.py
+++ b/cobbler/remote.py
@@ -475,25 +475,13 @@ class CobblerXMLRPCInterface:
def get_random_mac(self,token=None):
"""
- 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
+ Wrapper for utils.get_random_mac
+
+ Used in the webui
"""
self.log("get_random_mac",token=None)
self._refresh()
- 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 = self.api.systems()
- while ( systems.find(mac_address=mac) ):
- mac = self.get_random_mac()
-
- return mac
+ return utils.get_random_mac(self.api)
def _fix_none(self,data):
"""
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):
"""
diff --git a/cobbler/webui/master.py b/cobbler/webui/master.py
index cdde14d..50f9fd1 100644
--- a/cobbler/webui/master.py
+++ b/cobbler/webui/master.py
@@ -33,8 +33,8 @@ VFN=valueForName
currentTime=time.time
__CHEETAH_version__ = '2.0.1'
__CHEETAH_versionTuple__ = (2, 0, 1, 'final', 0)
-__CHEETAH_genTime__ = 1209998447.8930521
-__CHEETAH_genTimestamp__ = 'Mon May 5 10:40:47 2008'
+__CHEETAH_genTime__ = 1210208830.681746
+__CHEETAH_genTimestamp__ = 'Wed May 7 21:07:10 2008'
__CHEETAH_src__ = 'webui_templates/master.tmpl'
__CHEETAH_srcLastModified__ = 'Thu May 1 13:51:29 2008'
__CHEETAH_docstring__ = 'Autogenerated by CHEETAH: The Python-Powered Template Engine'