summaryrefslogtreecommitdiffstats
path: root/ipaclient/remote_plugins/schema.py
diff options
context:
space:
mode:
Diffstat (limited to 'ipaclient/remote_plugins/schema.py')
-rw-r--r--ipaclient/remote_plugins/schema.py120
1 files changed, 18 insertions, 102 deletions
diff --git a/ipaclient/remote_plugins/schema.py b/ipaclient/remote_plugins/schema.py
index da917a984..8ce26e608 100644
--- a/ipaclient/remote_plugins/schema.py
+++ b/ipaclient/remote_plugins/schema.py
@@ -16,12 +16,11 @@ import zipfile
import six
-from ipaclient.plugins.rpcclient import rpcclient
+from ipaclient.frontend import ClientCommand, ClientMethod
from ipalib import errors, parameters, plugable
-from ipalib.frontend import Command, Method, Object
+from ipalib.frontend import Object
from ipalib.output import Output
from ipalib.parameters import DefaultFrom, Flag, Password, Str
-from ipalib.text import _
from ipapython.dn import DN
from ipapython.dnsutil import DNSName
from ipapython.ipa_log_manager import log_mgr
@@ -70,92 +69,11 @@ SERVERS_DIR = os.path.join(USER_CACHE_PATH, 'ipa', 'servers')
logger = log_mgr.get_logger(__name__)
-class _SchemaCommand(Command):
- def get_options(self):
- skip = set()
- for option in super(_SchemaCommand, self).get_options():
- if option.name in skip:
- continue
- if option.name in ('all', 'raw'):
- skip.add(option.name)
- yield option
+class _SchemaCommand(ClientCommand):
+ pass
-class _SchemaMethod(Method, _SchemaCommand):
- _failed_member_output_params = (
- # baseldap
- Str(
- 'member',
- label=_("Failed members"),
- ),
- Str(
- 'sourcehost',
- label=_("Failed source hosts/hostgroups"),
- ),
- Str(
- 'memberhost',
- label=_("Failed hosts/hostgroups"),
- ),
- Str(
- 'memberuser',
- label=_("Failed users/groups"),
- ),
- Str(
- 'memberservice',
- label=_("Failed service/service groups"),
- ),
- Str(
- 'failed',
- label=_("Failed to remove"),
- flags=['suppress_empty'],
- ),
- Str(
- 'ipasudorunas',
- label=_("Failed RunAs"),
- ),
- Str(
- 'ipasudorunasgroup',
- label=_("Failed RunAsGroup"),
- ),
- # caacl
- Str(
- 'ipamembercertprofile',
- label=_("Failed profiles"),
- ),
- Str(
- 'ipamemberca',
- label=_("Failed CAs"),
- ),
- # host
- Str(
- 'managedby',
- label=_("Failed managedby"),
- ),
- # service
- Str(
- 'ipaallowedtoperform_read_keys',
- label=_("Failed allowed to retrieve keytab"),
- ),
- Str(
- 'ipaallowedtoperform_write_keys',
- label=_("Failed allowed to create keytab"),
- ),
- # servicedelegation
- Str(
- 'failed_memberprincipal',
- label=_("Failed members"),
- ),
- Str(
- 'ipaallowedtarget',
- label=_("Failed targets"),
- ),
- # vault
- Str(
- 'owner?',
- label=_("Failed owners"),
- ),
- )
-
+class _SchemaMethod(ClientMethod):
@property
def obj_name(self):
return self.api.Object[self.obj_full_name].name
@@ -164,15 +82,6 @@ class _SchemaMethod(Method, _SchemaCommand):
def obj_version(self):
return self.api.Object[self.obj_full_name].version
- def get_output_params(self):
- seen = set()
- for output_param in super(_SchemaMethod, self).get_output_params():
- seen.add(output_param.name)
- yield output_param
- for output_param in self._failed_member_output_params:
- if output_param.name not in seen:
- yield output_param
-
class _SchemaObject(Object):
pass
@@ -407,6 +316,10 @@ class _SchemaNameSpace(collections.Mapping):
return len(list(self._schema.iter_namespace(self.name)))
+class NotAvailable(Exception):
+ pass
+
+
class Schema(object):
"""
Store and provide schema for commands and topics
@@ -443,8 +356,9 @@ class Schema(object):
def _in_cache(cls, fingeprint):
return os.path.exists(cls.schema_path_template.format(fingeprint))
- def __init__(self, api):
+ def __init__(self, api, client):
self._api = api
+ self._client = client
self._dict = {}
def _open_server_info(self, hostname, mode):
@@ -453,9 +367,9 @@ class Schema(object):
return open(path, mode)
def _get_schema(self):
- client = rpcclient(self._api)
- client.finalize()
- client.connect(verbose=False)
+ client = self._client
+ if not client.isconnected():
+ client.connect(verbose=False)
fps = [unicode(f) for f in Schema._list()]
kwargs = {u'version': u'2.170'}
@@ -463,6 +377,8 @@ class Schema(object):
kwargs[u'known_fingerprints'] = fps
try:
schema = client.forward(u'schema', **kwargs)['result']
+ except errors.CommandError:
+ raise NotAvailable()
except errors.SchemaUpToDate as e:
fp = e.fingerprint
ttl = e.ttl
@@ -561,11 +477,11 @@ class Schema(object):
yield r.groups('name')[0]
-def get_package(api):
+def get_package(api, client):
try:
schema = api._schema
except AttributeError:
- schema = Schema(api)
+ schema = Schema(api, client)
object.__setattr__(api, '_schema', schema)
fingerprint = str(schema['fingerprint'])