This is an automated email from the git hooks/post-receive script.
firstyear pushed a commit to branch master in repository lib389.
commit 87eb62a4117ea5b864d4e75694ca6f82dfafb34d Author: William Brown firstyear@redhat.com Date: Thu Apr 6 11:31:47 2017 +1000
Ticket 14 - Remane dsadm to dsctl
Bug Description: Rename dsadm to dsctl I forgot to provide the dsctl files. They are in this commit.
https://pagure.io/lib389/issue/14
Author: wibrown
Review by: spichugi (Thanks!) --- cli/dsctl | 101 ++++++++++++++++++++++++++++++++++ lib389/cli_ctl/__init__.py | 8 +++ lib389/cli_ctl/dbtasks.py | 18 ++++++ lib389/cli_ctl/instance.py | 133 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 260 insertions(+)
diff --git a/cli/dsctl b/cli/dsctl new file mode 100755 index 0000000..6c38bce --- /dev/null +++ b/cli/dsctl @@ -0,0 +1,101 @@ +#!/usr/bin/python + +# --- BEGIN COPYRIGHT BLOCK --- +# Copyright (C) 2016 Red Hat, Inc. +# All rights reserved. +# +# License: GPL (version 3 or any later version). +# See LICENSE for details. +# --- END COPYRIGHT BLOCK --- + +import argparse +import logging +import sys + +# This has to happen before we import DirSrv else it tramples our config ... :( +logging.basicConfig(format='%(message)s') + +from lib389.cli_base import _get_arg +from lib389 import DirSrv +from lib389.cli_ctl import instance as cli_instance +from lib389.cli_ctl import dbtasks as cli_dbtasks +from lib389.cli_base import disconnect_instance + +log = logging.getLogger("dsadm") + +if __name__ == '__main__': + + parser = argparse.ArgumentParser() + + parser.add_argument('-v', '--verbose', + help="Display verbose operation tracing during command execution", + action='store_true', default=False + ) + parser.add_argument('instance', + help="The name of the instance to act upon", + ) + + subparsers = parser.add_subparsers(help="action") + + # We stack our needed options in via submodules. + + cli_instance.create_parser(subparsers) + cli_dbtasks.create_parser(subparsers) + + # Then we tell it to execute. + + args = parser.parse_args() + + if args.verbose: + log.setLevel(logging.DEBUG) + else: + log.setLevel(logging.INFO) + + log.debug("The 389 Directory Server Administration Tool") + # Leave this comment here: UofA let me take this code with me provided + # I gave attribution. -- wibrown + log.debug("Inspired by works of: ITS, The University of Adelaide") + + log.debug("Called with: %s", args) + + # Assert we have a resources to work on. + if not hasattr(args, 'func'): + log.error("No action provided") + log.error("USAGE: dsadm [options] <resource> <action> [action options]") + sys.exit(1) + + # Connect + # inst = None + inst = DirSrv(verbose=args.verbose) + + result = True + + # Allocate the instance based on name + insts = inst.list(serverid=args.instance) + if len(insts) != 1: + raise ValueError("No such instance %s" % args.instance) + + inst.allocate(insts[0]) + log.debug('Instance allocated') + + if args.verbose: + result = args.func(inst, log, args) + else: + try: + result = args.func(inst, log, args) + except Exception as e: + log.debug(e, exc_info=True) + log.error("Error: %s" % e.message) + disconnect_instance(inst) + + if result is True: + log.info('FINISH: Command succeeded') + elif result is False: + log.info('FAIL: Command failed. See output for details.') + + # Done! + log.debug("dsadm is brought to you by the letter R and the number 27.") + + if result is False: + sys.exit(1) + diff --git a/lib389/cli_ctl/__init__.py b/lib389/cli_ctl/__init__.py new file mode 100644 index 0000000..d57ac33 --- /dev/null +++ b/lib389/cli_ctl/__init__.py @@ -0,0 +1,8 @@ +# --- BEGIN COPYRIGHT BLOCK --- +# Copyright (C) 2016 Red Hat, Inc. +# All rights reserved. +# +# License: GPL (version 3 or any later version). +# See LICENSE for details. +# --- END COPYRIGHT BLOCK --- + diff --git a/lib389/cli_ctl/dbtasks.py b/lib389/cli_ctl/dbtasks.py new file mode 100644 index 0000000..276f478 --- /dev/null +++ b/lib389/cli_ctl/dbtasks.py @@ -0,0 +1,18 @@ +# --- BEGIN COPYRIGHT BLOCK --- +# Copyright (C) 2016 Red Hat, Inc. +# All rights reserved. +# +# License: GPL (version 3 or any later version). +# See LICENSE for details. +# --- END COPYRIGHT BLOCK --- + +def dbtasks_db2index(inst, log, args): + # inst.db2index(suffixes=[args.suffix,]) + inst.db2index(bename=args.backend) + +def create_parser(subcommands): + db2index_parser = subcommands.add_parser('db2index', help="Initialise a reindex of the server database. The server must be stopped for this to proceed.") + # db2index_parser.add_argument('suffix', help="The suffix to reindex. IE dc=example,dc=com.") + db2index_parser.add_argument('backend', help="The backend to reindex. IE userRoot") + db2index_parser.set_defaults(func=dbtasks_db2index) + diff --git a/lib389/cli_ctl/instance.py b/lib389/cli_ctl/instance.py new file mode 100644 index 0000000..f59fb2b --- /dev/null +++ b/lib389/cli_ctl/instance.py @@ -0,0 +1,133 @@ +# --- BEGIN COPYRIGHT BLOCK --- +# Copyright (C) 2016 Red Hat, Inc. +# All rights reserved. +# +# License: GPL (version 3 or any later version). +# See LICENSE for details. +# --- END COPYRIGHT BLOCK --- + +from lib389._constants import * + +from lib389.tools import DirSrvTools +from lib389.instance.setup import SetupDs +from getpass import getpass +import os +import time +import sys + +from lib389.instance.options import General2Base, Slapd2Base + +def instance_list(inst, log, args): + instances = inst.list(all=True) + + try: + if len(instances) > 0: + for instance in instances: + log.info("instance: %s" % instance[CONF_SERVER_ID]) + else: + log.info("No instances of Directory Server") + except IOError as e: + log.info(e) + log.info("Perhaps you need to be a different user?") + +def instance_restart(inst, log, args): + inst.restart(post_open=False) + +def instance_start(inst, log, args): + inst.start(post_open=False) + +def instance_stop(inst, log, args): + inst.stop() + +def instance_status(inst, log, args): + if inst.status() is True: + log.info("Instance is running") + else: + log.info("Instance is not running") + +def instance_create(inst, log, args): + if not args.ack: + sys.exit(0) + else: + log.info(""" + _________________________________________ +/ This is not what you want! Press ctrl-c \ +\ now ... / + ----------------------------------------- + \ / \ //\ + \ |\___/| / \// \\ + /0 0 \__ / // | \ \ + / / \/_/ // | \ \ + @_^_@'/ \/_ // | \ \ + //_^_/ \/_ // | \ \ + ( //) | \/// | \ \ + ( / /) _|_ / ) // | \ _\ + ( // /) '/,_ _ _/ ( ; -. | _ _\.-~ .-~~~^-. + (( / / )) ,-{ _ `-.|.-~-. .~ `. + (( // / )) '/\ / ~-. _ .-~ .-~^-. \ + (( /// )) `. { } / \ \ + (( / )) .----~-.\ \-' .~ \ `. \^-. + ///.----..> \ _ -~ `. ^-` ^-_ + ///-._ _ _ _ _ _ _}^ - - - - ~ ~-- ,.-~ + /.-~ + """) + for i in range(1,6): + log.info('%s ...' % (5 - int(i))) + time.sleep(1) + log.info('Launching ...') + if args.containerised: + log.debug("Containerised features requested.") + sd = SetupDs(args.verbose, args.dryrun, log, args.containerised) + ### If args.file is not set, we need to interactively get answers! + if sd.create_from_inf(args.file): + # print("Sucessfully created instance") + return True + else: + # print("Failed to create instance") + return False + +def instance_example(inst, log, args): + print(""" +; --- BEGIN COPYRIGHT BLOCK --- +; Copyright (C) 2015 Red Hat, Inc. +; All rights reserved. +; +; License: GPL (version 3 or any later version). +; See LICENSE for details. +; --- END COPYRIGHT BLOCK --- + +; Author: firstyear at redhat.com + +; This is a version 2 ds setup inf file. +; It is used by the python versions of setup-ds-* +; Most options map 1 to 1 to the original .inf file. +; However, there are some differences that I envision +; For example, note the split backend section. +; You should be able to create, one, many or no backends in an install +; +; The special value {instance_name} is substituted at installation time. +; + + """) + g2b = General2Base(log) + s2b = Slapd2Base(log) + print(g2b.collect_help()) + print(s2b.collect_help()) + +def create_parser(subcommands): + # list_parser = subcommands.add_parser('list', help="List installed instances of Directory Server") + # list_parser.set_defaults(func=instance_list) + # list_parser.set_defaults(noinst=True) + restart_parser = subcommands.add_parser('restart', help="Restart an instance of Directory Server, if it is running: else start it.") + restart_parser.set_defaults(func=instance_restart) + + start_parser = subcommands.add_parser('start', help="Start an instance of Directory Server, if it is not currently running") + start_parser.set_defaults(func=instance_start) + + stop_parser = subcommands.add_parser('stop', help="Stop an instance of Directory Server, if it is currently running") + stop_parser.set_defaults(func=instance_stop) + + status_parser = subcommands.add_parser('status', help="Check running status of an instance of Directory Server") + status_parser.set_defaults(func=instance_status) + +