abstracted lish job printing

This commit is contained in:
RafTim 2013-10-20 01:20:27 +02:00
commit 4d7ded5e51
3 changed files with 31 additions and 10 deletions

View file

@ -240,6 +240,8 @@ class FullConfigParser(ConfigParser):
creator = lambda name, values: HostGroup(name, **values)
self.hostgroups = self._create_raw_Object(self.dict[KEY_HOSTGROUPS], "Hostgroup", creator)
creator = parsePeriodList
periods = self._create_raw_Object(self.dict[KEY_PERIODS], "Period", creator)

View file

@ -19,6 +19,7 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from collections import OrderedDict
class LinspectorInterface(object):
@ -37,10 +38,25 @@ class LinspectorInterface(object):
return self.jobHex
def find_job_by_hex_string(self, hexString):
if hexString is None:
return None
for job in self.jobs:
if job.hex_string() == hexString:
return job
def get_job_info_dict(self, job):
d = OrderedDict()
d["Job"] = job.hex_string()
d["Hostgroup"] = job.hostgroup.get_name()
d["Host"] = job.host
d["Service"] = str(job.service)
d["Members"] = str([member.name for member in job.members])
d["Interval"] = str(job.job.trigger)
d["Next run"] = str(job.job.next_run_time)
d["Enabled"] = str(job._enabled)
d["Fails"] = str(job.jobThreshold)
return d
def get_enabled_layouts(self):
self._config.get_enabled_layouts()

View file

@ -186,17 +186,19 @@ class LishCommander(Exit, ShellCommander, LogCommander):
def help_python(self):
print "executes python using 'exec'."
def print_color(self, color, text):
print color + str(text) + END
def print_dict(self, dict):
for key, val in dict.items():
tab = ":\t"
if len(str(key)) < 7:
tab += "\t"
print str(key) + tab + str(val)
def print_jobs_infos(self, job):
#TODO: fix the output for "interval" and "next run"
print "Job:\t\t" + job.hex_string() + "\n" + \
"Hostgroup:\t" + job.hostgroup.get_name() + "\n" + \
"Host:\t\t" + job.host + "\n" + \
"Service:\t" + str(job.service) + "\n" + \
"Members:\t" + str([member.name for member in job.members]) + "\n" + \
"Interval:\t" + str(job.job.trigger) + "\n" + \
"Next run:\t" + str(job.job.next_run_time) + "\n" + \
"Enabled:\t" + str(job._enabled) + "\n" + \
"Fails:\t\t" + str(job.jobThreshold)
self.print_dict(self.interface.get_job_info_dict(job))
def do_job(self, text):
text = shsplit(text)
@ -206,6 +208,7 @@ class LishCommander(Exit, ShellCommander, LogCommander):
if job is None:
print RED + "first parameter must be a job hex id! get a List of all ids by typing 'jobs list'\n" + END
self.help_job()
return
if len(text) == 1:
self.print_jobs_infos(job)