summaryrefslogtreecommitdiffstats
path: root/ipaclient/remote_plugins
diff options
context:
space:
mode:
authorJan Cholasta <jcholast@redhat.com>2016-06-16 13:21:17 +0200
committerJan Cholasta <jcholast@redhat.com>2016-06-20 16:39:12 +0200
commitec1b3e71b2688eed2264b7b24d9e8fcff938967f (patch)
tree79f670cfd084825743e9e8a1459b70f93a79723c /ipaclient/remote_plugins
parent3ec7a52aea104ce0f37d9204fcba21a42abfc798 (diff)
downloadfreeipa-ec1b3e71b2688eed2264b7b24d9e8fcff938967f.tar.gz
freeipa-ec1b3e71b2688eed2264b7b24d9e8fcff938967f.tar.xz
freeipa-ec1b3e71b2688eed2264b7b24d9e8fcff938967f.zip
schema: add object class schema
Support object classes defined by object plugins in API schema. Added new commands `class-show` and `class-find` to retrieve information about object classes. `param-show` and `param-find` now support both commands and classes. https://fedorahosted.org/freeipa/ticket/4739 Reviewed-By: David Kupka <dkupka@redhat.com>
Diffstat (limited to 'ipaclient/remote_plugins')
-rw-r--r--ipaclient/remote_plugins/schema.py52
1 files changed, 42 insertions, 10 deletions
diff --git a/ipaclient/remote_plugins/schema.py b/ipaclient/remote_plugins/schema.py
index 28c3be7a5..d026d44a4 100644
--- a/ipaclient/remote_plugins/schema.py
+++ b/ipaclient/remote_plugins/schema.py
@@ -10,8 +10,8 @@ import types
import six
from ipaclient.plugins.rpcclient import rpcclient
-from ipalib import Command
from ipalib import parameters, plugable
+from ipalib.frontend import Command, Object
from ipalib.output import Output
from ipalib.parameters import Bool, DefaultFrom, Flag, Password, Str
from ipalib.text import ConcatenatedLazyText
@@ -226,8 +226,23 @@ def _create_command(schema):
return command
-class _LazySchemaCommand(object):
- def __init__(self, schema):
+def _create_class(schema):
+ cls = {}
+ cls['name'] = str(schema['name'])
+ if 'doc' in schema:
+ cls['doc'] = ConcatenatedLazyText(schema['doc'])
+ if 'topic_topic' in schema:
+ cls['topic'] = str(schema['topic_topic'])
+ else:
+ cls['topic'] = None
+ cls['takes_params'] = tuple(_create_param(s) for s in schema['params'])
+
+ return cls
+
+
+class _LazySchemaPlugin(object):
+ def __init__(self, base, schema):
+ self.__base = base
self.__schema = schema
self.__class = None
self.__module__ = None
@@ -236,21 +251,32 @@ class _LazySchemaCommand(object):
def name(self):
return str(self.__schema['name'])
- bases = (_SchemaCommand,)
+ @property
+ def bases(self):
+ if self.__base is Command:
+ return (_SchemaCommand,)
+ else:
+ return (self.__base,)
def __call__(self, api):
if self.__class is None:
- command = _create_command(self.__schema)
- name = command.pop('name')
- command = type(name, (_SchemaCommand,), command)
- command.__module__ = self.__module__
- self.__class = command
+ if self.__base is Command:
+ metaobject = _create_command(self.__schema)
+ else:
+ metaobject = _create_class(self.__schema)
+ metaobject = type(self.name, self.bases, metaobject)
+ metaobject.__module__ = self.__module__
+ self.__class = metaobject
return self.__class(api)
def _create_commands(schema):
- return [_LazySchemaCommand(s) for s in schema]
+ return [_LazySchemaPlugin(Command, s) for s in schema]
+
+
+def _create_classes(schema):
+ return [_LazySchemaPlugin(Object, s) for s in schema]
def _create_topic(schema):
@@ -289,6 +315,7 @@ def get_package(api):
client.disconnect()
commands = _create_commands(schema['commands'])
+ classes = _create_classes(schema['classes'])
topics = _create_topics(schema['topics'])
package = types.ModuleType(package_name)
@@ -308,6 +335,11 @@ def get_package(api):
command = module.register()(command)
setattr(module, command.name, command)
+ for cls in classes:
+ cls.__module__ = module_name
+ cls = module.register()(cls)
+ setattr(module, cls.name, command)
+
for topic in topics:
name = topic.pop('name')
module_name = '.'.join((package_name, name))