Backend.xmlrpc and simple-server.py now use the xmlrpc_marshal() and xmlrpc_unmarshal() functions respectively

This commit is contained in:
Jason Gerard DeRose 2008-10-02 19:42:06 -06:00
parent d84e27f0d4
commit 3ffbaac64c
4 changed files with 22 additions and 11 deletions

View File

@ -23,7 +23,7 @@ DEFAULT_CONF='/etc/ipa/ipa.conf'
def generate_env(d={}):
default = dict(
server_context = True,
server_context = False,
query_dns = True,
verbose = False,
servers = LazyIter(get_servers),
@ -35,7 +35,7 @@ def generate_env(d={}):
default[key].set_value(value)
else:
default[key] = value
return default

View File

@ -541,8 +541,10 @@ class Command(plugable.Plugin):
print ' kw =', kw
def forward(self, *args, **kw):
xmlrpc_client = self.api.Backend.xmlrpc.get_client()
return getattr(xmlrpc_client, self.name)(kw, *args)
"""
Forward call over XML-RPC.
"""
return self.api.Backend.xmlrpc.forward_call(self.name, *args, **kw)
def __call__(self, *args, **kw):

View File

@ -25,6 +25,7 @@ Lightwieght XML-RPC client using Python standard library xmlrpclib.
import xmlrpclib
from ipalib.backend import Backend
from ipalib.util import xmlrpc_marshal
from ipalib import api
class xmlrpc(Backend):
@ -36,4 +37,13 @@ class xmlrpc(Backend):
# FIXME: The server uri should come from self.api.env.server_uri
return xmlrpclib.ServerProxy('http://localhost:8080', allow_none=True)
def forward_call(self, name, *args, **kw):
"""
Forward a call over XML-RPC to an IPA server.
"""
client = self.get_client()
command = getattr(client, name)
params = xmlrpc_marshal(*args, **kw)
return command(*params)
api.register(xmlrpc)

View File

@ -26,9 +26,11 @@ The server will run at http://localhost:8080
"""
from SimpleXMLRPCServer import SimpleXMLRPCServer
from ipalib.util import xmlrpc_unmarshal
from ipalib import api
from ipalib import load_plugins
api.env.server_context = True
api.finalize()
class Dispatch(object):
@ -36,15 +38,12 @@ class Dispatch(object):
self.__cmd = cmd
def __call__(self, *params):
if len(params) > 0:
kw = params[0]
else:
kw = {}
args = params[1:]
return cmd(*args, **kw)
print 'dispatch: %s%r' % (self.__cmd.name, params)
(args, kw) = xmlrpc_unmarshal(*params)
return self.__cmd(*args, **kw)
server = SimpleXMLRPCServer(('localhost', 8080))
server = SimpleXMLRPCServer(('localhost', 8080), allow_none=True)
server.register_introspection_functions()
for cmd in api.Command():
server.register_function(Dispatch(cmd), cmd.name)