Skip to content

Instantly share code, notes, and snippets.

Last active Dec 18, 2015
What would you like to do?
class XmlRpcInterface(object):
def __init__(self):
cm_config_file = '/etc/certmaster/minion.conf'
self.cm_config = read_config(cm_config_file, CMConfig)
config_file = "/etc/func/minion.conf"
self.config = read_config(config_file, FuncdConfig)
self.logger = logger.Logger().logger
self.audit_logger = logger.AuditLogger()
# need a reference so we can log ip's, certs, etc
# self.server = server
def __setup_handlers(self):
Add RPC functions from each class to the global list so they can be called.
self.handlers = {}
for x in self.modules.keys():
self.modules[x].register_rpc(self.handlers, x)
self.logger.debug("adding %s" % x)
except AttributeError, e:
self.logger.warning("module %s not loaded, missing register_rpc method" % self.modules[x])
# internal methods that we do instead of spreading internal goo
# all over the modules. For now, at lest -akl
# system.listMethods os a quasi stanard xmlrpc method, so
# thats why it has a odd looking name
self.handlers["system.listMethods"] = self.list_methods
self.handlers["system.list_methods"] = self.list_methods
self.handlers["system.list_modules"] = self.list_modules
self.handlers["system.inventory"] = self.inventory
self.handlers["system.grep"] = self.grep
# 添加重载模块的键值
self.handlers["system.reload_modules"] = self.reload_modules
# ultimately need to add a method here to force the server to reload itself so all NEW connections
# get a new RequestHandler
# 实现重载模块的方法
def reload_modules(self):
self.modules = module_loader.load_modules()
# log.logger.debug(self.modules)
return True
def list_modules(self):
modules = self.modules.keys()
return modules
def list_methods(self):
methods = self.handlers.keys()
return methods
import func.minion.modules.func_module as fm
def grep(self,word):
Finding the wanted word
word = word.strip()
modules = self.modules.keys()
methods = self.handlers.keys()
return_dict = {}
#find modules
for m in modules:
if m.find(word)!=-1:
#find methods
for m in methods:
if m.find(word)!=-1:
return return_dict
grep = fm.findout(grep)
def inventory(self):
inventory = {}
# FIXME: it's kind of dumb that we dont have a real object
# to represent which methods are in which classes, just a list
# of modules, and a list of methods. we can match strings to
# see which are where, but that seems lame -akl
for module in self.modules.keys():
inventory[module] = []
for method in self.handlers.keys():
# string match, ick.
method_bits = method.split('.')
method_module = string.join(method_bits[:-1], '.')
method_name = method_bits[-1]
if method_module in inventory:
return inventory
def get_dispatch_method(self, method):
# 不知道如何修改子类FuncSSLXMLRPCServer的变量
# 只能非常暴力地每次执行方法都重装一次
if method in self.handlers:
return FuncApiMethod(self.logger, method, self.handlers[method])
module_name = string.join(method.split('.')[:-1], '.')
if module_name not in self.modules:
self.logger.exception("method %s called but %s module is not available" % (method, module_name))
raise codes.ModuleNotFoundException
self.logger.exception("Unhandled method call for method: %s " % method)
raise codes.InvalidMethodException
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment