summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorMichael DeHaan <mdehaan@redhat.com>2008-03-07 11:26:04 -0500
committerMichael DeHaan <mdehaan@redhat.com>2008-03-07 11:26:04 -0500
commit64309dd05411ee5b8ca294da58ddac9ffc882168 (patch)
treea2f6b74a3cd783f624bd433bdd2fb50e28a1d673 /scripts
parentac60c2532fb410217a8e3f1fe2a4bf3bf6eb72fc (diff)
downloadthird_party-cobbler-64309dd05411ee5b8ca294da58ddac9ffc882168.tar.gz
third_party-cobbler-64309dd05411ee5b8ca294da58ddac9ffc882168.tar.xz
third_party-cobbler-64309dd05411ee5b8ca294da58ddac9ffc882168.zip
Getting ready for 0.8.2 release
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/change_profile.cgi86
-rwxr-xr-xscripts/findks.cgi1
-rwxr-xr-xscripts/register_mac.cgi22
3 files changed, 15 insertions, 94 deletions
diff --git a/scripts/change_profile.cgi b/scripts/change_profile.cgi
index f2e5acd..f7330f1 100755
--- a/scripts/change_profile.cgi
+++ b/scripts/change_profile.cgi
@@ -24,12 +24,8 @@ import sys
import socket
import xmlrpclib
-# FIXME: edit these two variables to match your webui configuration
-USERNAME = "cobbler"
-PASSWORD = "cobbler"
-
COBBLER_BASE = "/var/www/cobbler"
-XMLRPC_SERVER = "http://127.0.0.1/cobbler_api_rw"
+XMLRPC_SERVER = "http://127.0.0.1/cobbler_api"
DEFAULT_PROFILE = "default"
#----------------------------------------------------------------------
@@ -44,6 +40,12 @@ class ServerProxy(xmlrpclib.ServerProxy):
def parse_query():
form = cgi.parse()
+
+ mac = "-1"
+ 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"]
+ return devicepair.split()[1].strip()
if form.has_key("profile"):
profile = form["profile"][0]
@@ -57,68 +59,10 @@ def parse_query():
#----------------------------------------------------------------------
def autodetect():
+ # get mac address, requires kssendmac on the kernel options line.
+ else:
+ return "-1"
- # 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.
-
- try:
- ip = os.environ["REMOTE_ADDR"]
- except:
- ip = "127.0.0.1"
-
- candidates = []
- for x in systems:
- for y in x["interfaces"]:
- if x["interfaces"][y]["ip_address"] == ip:
- candidates.append(x)
-
- if len(candidates) == 0:
- 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)
- elif len(candidates) == 1:
- return candidates[0]
-
-#----------------------------------------------------------------------
-
-
-def make_change(server,system,profile,token):
- print "# getting handle for: %s" % system
- handle = server.get_system_handle(system,token)
- print "# modifying system %s to %s" % (system,profile)
- server.modify_system(handle,"profile",profile,token)
- print "# saving system"
- server.save_system(handle,token)
#----------------------------------------------------------------------
@@ -132,15 +76,11 @@ if __name__ == "__main__":
cgitb.enable(format='text')
header()
server = ServerProxy(XMLRPC_SERVER)
- token = server.login(USERNAME,PASSWORD)
- (system, profile) = parse_query()
- print "# running for %s %s" % (system,profile)
+ (mac, profile) = parse_query()
try:
ip = os.environ["REMOTE_ADDR"]
except:
ip = "???"
- print "# requestor ip = %s" % ip
- print "# ============================="
- print "# system name = %s" % system
- make_change(server,system,profile,token)
+ print "# attempting to change system(mac=%s) to profile(%s)" % (mac,profile)
+ server.change_profile(mac,profile)
diff --git a/scripts/findks.cgi b/scripts/findks.cgi
index 6fad6dc..39adbcf 100755
--- a/scripts/findks.cgi
+++ b/scripts/findks.cgi
@@ -73,6 +73,7 @@ def autodetect():
candidates = []
for x in systems:
+
for y in x["interfaces"]:
if x["interfaces"][y]["ip_address"] == ip:
candidates.append(x)
diff --git a/scripts/register_mac.cgi b/scripts/register_mac.cgi
index b0eb587..5507525 100755
--- a/scripts/register_mac.cgi
+++ b/scripts/register_mac.cgi
@@ -84,27 +84,7 @@ def autodetect():
def make_change(server,mac,profile,token):
- print "# getting handle for: %s" % mac
-
- systems = server.get_systems()
- for s in systems:
- for i in s["interfaces"]:
- if s["interfaces"][i]["mac_address"].lower() == mac.lower():
- print "# found an existing record, will not continue"
- return
-
- # good, no system found, so we can add a new one.
- print "# creating new system record"
- handle = server.new_system(token)
- server.modify_system(handle,"profile",profile,token)
- server.modify_system(handle,"name",mac.replace(":","_"),token)
- intf_hash = {
- # FIXME: also include IP info if we have it?
- "macaddress-intf0" : mac
- }
- server.modify_system(handle,"modify-interface",intf_hash,token)
- print "# saving system"
- server.save_system(handle,token)
+ server.register_mac(mac,profile)
#----------------------------------------------------------------------