summaryrefslogtreecommitdiffstats
path: root/scripts/findks.cgi
diff options
context:
space:
mode:
authorMichael DeHaan <mdehaan@mdehaan.rdu.redhat.com>2007-07-23 12:03:38 -0400
committerMichael DeHaan <mdehaan@mdehaan.rdu.redhat.com>2007-07-23 12:03:38 -0400
commit5883a0017a8e4f7f1a56e5a80cd3717336f83a9e (patch)
tree8f8b25f890fd637a27430cbbbac41d1d0f5a6916 /scripts/findks.cgi
parentf824e3a7acf0a32437dc255fdf4a2f2ddbd13248 (diff)
downloadthird_party-cobbler-5883a0017a8e4f7f1a56e5a80cd3717336f83a9e.tar.gz
third_party-cobbler-5883a0017a8e4f7f1a56e5a80cd3717336f83a9e.tar.xz
third_party-cobbler-5883a0017a8e4f7f1a56e5a80cd3717336f83a9e.zip
Added MAC address detection to findks.cgi (Adam Wolf's patch)
Diffstat (limited to 'scripts/findks.cgi')
-rwxr-xr-xscripts/findks.cgi54
1 files changed, 42 insertions, 12 deletions
diff --git a/scripts/findks.cgi b/scripts/findks.cgi
index be8afdf..fbb6fd2 100755
--- a/scripts/findks.cgi
+++ b/scripts/findks.cgi
@@ -45,26 +45,55 @@ def parse_query():
type = "profile"
else:
type = "system"
- name = autodetect_ip()
+ name = autodetect()
return (name,type)
#----------------------------------------------------------------------
-def autodetect_ip():
+def autodetect():
+ # connect to cobblerd and get the list of systems
+
+ try:
+ xmlrpc_server = ServerProxy(XMLRPC_SERVER)
+ systems = xmlrpc_server.get_systems()
+ except:
+ print "# could not contact cobblerd at %s" % XMLRPC_SERVER
+ sys.exit(1)
+
+ # if kssendmac was in the kernel options line, see
+ # if a system can be found matching the MAC address. This
+ # is more specific than an IP match.
+
+ if os.environ.has_key("HTTP_X_RHN_PROVISIONING_MAC_0"):
+ # FIXME: will not key off other NICs
+ devicepair = os.environ["HTTP_X_RHN_PROVISIONING_MAC_0"]
+ mac = devicepair.split()[1].strip()
+ # mac is the macaddress of the first nic reported by anaconda
+ candidates = [system['name'] for system in systems if system['mac_address'].lower() == mac.lower()]
+ if len(candidates) == 0:
+ print "# no system entries with MAC %s found" % mac
+ print "# trying IP lookup"
+ elif len(candidates) > 1:
+ print "# multiple system entries with MAC %s found" % mac
+ sys.exit(1)
+ elif len(candidates) == 1:
+ print "# kickstart matched by MAC: %s" % mac
+ return candidates[0]
+
+ # attempt to match by the IP.
+
ip = os.environ["REMOTE_ADDR"]
- xmlrpc_server = ServerProxy(XMLRPC_SERVER)
- systems = xmlrpc_server.get_systems()
candidates = [system['name'] for system in systems if system['ip_address'] == ip]
if len(candidates) == 0:
- print "# No system entries with ip %s found" % ip
- sys.exit(1)
+ print "# no system entries with ip %s found" % ip
+ sys.exit(1)
elif len(candidates) > 1:
- print "# Multiple system entries with ip %s found" % ip
- sys.exit(1)
+ print "# multiple system entries with ip %s found" % ip
+ sys.exit(1)
elif len(candidates) == 1:
- return candidates[0]
+ return candidates[0]
#----------------------------------------------------------------------
@@ -81,7 +110,7 @@ def serve_file(name):
ks_path = "%s/kickstarts/%s/ks.cfg" % (COBBLER_BASE, name)
if not os.path.exists(ks_path):
- print "# No such cobbler object"
+ print "# no such cobbler object"
sys.exit(1)
try:
@@ -99,6 +128,8 @@ def serve_file(name):
def header():
print "Content-type: text/plain"
print
+ print "# kickstart managed by Cobbler -- http://cobbler.et.redhat.com"
+ print "# served on %s" % time.ctime()
#----------------------------------------------------------------------
@@ -106,8 +137,7 @@ if __name__ == "__main__":
cgitb.enable(format='text')
header()
(name, type) = parse_query()
- print "# kickstart for cobbler %s %s" % (type,name)
- print "# served on %s" % time.ctime()
+ print "# %s %s" % (type,name)
print "# requestor ip = %s" % os.environ["REMOTE_ADDR"]
print "# ============================="
print " "