summaryrefslogtreecommitdiffstats
path: root/cobbler
diff options
context:
space:
mode:
authorMichael DeHaan <mdehaan@redhat.com>2008-04-16 18:37:48 -0400
committerMichael DeHaan <mdehaan@redhat.com>2008-04-16 18:37:48 -0400
commit143f4e068dc1a7e2f5b7196bcfc9a7317bf11fcc (patch)
treebfaea8d0d0bec60d0e2c5755b3badd78fb49db2d /cobbler
parent30f0d9f1f5e3ebe897c0786f52e2f404cd88b737 (diff)
downloadthird_party-cobbler-143f4e068dc1a7e2f5b7196bcfc9a7317bf11fcc.tar.gz
third_party-cobbler-143f4e068dc1a7e2f5b7196bcfc9a7317bf11fcc.tar.xz
third_party-cobbler-143f4e068dc1a7e2f5b7196bcfc9a7317bf11fcc.zip
This is the new status engine in progress. I still need to do some things to parse out
times and indicate how long installs have been active (so there is an easier way to grep for last installs). Technically this will also provide ways of looking at an install history which is probably something we could add if it was interesting. Lots of options.
Diffstat (limited to 'cobbler')
-rw-r--r--cobbler/action_status.py295
-rw-r--r--cobbler/api.py4
-rw-r--r--cobbler/item_repo.py7
-rw-r--r--cobbler/modules/cli_misc.py2
-rw-r--r--cobbler/utils.py3
5 files changed, 117 insertions, 194 deletions
diff --git a/cobbler/action_status.py b/cobbler/action_status.py
index 703bf41..cd76a39 100644
--- a/cobbler/action_status.py
+++ b/cobbler/action_status.py
@@ -2,7 +2,7 @@
Reports on kickstart activity by examining the logs in
/var/log/cobbler.
-Copyright 2007, Red Hat, Inc
+Copyright 2007-2008, Red Hat, Inc
Michael DeHaan <mdehaan@redhat.com>
This software may be freely redistributed under the terms of the GNU
@@ -19,7 +19,7 @@ import glob
import time
import api as cobbler_api
-from utils import _
+#from utils import _
class BootStatusReport:
@@ -30,207 +30,126 @@ class BootStatusReport:
"""
self.config = config
self.settings = config.settings()
+ self.ip_data = {}
self.mode = mode
# -------------------------------------------------------
- def scan_apache_logfiles(self):
- results = {}
- files = [ "/var/log/httpd/access_log" ]
- for x in range(1,4):
- consider = "/var/log/httpd/access_log.%s" % x
- if os.path.exists(consider):
- files.append(consider)
- for fname in files:
- fh = open(fname)
- data = fh.readline()
- while (data is not None and data != ""):
- data = fh.readline()
- tokens = data.split(None)
- if len(tokens) < 6:
- continue
- ip = tokens[0]
- stime = tokens[3].replace("[","")
- req = tokens[6]
- if req.find("/cblr") == -1:
- continue
- ttime = time.strptime(stime,"%d/%b/%Y:%H:%M:%S")
- itime = time.mktime(ttime)
- if not results.has_key(ip):
- results[ip] = {}
- results[ip][itime] = req
-
- return results
-
- # -------------------------------------------------------
-
- def scan_syslog_logfiles(self):
-
- # find all of the logged IP addrs
- filelist = glob.glob("/var/log/cobbler/syslog/*")
- filelist.sort()
- results = {}
-
- for fullname in filelist:
- #fname = os.path.basename(fullname)
- logfile = open(fullname, "r")
- # for each line in the file...
- data = logfile.readline()
- while(data is not None and data != ""):
- data = logfile.readline()
-
- try:
- (epoch, strdate, ip, request) = data.split("\t", 3)
- epoch = float(epoch)
- except:
- continue
-
- if not results.has_key(ip):
- results[ip] = {}
- results[ip][epoch] = request
-
- return results
-
- # -------------------------------------------------------
+ def scan_logfiles(self):
- def run(self):
- """
- Calculate and print a kickstart-status report.
- For kickstart trees not in /var/lib/cobbler (or a symlink off of there)
- tracking will be incomplete. This should be noted in the docs.
- """
+ #profile foosball ? 127.0.0.1 start 1208294043.58
+ #system neo ? 127.0.0.1 start 1208295122.86
- print "NOTE: this function is being replaced right now. Stay tuned!"
- return 0
+ files = glob.glob("/var/log/cobbler/install.log*")
+ for fname in files:
+ fd = open(fname)
+ data = fd.read()
+ for line in data.split("\n"):
+ tokens = line.split()
+ if len(tokens) == 0:
+ continue
+ (profile_or_system, name, mac, ip, start_or_stop, ts) = tokens
+ self.catalog(profile_or_system,name,mac,ip,start_or_stop,ts)
+ fd.close()
+
+ # ------------------------------------------------------
+
+ def catalog(self,profile_or_system,name,mac,ip,start_or_stop,ts):
+ ip_data = self.ip_data
+
+ if not ip_data.has_key(ip):
+ ip_data[ip] = {}
+ elem = ip_data[ip]
+
+ ts = float(ts)
+
+ if not elem.has_key("most_recent_start"):
+ elem["most_recent_start"] = -1
+ if not elem.has_key("most_recent_stop"):
+ elem["most_recent_stop"] = -1
+ if not elem.has_key("most_recent_target"):
+ elem["most_recent_target"] = "?"
+ if not elem.has_key("seen_start"):
+ elem["seen_start"] = 0
+ if not elem.has_key("seen_stop"):
+ elem["seen_stop"] = 0
+ if not elem.has_key("mac"):
+ elem["mac"] = "?"
+
+ mrstart = elem["most_recent_start"]
+ mrstop = elem["most_recent_stop"]
+ mrtarg = elem["most_recent_target"]
+ snstart = elem["seen_start"]
+ snstop = elem["seen_stop"]
+ snmac = elem["mac"]
+
+
+ if start_or_stop == "start":
+ if mrstart < ts:
+ mrstart = ts
+ mrtarg = "%s:%s" % (profile_or_system, name)
+ snmac = mac
+ elem["seen_start"] = elem["seen_start"] + 1
+
+ if start_or_stop == "stop":
+ if mrstop < ts:
+ mrstop = ts
+ mrtarg = "%s:%s" % (profile_or_system, name)
+ snmac = mac
+ elem["seen_stop"] = elem["seen_stop"] + 1
+
+ elem["most_recent_start"] = mrstart
+ elem["most_recent_stop"] = mrstop
+ elem["most_recent_target"] = mrtarg
+ elem["mac"] = mac
+ # -------------------------------------------------------
- api = cobbler_api.BootAPI()
+ def process_results(self):
+ # FIXME: this should update the times here
+ print "DEBUG: %s" % self.ip_data
+ return self.ip_data
- apache_results = self.scan_apache_logfiles()
- syslog_results = self.scan_syslog_logfiles()
- ips = apache_results.keys()
+ def get_printable_results(self):
+ # ip | last mac | last target | start | stop | count
+ format = "%-15s %-17s %-20s %-17s %-17s %5s"
+ ip_data = self.ip_data
+ ips = ip_data.keys()
ips.sort()
- ips2 = syslog_results.keys()
- ips2.sort()
-
- ips.extend(ips2)
- ip_printed = {}
-
- last_recorded_time = 0
- time_collisions = 0
-
- #header = ("Name", "State", "Started", "Last Request", "Seconds", "Log Entries")
- print "%-20s | %-15s | %-25s | %-25s | %-10s | %-6s" % (
- _("Name"),
- _("State"),
- _("Last Request"),
- _("Started"),
- _("Seconds"),
- _("Log Entries")
+ line = (
+ "ip",
+ "mac",
+ "target",
+ "start",
+ "stop",
+ "count",
)
-
-
+ print "DEBUG:", line
+ buf = format % line
for ip in ips:
- if ip_printed.has_key(ip):
- continue
- ip_printed[ip] = 1
- entries = {} # hash of access times and messages
- if apache_results.has_key(ip):
- times = apache_results[ip].keys()
- for logtime in times:
- request = apache_results[ip][logtime]
- if request.find("?system_done") != -1:
- entries[logtime] = "DONE"
- elif request.find("?profile_done") != -1:
- entries[logtime] = "DONE"
- else:
- entries[logtime] = "1" # don't really care what the filename was
-
- if syslog_results.has_key(ip):
- times = syslog_results[ip].keys()
- for logtime in times:
- request = syslog_results[ip][logtime]
- if request.find("methodcomplete") != -1:
- entries[logtime] = "DONE"
- elif request.find("Method =") != -1:
- entries[logtime] = "START"
- else:
- entries[logtime] = "1"
-
- obj = api.systems().find(ip_address=ip)
-
- if obj is not None:
- self.generate_report(entries,obj.name)
- else:
- self.generate_report(entries,ip)
-
- return True
+ elem = ip_data[ip]
+ line = (
+ ip,
+ elem["mac"],
+ elem["most_recent_target"],
+ elem["most_recent_start"], # clean up
+ elem["most_recent_stop"], # clean up
+ elem["seen_stop"]
+ )
+ print "DEBUG: ", line
+ buf = buf + "\n" + format % line
+ return buf
- #-----------------------------------------
+ # -------------------------------------------------------
- def generate_report(self,entries,name):
+ def run(self):
"""
- Given the information about transferred files and kickstart finish times, attempt
- to produce a report that most describes the state of the system.
+ Calculate and print a kickstart-status report.
"""
- # sort the access times
- rtimes = entries.keys()
- rtimes.sort()
-
- # variables for calculating kickstart state
- last_request_time = 0
- last_start_time = 0
- last_done_time = 0
- fcount = 0
-
- if len(rtimes) == 0:
- print _("%s: ?") % name
- return
-
- # for each request time the machine has made
- for rtime in rtimes:
-
- rtime = rtime
- fname = entries[rtime]
-
- if fname == "START":
- install_state = "installing"
- last_start_time = rtime
- last_request_time = rtime
- fcount = 0
- elif fname == "DONE":
- # kickstart finished
- last_done_time = rtime
- install_state = "done"
- else:
- install_state = "?"
- last_request_time = rtime
- fcount = fcount + 1
-
- # calculate elapsed time for kickstart
- elapsed_time = 0
- if install_state == "done":
- elapsed_time = int(last_done_time - last_start_time)
- else:
- elapsed_time = int(last_request_time - last_start_time)
-
- # FIXME: IP to MAC mapping where cobbler knows about it would be nice.
- display_start = time.asctime(time.localtime(last_start_time))
- display_last = time.asctime(time.localtime(last_request_time))
-
- if display_start.find(" 1969") != -1:
- display_start = "?"
- elapsed_time = "?"
-
- # print the status line for this IP address
- print "%-20s | %-15s | %-25s | %-25s | %-10s | %-6s" % (
- name,
- install_state,
- display_start,
- display_last,
- elapsed_time,
- fcount
- )
-
+
+ self.scan_logfiles()
+ self.process_results()
+ print self.get_printable_results()
+ return True
diff --git a/cobbler/api.py b/cobbler/api.py
index ef6fa8e..6f7d1b1 100644
--- a/cobbler/api.py
+++ b/cobbler/api.py
@@ -332,8 +332,8 @@ class BootAPI:
return reposync.run(name)
def status(self,mode):
- self.log("status",[mode])
- statusifier = action_status.BootStatusReport(self._config, mode)
+ self.log("status")
+ statusifier = action_status.BootStatusReport(self._config,mode)
return statusifier.run()
def import_tree(self,mirror_url,mirror_name,network_root=None,kickstart_file=None,rsync_flags=None,arch=None):
diff --git a/cobbler/item_repo.py b/cobbler/item_repo.py
index f9e9714..b87528d 100644
--- a/cobbler/item_repo.py
+++ b/cobbler/item_repo.py
@@ -66,6 +66,13 @@ class Repo(item.Item):
reposync/repotrack integration over HTTP might come later.
"""
self.mirror = mirror
+ if self.arch is None or self.arch == "":
+ if mirror.find("x86_64") != -1:
+ self.set_arch("x86_64")
+ elif mirror.find("x86") != -1 or mirror.find("i386") != -1:
+ self.set_arch("x86")
+ elif mirror.find("ia64") != -1:
+ self.set_arch("ia64")
return True
def set_keep_updated(self,keep_updated):
diff --git a/cobbler/modules/cli_misc.py b/cobbler/modules/cli_misc.py
index f8b0a7d..af2f6b2 100644
--- a/cobbler/modules/cli_misc.py
+++ b/cobbler/modules/cli_misc.py
@@ -200,7 +200,7 @@ class StatusFunction(commands.CobblerFunction):
return "status"
def run(self):
- return self.api.status("text") # no other output modes supported yet
+ return self.api.status("text") # no other output modes supported yet
########################################################
diff --git a/cobbler/utils.py b/cobbler/utils.py
index 0f09345..7bd37ad 100644
--- a/cobbler/utils.py
+++ b/cobbler/utils.py
@@ -467,9 +467,6 @@ def fix_mod_python_select_submission(repos):
which doesn't seem to happen on all versions of python/mp.
"""
- if str(repos).find("Field(") == -1:
- return repos # no hack needed
-
# should be nice regex, but this is readable :)
repos = str(repos)
repos = repos.replace("'repos'","")