abstracted lish job printing
This commit is contained in:
parent
c9c7e7296d
commit
4d7ded5e51
3 changed files with 31 additions and 10 deletions
|
|
@ -240,6 +240,8 @@ class FullConfigParser(ConfigParser):
|
||||||
|
|
||||||
creator = lambda name, values: HostGroup(name, **values)
|
creator = lambda name, values: HostGroup(name, **values)
|
||||||
self.hostgroups = self._create_raw_Object(self.dict[KEY_HOSTGROUPS], "Hostgroup", creator)
|
self.hostgroups = self._create_raw_Object(self.dict[KEY_HOSTGROUPS], "Hostgroup", creator)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
creator = parsePeriodList
|
creator = parsePeriodList
|
||||||
periods = self._create_raw_Object(self.dict[KEY_PERIODS], "Period", creator)
|
periods = self._create_raw_Object(self.dict[KEY_PERIODS], "Period", creator)
|
||||||
|
|
|
||||||
|
|
@ -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
|
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/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
|
||||||
class LinspectorInterface(object):
|
class LinspectorInterface(object):
|
||||||
|
|
@ -37,10 +38,25 @@ class LinspectorInterface(object):
|
||||||
return self.jobHex
|
return self.jobHex
|
||||||
|
|
||||||
def find_job_by_hex_string(self, hexString):
|
def find_job_by_hex_string(self, hexString):
|
||||||
|
if hexString is None:
|
||||||
|
return None
|
||||||
for job in self.jobs:
|
for job in self.jobs:
|
||||||
if job.hex_string() == hexString:
|
if job.hex_string() == hexString:
|
||||||
return job
|
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):
|
def get_enabled_layouts(self):
|
||||||
self._config.get_enabled_layouts()
|
self._config.get_enabled_layouts()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -186,17 +186,19 @@ class LishCommander(Exit, ShellCommander, LogCommander):
|
||||||
def help_python(self):
|
def help_python(self):
|
||||||
print "executes python using 'exec'."
|
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):
|
def print_jobs_infos(self, job):
|
||||||
#TODO: fix the output for "interval" and "next run"
|
self.print_dict(self.interface.get_job_info_dict(job))
|
||||||
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)
|
|
||||||
|
|
||||||
def do_job(self, text):
|
def do_job(self, text):
|
||||||
text = shsplit(text)
|
text = shsplit(text)
|
||||||
|
|
@ -206,6 +208,7 @@ class LishCommander(Exit, ShellCommander, LogCommander):
|
||||||
if job is None:
|
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
|
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()
|
self.help_job()
|
||||||
|
return
|
||||||
|
|
||||||
if len(text) == 1:
|
if len(text) == 1:
|
||||||
self.print_jobs_infos(job)
|
self.print_jobs_infos(job)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue