summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2009-01-22 15:41:54 -0700
committerRob Crittenden <rcritten@redhat.com>2009-02-03 15:29:01 -0500
commit24b6cb89d443384cb432f01265c45bc18d9cf2fc (patch)
tree50aa6e4b2ce4863d018644026c34085347263c74 /ipalib
parent9f48612a56b6e760aa06a9af2071f1b50f413f27 (diff)
downloadfreeipa-24b6cb89d443384cb432f01265c45bc18d9cf2fc.tar.gz
freeipa-24b6cb89d443384cb432f01265c45bc18d9cf2fc.tar.xz
freeipa-24b6cb89d443384cb432f01265c45bc18d9cf2fc.zip
Further migration toward new xmlrcp code; fixed problem with unicode Fault.faultString; fixed problem where ServerProxy method was not called correctly
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/base.py2
-rw-r--r--ipalib/cli.py9
-rw-r--r--ipalib/frontend.py20
-rw-r--r--ipalib/plugins/misc.py2
-rw-r--r--ipalib/rpc.py19
5 files changed, 33 insertions, 19 deletions
diff --git a/ipalib/base.py b/ipalib/base.py
index bff8f1951..e0951e41e 100644
--- a/ipalib/base.py
+++ b/ipalib/base.py
@@ -455,7 +455,7 @@ class NameSpace(ReadOnly):
:param key: The name or index of a member, or a slice object.
"""
- if type(key) is str:
+ if isinstance(key, basestring):
return self.__map[key]
if type(key) in (int, slice):
return self.__members[key]
diff --git a/ipalib/cli.py b/ipalib/cli.py
index 809c0e551..62b8b9304 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -35,6 +35,7 @@ import struct
import frontend
import backend
import errors
+import errors2
import plugable
import util
from constants import CLI_TAB
@@ -534,9 +535,9 @@ class CLI(object):
print ''
self.api.log.info('operation aborted')
sys.exit()
- except errors.IPAError, e:
- self.api.log.error(unicode(e))
- sys.exit(e.faultCode)
+ except errors2.PublicError, e:
+ self.api.log.error(e.strerror)
+ sys.exit(e.errno)
def run_real(self):
"""
@@ -620,6 +621,8 @@ class CLI(object):
(c.name.replace('_', '-'), c) for c in self.api.Command()
)
self.textui = self.api.Backend.textui
+ if self.api.env.in_server is False and 'xmlclient' in self.api.Backend:
+ self.api.Backend.xmlclient.connect()
def load_plugins(self):
"""
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index 2277c7a09..6efccbb4d 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -96,14 +96,14 @@ class Command(plugable.Plugin):
If not in a server context, the call will be forwarded over
XML-RPC and the executed an the nearest IPA server.
"""
- self.debug(make_repr(self.name, *args, **options))
params = self.args_options_2_params(*args, **options)
params = self.normalize(**params)
params = self.convert(**params)
params.update(self.get_default(**params))
self.validate(**params)
(args, options) = self.params_2_args_options(**params)
- self.debug(make_repr(self.name, *args, **options))
+ # FIXME: don't log passords!
+ self.info(make_repr(self.name, *args, **options))
result = self.run(*args, **options)
self.debug('%s result: %r', self.name, result)
return result
@@ -200,6 +200,11 @@ class Command(plugable.Plugin):
(k, self.params[k].convert(v)) for (k, v) in kw.iteritems()
)
+ def __convert_iter(self, kw):
+ for param in self.params():
+ if kw.get(param.name, None) is None:
+ continue
+
def get_default(self, **kw):
"""
Return a dictionary of defaults for all missing required values.
@@ -245,7 +250,7 @@ class Command(plugable.Plugin):
elif param.required:
raise errors.RequirementError(param.name)
- def run(self, *args, **kw):
+ def run(self, *args, **options):
"""
Dispatch to `Command.execute` or `Command.forward`.
@@ -258,11 +263,8 @@ class Command(plugable.Plugin):
performs is executed remotely.
"""
if self.api.env.in_server:
- target = self.execute
- else:
- target = self.forward
- object.__setattr__(self, 'run', target)
- return target(*args, **kw)
+ return self.execute(*args, **options)
+ return self.forward(*args, **options)
def execute(self, *args, **kw):
"""
@@ -283,7 +285,7 @@ class Command(plugable.Plugin):
"""
Forward call over XML-RPC to this same command on server.
"""
- return self.Backend.xmlrpc.forward_call(self.name, *args, **kw)
+ return self.Backend.xmlclient.forward(self.name, *args, **kw)
def finalize(self):
"""
diff --git a/ipalib/plugins/misc.py b/ipalib/plugins/misc.py
index a2f0fa4e4..327e52b56 100644
--- a/ipalib/plugins/misc.py
+++ b/ipalib/plugins/misc.py
@@ -22,7 +22,7 @@ Misc frontend plugins.
"""
import re
-from ipalib import api, LocalOrRemote
+from ipalib import api, LocalOrRemote, Bytes
diff --git a/ipalib/rpc.py b/ipalib/rpc.py
index e845b8939..aa8002094 100644
--- a/ipalib/rpc.py
+++ b/ipalib/rpc.py
@@ -135,8 +135,13 @@ def xml_dumps(params, methodname=None, methodresponse=False, encoding='UTF-8'):
allow_none=True,
)
+def decode_fault(e, encoding='UTF-8'):
+ assert isinstance(e, Fault)
+ if type(e.faultString) is str:
+ return Fault(e.faultCode, e.faultString.decode(encoding))
+ return e
-def xml_loads(data):
+def xml_loads(data, encoding='UTF-8'):
"""
Decode the XML-RPC packet in ``data``, transparently unwrapping its params.
@@ -159,8 +164,11 @@ def xml_loads(data):
:param data: The XML-RPC packet to decode.
"""
- (params, method) = loads(data)
- return (xml_unwrap(params), method)
+ try:
+ (params, method) = loads(data)
+ return (xml_unwrap(params), method)
+ except Fault, e:
+ raise decode_fault(e)
class KerbTransport(SafeTransport):
@@ -211,8 +219,8 @@ class xmlclient(Backend):
)
)
conn = ServerProxy(self.env.xmlrpc_uri,
- transport=KerbTransport(),
allow_none=True,
+ encoding='UTF-8',
)
setattr(context, self.connection_name, conn)
@@ -243,9 +251,10 @@ class xmlclient(Backend):
command = getattr(context.xmlconn, name)
params = args + (kw,)
try:
- response = command(xml_wrap(params))
+ response = command(*xml_wrap(params))
return xml_unwrap(response)
except Fault, e:
+ e = decode_fault(e)
self.debug('Caught fault %d from server %s: %s', e.faultCode,
self.env.xmlrpc_uri, e.faultString)
if e.faultCode in self.__errors: