summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/__init__.py7
-rw-r--r--ipalib/frontend.py45
-rw-r--r--ipalib/plugable.py2
3 files changed, 52 insertions, 2 deletions
diff --git a/ipalib/__init__.py b/ipalib/__init__.py
index 57f784721..d822ba595 100644
--- a/ipalib/__init__.py
+++ b/ipalib/__init__.py
@@ -882,7 +882,7 @@ freeIPA.org:
import os
import plugable
from backend import Backend
-from frontend import Command, LocalOrRemote, Updater
+from frontend import Command, LocalOrRemote, Updater, Advice
from frontend import Object, Method, Property
from crud import Create, Retrieve, Update, Delete, Search
from parameters import DefaultFrom, Bool, Flag, Int, Decimal, Bytes, Str, IA5Str, Password, DNParam, DeprecatedParam
@@ -912,9 +912,12 @@ def create_api(mode='dummy'):
- `frontend.Property`
+ - `frontend.Advice`
+
- `backend.Backend`
"""
- api = plugable.API(Command, Object, Method, Property, Backend, Updater)
+ api = plugable.API(Command, Object, Method, Property, Backend, Updater,
+ Advice)
if mode is not None:
api.env.mode = mode
assert mode != 'production'
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index 427f68235..67ca7767c 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -1445,3 +1445,48 @@ class Updater(Method):
)
return self.execute(**options)
+
+
+class _AdviceOutput(object):
+
+ def __init__(self):
+ self.content = []
+ self.prefix = '# '
+ self.options = None
+
+ def comment(self, line):
+ self.content.append(self.prefix + line)
+
+ def debug(self, line):
+ if self.options.verbose:
+ self.comment('DEBUG: ' + line)
+
+ def command(self, line):
+ self.content.append(line)
+
+
+class Advice(Plugin):
+ """
+ Base class for advices, plugins for ipa-advise.
+ """
+
+ options = None
+ require_root = False
+ description = ''
+
+ def __init__(self):
+ super(Advice, self).__init__()
+ self.log = _AdviceOutput()
+
+ def set_options(self, options):
+ self.options = options
+ self.log.options = options
+
+ def get_info(self):
+ """
+ This method should be overriden by child Advices.
+
+ Returns a string with instructions.
+ """
+
+ raise NotImplementedError
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index aaa0dea48..25698d8f5 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -615,6 +615,8 @@ class API(DictProxy):
self.import_plugins('ipaserver')
if self.env.context in ('installer', 'updates'):
self.import_plugins('ipaserver/install/plugins')
+ if self.env.context in ('advise'):
+ self.import_plugins('ipaserver/advise/plugins')
# FIXME: This method has no unit test
def import_plugins(self, package):