From ef526c98c51ff39a7ead893d976a19247db4132b Mon Sep 17 00:00:00 2001 From: "Rafael.Timmerberg" Date: Tue, 18 Jun 2013 01:50:01 +0200 Subject: [PATCH] added rest --- lib/config/parser.py | 2 +- lib/processors/processor.py | 8 +++++ lib/tasks/task.py | 60 +++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 lib/processors/processor.py create mode 100644 lib/tasks/task.py diff --git a/lib/config/parser.py b/lib/config/parser.py index ee9174a..9d3b6dc 100644 --- a/lib/config/parser.py +++ b/lib/config/parser.py @@ -13,7 +13,7 @@ from lib.services.service import Service from lib.processors.processor import Processor from lib.parsers.parser import Parser from lib.tasks.task import Task -from platform import processor + MOD_SERVICES = "services" MOD_PROCESSORS = "processors" diff --git a/lib/processors/processor.py b/lib/processors/processor.py new file mode 100644 index 0000000..df61b44 --- /dev/null +++ b/lib/processors/processor.py @@ -0,0 +1,8 @@ +''' +Created on Jun 16, 2013 + +@author: rafael +''' +class Processor: + def __init__(self): + pass \ No newline at end of file diff --git a/lib/tasks/task.py b/lib/tasks/task.py new file mode 100644 index 0000000..78d8736 --- /dev/null +++ b/lib/tasks/task.py @@ -0,0 +1,60 @@ +''' +Created on Jun 15, 2013 + +@author: Rafael Timmerberg +''' + +class Task: + ''' + Base class for all built-in Tasks. + ''' + + def set_task_type(self, taskType): + ''' + sets the type of this task. + + Be aware! this method can only get called once! + + params: + taskType: the type of this task + ''' + if hasattr(self, "_taskType"): + raise Exception("taskType is only allowed to set once!") + self.taskType = taskType + + def get_task_type(self): + ''' + returns the type set by set_type_task + ''' + return self._taskType + + def execute_task(self, msg): + ''' + this is the method tasks usually override. + It gets called anytime the task should get executed + + default does nothing + + params: + msg: the msg for this task + ''' + pass + + def _execute(self,taskType, msg): + ''' + 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 + + params: + taskType: the type of the fail which is compared with get_task_type() + msg: the error message + + return: + True if execute_task() is called succesfully, else False + ''' + if self.get_task_type() == taskType: + self.execute_task(msg) + return True + return False + \ No newline at end of file