2 ## Copyright 2007, Red Hat, Inc
5 ## This software may be freely redistributed under the terms of the GNU
6 ## general public license.
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.
15 from func
import logger
16 from func
.config
import read_config
17 from func
.commonconfig
import FuncdConfig
20 class FuncModule(object):
22 # the version is meant to
25 description
= "No Description provided"
29 config_file
= '/etc/func/minion.conf'
30 self
.config
= read_config(config_file
, FuncdConfig
)
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
42 self
.logger
= log
.logger
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
]
50 # register our module's handlers
51 for name
, handler
in self
.__list
_handlers
().items():
52 handlers
["%s.%s" % (module_name
, name
)] = handler
54 def __list_handlers(self
):
55 """ Return a dict of { handler_name, method, ... }.
56 All methods that do not being with an underscore will be exposed.
57 We also make sure to not expose our register_rpc method.
60 for attr
in dir(self
):
61 if inspect
.ismethod(getattr(self
, attr
)) and attr
[0] != '_' and \
62 attr
!= 'register_rpc':
63 handlers
[attr
] = getattr(self
, attr
)
66 def __list_methods(self
):
67 return self
.__list
_handlers
().keys() + self
.__base
_methods
.keys()
69 def __module_version(self
):
72 def __module_api_version(self
):
73 return self
.api_version
75 def __module_description(self
):
76 return self
.description