c911b9140cd04fb0866301a4a795b01d851f61ca
[certmaster.git] / certmaster / minion / modules / func_module.py.orig
1 ##
2 ## Copyright 2007, Red Hat, Inc
3 ## see AUTHORS
4 ##
5 ## This software may be freely redistributed under the terms of the GNU
6 ## general public license.
7 ##
8 ## You should have received a copy of the GNU General Public License
9 ## along with this program; if not, write to the Free Software
10 ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
11 ##
12
13 import inspect
14
15 from func import logger
16 from func.config import read_config
17 from func.commonconfig import FuncdConfig
18
19
20 class FuncModule(object):
21
22 # the version is meant to
23 version = "0.0.0"
24 api_version = "0.0.0"
25 description = "No Description provided"
26
27 def __init__(self):
28
29 config_file = '/etc/func/minion.conf'
30 self.config = read_config(config_file, FuncdConfig)
31 self.__init_log()
32 self.__base_methods = {
33 # __'s so we don't clobber useful names
34 "module_version" : self.__module_version,
35 "module_api_version" : self.__module_api_version,
36 "module_description" : self.__module_description,
37 "list_methods" : self.__list_methods
38 }
39
40 def __init_log(self):
41 log = logger.Logger()
42 self.logger = log.logger
43
44 def register_rpc(self, handlers, module_name):
45 # add the internal methods, note that this means they
46 # can get clobbbered by subclass versions
47 for meth in self.__base_methods:
48 handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth]
49
50 # register all methods that don't start with an underscore
51 for attr in dir(self):
52 if inspect.ismethod(getattr(self, attr)) and attr[0] != '_':
53 handlers["%s.%s" % (module_name, attr)] = getattr(self, attr)
54
55 def __list_methods(self):
56 return self.methods.keys() + self.__base_methods.keys()
57
58 def __module_version(self):
59 return self.version
60
61 def __module_api_version(self):
62 return self.api_version
63
64 def __module_description(self):
65 return self.description