summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-11-14 21:29:46 -0700
committerJason Gerard DeRose <jderose@redhat.com>2008-11-14 21:29:46 -0700
commit36737c2d913716eb99aece5cc1f6a21234abe46a (patch)
treef33cdc01d6580f373bc68445d46d866e84c973a9 /ipalib
parent3433840692d294d8c16bd775cfea225b86b4d9e1 (diff)
downloadfreeipa-36737c2d913716eb99aece5cc1f6a21234abe46a.tar.gz
freeipa-36737c2d913716eb99aece5cc1f6a21234abe46a.tar.xz
freeipa-36737c2d913716eb99aece5cc1f6a21234abe46a.zip
Added frontend.LocalOrRemote command base class for commands like env
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/__init__.py3
-rw-r--r--ipalib/frontend.py31
2 files changed, 33 insertions, 1 deletions
diff --git a/ipalib/__init__.py b/ipalib/__init__.py
index 53462cff3..b9a3c96d5 100644
--- a/ipalib/__init__.py
+++ b/ipalib/__init__.py
@@ -873,7 +873,8 @@ freeIPA.org:
import plugable
from backend import Backend, Context
-from frontend import Command, Object, Method, Property, Application
+from frontend import Command, LocalOrRemote, Application
+from frontend import Object, Method, Property
from ipa_types import Bool, Int, Unicode, Enum
from frontend import Param, DefaultFrom
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index 3e04db519..446384a3a 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -782,6 +782,37 @@ class Command(plugable.Plugin):
yield arg
+class LocalOrRemote(Command):
+ """
+ A command that is explicitly executed locally or remotely.
+
+ This is for commands that makes sense to execute either locally or
+ remotely to return a perhaps different result. The best example of
+ this is the `ipalib.plugins.f_misc.env` plugin which returns the
+ key/value pairs describing the configuration state: it can be
+ """
+
+ takes_options = (
+ Param('server', type=ipa_types.Bool(), default=False,
+ doc='Forward to server instead of running locally',
+ ),
+ )
+
+ def run(self, *args, **options):
+ """
+ Dispatch to forward() or execute() based on ``server`` option.
+
+ When running in a client context, this command is executed remotely if
+ ``options['server']`` is true; otherwise it is executed locally.
+
+ When running in a server context, this command is always executed
+ locally and the value of ``options['server']`` is ignored.
+ """
+ if options['server'] and not self.env.in_server:
+ return self.forward(*args, **options)
+ return self.execute(*args, **options)
+
+
class Object(plugable.Plugin):
__public__ = frozenset((
'backend',