linspector-old/lib/tasks/task.py

54 lines
1.5 KiB
Python
Raw Normal View History

2013-06-18 02:58:40 +02:00
"""
2013-06-19 03:26:25 +02:00
The task class.
2013-06-18 02:58:40 +02:00
"""
2013-06-18 01:50:01 +02:00
class Task:
2013-06-18 02:58:40 +02:00
"""
2013-06-18 01:50:01 +02:00
Base class for all built-in Tasks.
2013-06-18 02:58:40 +02:00
"""
2013-06-18 01:50:01 +02:00
def set_task_type(self, taskType):
2013-06-18 02:58:40 +02:00
"""
2013-06-18 01:50:01 +02:00
sets the type of this task.
Be aware! this method can only get called once!
2013-06-19 03:26:25 +02:00
:param taskType: the type of this task
2013-06-18 02:58:40 +02:00
"""
2013-06-18 01:50:01 +02:00
if hasattr(self, "_taskType"):
raise Exception("taskType is only allowed to set once!")
self.taskType = taskType
def get_task_type(self):
2013-06-18 02:58:40 +02:00
"""
2013-06-19 03:26:25 +02:00
:return: the type set by set_type_task
2013-06-18 02:58:40 +02:00
"""
2013-06-18 01:50:01 +02:00
return self._taskType
def execute_task(self, msg):
2013-06-18 02:58:40 +02:00
"""
2013-06-18 01:50:01 +02:00
this is the method tasks usually override.
It gets called anytime the task should get executed
default does nothing
2013-06-19 03:26:25 +02:00
:param msg: the msg for this task
2013-06-18 02:58:40 +02:00
"""
2013-06-18 01:50:01 +02:00
pass
2013-06-18 02:58:40 +02:00
def _execute(self, taskType, msg):
"""
2013-06-18 01:50:01 +02:00
internal method which gets called for any member in a hostgroup.
It determines if it has an appropriate type by comparing taskType with get_task_type().
Calls execute_task() if the type matches
2013-06-19 03:26:25 +02:00
:param taskType: the type of the fail which is compared with get_task_type()
:param msg: the error message
2013-06-18 01:50:01 +02:00
2013-06-19 03:26:25 +02:00
:return: True if execute_task() is called succesfully, else False
2013-06-18 02:58:40 +02:00
"""
2013-06-18 01:50:01 +02:00
if self.get_task_type() == taskType:
self.execute_task(msg)
return True
2013-06-18 02:58:40 +02:00
return False