From 71d051435420f49f915aab8895d3ca4396c8ccc8 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Thu, 17 Apr 2008 16:42:50 -0400 Subject: (A) The Python-yaml open source code that we had been using apparently didn't have copyright headers (not sure why, we absolutely positively want them there) so I'm adding them now. Similarly, I have included a copy of the license of the library in the docs directory. (B) This checkin also includes some work on the status command. --- cobbler/action_status.py | 85 ++++++++++++++++++++++++-------------------- cobbler/yaml/__init__.py | 6 ++++ cobbler/yaml/dump.py | 7 ++++ cobbler/yaml/implicit.py | 6 ++++ cobbler/yaml/inline.py | 6 ++++ cobbler/yaml/klass.py | 6 ++++ cobbler/yaml/load.py | 6 ++++ cobbler/yaml/ordered_dict.py | 7 ++++ cobbler/yaml/redump.py | 6 ++++ cobbler/yaml/stream.py | 6 ++++ cobbler/yaml/timestamp.py | 7 ++++ cobbler/yaml/ypath.py | 7 ++++ 12 files changed, 117 insertions(+), 38 deletions(-) (limited to 'cobbler') diff --git a/cobbler/action_status.py b/cobbler/action_status.py index cd76a39..df5062e 100644 --- a/cobbler/action_status.py +++ b/cobbler/action_status.py @@ -21,9 +21,18 @@ import api as cobbler_api #from utils import _ +# ARRAY INDEXES +MOST_RECENT_START = 0 +MOST_RECENT_STOP = 1 +MOST_RECENT_TARGET = 2 +SEEN_START = 3 +SEEN_STOP = 4 +MAC = 5 +STATE = 6 class BootStatusReport: + def __init__(self,config,mode): """ Constructor @@ -59,30 +68,17 @@ class BootStatusReport: ip_data = self.ip_data if not ip_data.has_key(ip): - ip_data[ip] = {} + ip_data[ip] = [ -1, -1, "?", 0, 0, "?", "?" ] 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"] + + 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": @@ -90,30 +86,47 @@ class BootStatusReport: mrstart = ts mrtarg = "%s:%s" % (profile_or_system, name) snmac = mac - elem["seen_start"] = elem["seen_start"] + 1 + 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[SEEN_STOP] = elem[SEEN_STOP] + 1 - elem["most_recent_start"] = mrstart - elem["most_recent_stop"] = mrstop - elem["most_recent_target"] = mrtarg - elem["mac"] = mac + elem[MOST_RECENT_START] = mrstart + elem[MOST_RECENT_STOP] = mrstop + elem[MOST_RECENT_TARGET] = mrtarg + elem[MAC] = mac # ------------------------------------------------------- def process_results(self): # FIXME: this should update the times here - print "DEBUG: %s" % self.ip_data + + tnow = int(time.time()) + for ip in self.ip_data.keys(): + elem = self.ip_data[ip] + + start = int(elem[MOST_RECENT_START]) + stop = int(elem[MOST_RECENT_STOP]) + if (stop > start): + elem[STATE] = "finished" + else: + delta = tnow - start + min = delta / 60 + sec = delta % 60 + if min > 100: + elem[STATE] = "unknown/stalled" + else: + elem[STATE] = "installing (%sm %ss)" % (min,sec) + return self.ip_data def get_printable_results(self): # ip | last mac | last target | start | stop | count - format = "%-15s %-17s %-20s %-17s %-17s %5s" + format = "%-15s|%-17s|%-20s|%-17s|%-17s" ip_data = self.ip_data ips = ip_data.keys() ips.sort() @@ -122,22 +135,18 @@ class BootStatusReport: "mac", "target", "start", - "stop", - "count", + "state", ) - print "DEBUG:", line buf = format % line for ip in ips: 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"] + elem[MAC], + elem[MOST_RECENT_TARGET], + time.ctime(elem[MOST_RECENT_START]), + elem[STATE] ) - print "DEBUG: ", line buf = buf + "\n" + format % line return buf diff --git a/cobbler/yaml/__init__.py b/cobbler/yaml/__init__.py index 419d1f3..bd21b40 100644 --- a/cobbler/yaml/__init__.py +++ b/cobbler/yaml/__init__.py @@ -1,3 +1,9 @@ +""" +pyyaml legacy +Copyright (c) 2001 Steve Howell and Friends; All Rights Reserved +(see open source license information in docs/ directory) +""" + __version__ = "0.32" from load import loadFile, load, Parser, l from dump import dump, dumpToFile, Dumper, d diff --git a/cobbler/yaml/dump.py b/cobbler/yaml/dump.py index b8e9d79..eb34955 100644 --- a/cobbler/yaml/dump.py +++ b/cobbler/yaml/dump.py @@ -1,3 +1,10 @@ +""" +pyyaml legacy +Copyright (c) 2001 Steve Howell and Friends; All Rights Reserved +(see open source license information in docs/ directory) +""" + + import types import string from types import StringType, UnicodeType, IntType, FloatType diff --git a/cobbler/yaml/implicit.py b/cobbler/yaml/implicit.py index 6172564..49d65e0 100644 --- a/cobbler/yaml/implicit.py +++ b/cobbler/yaml/implicit.py @@ -1,3 +1,9 @@ +""" +pyyaml legacy +Copyright (c) 2001 Steve Howell and Friends; All Rights Reserved +(see open source license information in docs/ directory) +""" + import re import string from timestamp import timestamp, matchTime diff --git a/cobbler/yaml/inline.py b/cobbler/yaml/inline.py index 8e647de..d4f6439 100644 --- a/cobbler/yaml/inline.py +++ b/cobbler/yaml/inline.py @@ -1,3 +1,9 @@ +""" +pyyaml legacy +Copyright (c) 2001 Steve Howell and Friends; All Rights Reserved +(see open source license information in docs/ directory) +""" + import re import string diff --git a/cobbler/yaml/klass.py b/cobbler/yaml/klass.py index edcf5a8..c182fcf 100644 --- a/cobbler/yaml/klass.py +++ b/cobbler/yaml/klass.py @@ -1,3 +1,9 @@ +""" +pyyaml legacy +Copyright (c) 2001 Steve Howell and Friends; All Rights Reserved +(see open source license information in docs/ directory) +""" + import new import re diff --git a/cobbler/yaml/load.py b/cobbler/yaml/load.py index 259178d..54931d6 100644 --- a/cobbler/yaml/load.py +++ b/cobbler/yaml/load.py @@ -1,3 +1,9 @@ +""" +pyyaml legacy +Copyright (c) 2001 Steve Howell and Friends; All Rights Reserved +(see open source license information in docs/ directory) +""" + import re, string from implicit import convertImplicit from inline import InlineTokenizer diff --git a/cobbler/yaml/ordered_dict.py b/cobbler/yaml/ordered_dict.py index b3788b7..5bc2e3e 100644 --- a/cobbler/yaml/ordered_dict.py +++ b/cobbler/yaml/ordered_dict.py @@ -1,3 +1,10 @@ +""" +pyyaml legacy +Copyright (c) 2001 Steve Howell and Friends; All Rights Reserved +(see open source license information in docs/ directory) +""" + + # This is extremely crude implementation of an OrderedDict. # If you know of a better implementation, please send it to # the author Steve Howell. You can find my email via diff --git a/cobbler/yaml/redump.py b/cobbler/yaml/redump.py index 56ea958..eefd68e 100644 --- a/cobbler/yaml/redump.py +++ b/cobbler/yaml/redump.py @@ -1,3 +1,9 @@ +""" +pyyaml legacy +Copyright (c) 2001 Steve Howell and Friends; All Rights Reserved +(see open source license information in docs/ directory) +""" + from ordered_dict import OrderedDict from load import Parser from dump import Dumper diff --git a/cobbler/yaml/stream.py b/cobbler/yaml/stream.py index cc78c4b..dcd65c3 100644 --- a/cobbler/yaml/stream.py +++ b/cobbler/yaml/stream.py @@ -1,3 +1,9 @@ +""" +pyyaml legacy +Copyright (c) 2001 Steve Howell and Friends; All Rights Reserved +(see open source license information in docs/ directory) +""" + import re import string diff --git a/cobbler/yaml/timestamp.py b/cobbler/yaml/timestamp.py index abcb2e6..5c522f6 100644 --- a/cobbler/yaml/timestamp.py +++ b/cobbler/yaml/timestamp.py @@ -1,3 +1,10 @@ +""" +pyyaml legacy +Copyright (c) 2001 Steve Howell and Friends; All Rights Reserved +(see open source license information in docs/ directory) +""" + + import time, re, string from types import ListType, TupleType diff --git a/cobbler/yaml/ypath.py b/cobbler/yaml/ypath.py index 51d9d2f..b183a23 100644 --- a/cobbler/yaml/ypath.py +++ b/cobbler/yaml/ypath.py @@ -1,3 +1,10 @@ +""" +pyyaml legacy +Copyright (c) 2001 Steve Howell and Friends; All Rights Reserved +(see open source license information in docs/ directory) +""" + + from types import ListType, StringType, IntType, DictType, InstanceType import re from urllib import quote -- cgit