advise: Add separate API object for ipa-advise

Reviewed-By: Tomas Babej <tbabej@redhat.com>
This commit is contained in:
Jan Cholasta 2015-02-16 16:34:01 +00:00 committed by Tomas Babej
parent dae6a18813
commit 2625efa727
5 changed files with 79 additions and 82 deletions

View File

@ -882,7 +882,7 @@ freeIPA.org:
import os
import plugable
from backend import Backend
from frontend import Command, LocalOrRemote, Updater, Advice
from frontend import Command, LocalOrRemote, Updater
from frontend import Object, Method
from crud import Create, Retrieve, Update, Delete, Search
from parameters import DefaultFrom, Bool, Flag, Int, Decimal, Bytes, Str, IA5Str, Password, DNParam, DeprecatedParam
@ -909,8 +909,6 @@ class API(plugable.API):
self.packages.append('ipaserver')
if self.env.context in ('installer', 'updates'):
self.packages.append('ipaserver/install/plugins')
if self.env.context in ('advise',):
self.packages.append('ipaserver/advise/plugins')
def create_api(mode='dummy'):
@ -926,11 +924,9 @@ def create_api(mode='dummy'):
- `frontend.Method`
- `frontend.Advice`
- `backend.Backend`
"""
api = API((Command, Object, Method, Backend, Updater, Advice))
api = API((Command, Object, Method, Backend, Updater))
if mode is not None:
api.env.mode = mode
assert mode != 'production'

View File

@ -1406,53 +1406,3 @@ class Updater(Method):
)
return self.execute(**options)
class _AdviceOutput(object):
def __init__(self):
self.content = []
self.prefix = '# '
self.options = None
def comment(self, line, wrapped=True):
if wrapped:
for wrapped_line in wrap(line, 70):
self.content.append(self.prefix + wrapped_line)
else:
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)
@register.base()
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

View File

@ -19,11 +19,14 @@
import os
from ipalib import api
from ipalib.plugable import Plugin, Registry, API
from ipalib.errors import ValidationError
from ipapython import admintool
from textwrap import wrap
from ipapython.ipa_log_manager import log_mgr
register = Registry()
"""
To add configuration instructions for a new use case, define a new class that
@ -72,6 +75,58 @@ Important! Do not forget to register the class to the API.
"""
class _AdviceOutput(object):
def __init__(self):
self.content = []
self.prefix = '# '
self.options = None
def comment(self, line, wrapped=True):
if wrapped:
for wrapped_line in wrap(line, 70):
self.content.append(self.prefix + wrapped_line)
else:
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)
@register.base()
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
advise_api = API((Advice,), ('ipaserver/advise/plugins',))
class IpaAdvise(admintool.AdminTool):
"""
Admin tool that given systems's configuration provides instructions how to
@ -104,10 +159,10 @@ class IpaAdvise(admintool.AdminTool):
def print_config_list(self):
self.print_header('List of available advices')
max_keyword_len = max((len(keyword) for keyword in api.Advice))
max_keyword_len = max((len(keyword) for keyword in advise_api.Advice))
for keyword in api.Advice:
advice = getattr(api.Advice, keyword, '')
for keyword in advise_api.Advice:
advice = getattr(advise_api.Advice, keyword, '')
description = getattr(advice, 'description', '')
keyword = keyword.replace('_', '-')
@ -139,7 +194,7 @@ class IpaAdvise(admintool.AdminTool):
print(prefix + '-' * 70)
def print_advice(self, keyword):
advice = getattr(api.Advice, keyword, None)
advice = getattr(advise_api.Advice, keyword, None)
# Ensure that Configuration class for given --setup option value exists
if advice is None:
@ -172,8 +227,10 @@ class IpaAdvise(admintool.AdminTool):
def run(self):
super(IpaAdvise, self).run()
api.bootstrap(in_server=False, context='advise')
api.bootstrap(in_server=False, context='cli')
api.finalize()
advise_api.bootstrap(in_server=False, context='cli')
advise_api.finalize()
if not self.options.verbose:
# Do not print connection information by default
logger_name = r'ipa\.ipalib\.plugins\.rpcclient'

View File

@ -18,9 +18,13 @@
#
from ipalib import api
from ipalib.frontend import Advice
from ipalib.plugable import Registry
from ipaserver.advise.base import Advice
register = Registry()
@register()
class config_fedora_authconfig(Advice):
"""
Provides client configuration instructions using authconfig.
@ -36,6 +40,3 @@ class config_fedora_authconfig(Advice):
"--enablerfc2307bis --enablekrb5"
advice = template.format(server=api.env.host)
self.log.command(advice)
api.register(config_fedora_authconfig)

View File

@ -19,9 +19,12 @@
import os
from ipalib import api
from ipalib.frontend import Advice
from ipalib.plugable import Registry
from ipaserver.advise.base import Advice
from ipapython.ipautil import template_file, SHARE_DIR
register = Registry()
class config_base_legacy_client(Advice):
def get_uri_and_base(self):
@ -80,6 +83,7 @@ class config_base_legacy_client(Advice):
self.log.command('service sssd start')
@register()
class config_redhat_sssd_before_1_9(config_base_legacy_client):
"""
Legacy client configuration for Red Hat based systems, using SSSD.
@ -113,9 +117,7 @@ class config_redhat_sssd_before_1_9(config_base_legacy_client):
super(config_redhat_sssd_before_1_9, self).configure_ca_cert()
api.register(config_redhat_sssd_before_1_9)
@register()
class config_generic_linux_sssd_before_1_9(config_base_legacy_client):
"""
Legacy client configuration for non Red Hat based linux systems,
@ -170,9 +172,7 @@ class config_generic_linux_sssd_before_1_9(config_base_legacy_client):
'/etc/ldap/ldap.conf\n')
api.register(config_generic_linux_sssd_before_1_9)
@register()
class config_redhat_nss_pam_ldapd(config_base_legacy_client):
"""
Legacy client configuration for Red Hat based systems,
@ -207,9 +207,7 @@ class config_redhat_nss_pam_ldapd(config_base_legacy_client):
super(config_redhat_nss_pam_ldapd, self).configure_ca_cert()
api.register(config_redhat_nss_pam_ldapd)
@register()
class config_generic_linux_nss_pam_ldapd(config_base_legacy_client):
"""
Legacy client configuration for non Red Hat based linux systems,
@ -276,9 +274,7 @@ class config_generic_linux_nss_pam_ldapd(config_base_legacy_client):
'/etc/ldap/ldap.conf\n')
api.register(config_generic_linux_nss_pam_ldapd)
@register()
class config_freebsd_nss_pam_ldapd(config_base_legacy_client):
"""
Legacy client configuration for FreeBSD, using nss-pam-ldapd.
@ -343,9 +339,8 @@ class config_freebsd_nss_pam_ldapd(config_base_legacy_client):
self.log.command('curl -k https://%s/ipa/config/ca.crt > '
'%s' % (api.env.host, cacrt))
api.register(config_freebsd_nss_pam_ldapd)
@register()
class config_redhat_nss_ldap(config_base_legacy_client):
"""
Legacy client configuration for Red Hat based systems,
@ -378,5 +373,3 @@ class config_redhat_nss_ldap(config_base_legacy_client):
'Therefore, clients older than RHEL5.2 will not be '
'able to interoperate with IPA server 3.x.')
super(config_redhat_nss_ldap, self).configure_ca_cert()
api.register(config_redhat_nss_ldap)