summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/plugable.py27
-rw-r--r--ipalib/plugins/ping.py8
2 files changed, 32 insertions, 3 deletions
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index 25698d8f5..3be8bb118 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -59,6 +59,33 @@ def is_production_mode(obj):
return obj.env.mode == 'production'
+class Registry(object):
+ """A decorator that makes plugins available to the API
+
+ Usage::
+
+ register = Registry()
+
+ @register()
+ class obj_mod(...):
+ ...
+
+ For forward compatibility, make sure that the module-level instance of
+ this object is named "register".
+ """
+ # TODO: Instead of auto-loading when plugin modules are imported,
+ # plugins should be stored in this object.
+ # The API should examine it and load plugins explicitly.
+ def __call__(self):
+ from ipalib import api
+
+ def decorator(cls):
+ api.register(cls)
+ return cls
+
+ return decorator
+
+
class SetProxy(ReadOnly):
"""
A read-only container with set/sequence behaviour.
diff --git a/ipalib/plugins/ping.py b/ipalib/plugins/ping.py
index 0743758fc..52da5d4bc 100644
--- a/ipalib/plugins/ping.py
+++ b/ipalib/plugins/ping.py
@@ -17,10 +17,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from ipalib import api
from ipalib import Command
from ipalib import output
from ipalib import _, ngettext
+from ipalib.plugable import Registry
from ipapython.version import VERSION, API_VERSION
__doc__ = _("""
@@ -51,6 +51,10 @@ EXAMPLES:
-----------------------------------------------------
""")
+register = Registry()
+
+
+@register()
class ping(Command):
__doc__ = _('Ping a remote server.')
@@ -64,5 +68,3 @@ class ping(Command):
back but a fixed value works for now.
"""
return dict(summary=u'IPA server version %s. API version %s' % (VERSION, API_VERSION))
-
-api.register(ping)