Blob Blame Raw
From f77760fb4e39e6d5b673ee8c5388407ff1ae98be Mon Sep 17 00:00:00 2001
From: William Brown <william@blackhats.net.au>
Date: Wed, 23 Oct 2019 12:01:04 +1000
Subject: [PATCH] Ticket 50667 - dsctl -l did not respect PREFIX

Bug Description: dsctl list was not coded to allow
using the paths module.

Fix Description: Change to the paths module to allow
better and consistent CLI handling.

https://pagure.io/389-ds-base/issue/50667

Author: William Brown <william@blackhats.net.au>

Review by: mreynolds, spichugi (thanks)
---
 src/lib389/cli/dsctl                  | 4 ++--
 src/lib389/lib389/cli_ctl/instance.py | 2 +-
 src/lib389/lib389/utils.py            | 8 ++++++--
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/lib389/cli/dsctl b/src/lib389/cli/dsctl
index 8b86629ac..47ca8269b 100755
--- a/src/lib389/cli/dsctl
+++ b/src/lib389/cli/dsctl
@@ -46,8 +46,8 @@ parser.add_argument('-l', '--list',
         default=False, action='store_true'
     )
 
-parser.add_argument('--remove-all', nargs="?", default=False, const=None,
-        help="Remove all instances of Directory Server (you can also provide an optional directory prefix for this argument)",
+parser.add_argument('--remove-all', default=False, action='store_true',
+        help=argparse.SUPPRESS
     )
 
 subparsers = parser.add_subparsers(help="action")
diff --git a/src/lib389/lib389/cli_ctl/instance.py b/src/lib389/lib389/cli_ctl/instance.py
index 95958e14c..f0111f35b 100644
--- a/src/lib389/lib389/cli_ctl/instance.py
+++ b/src/lib389/lib389/cli_ctl/instance.py
@@ -127,7 +127,7 @@ def instance_remove_all(log, args):
     """Remove all instances - clean sweep!
     """
 
-    inst_names = get_instance_list(args.remove_all)
+    inst_names = get_instance_list()
     if len(inst_names) > 0:
         answer = input("Are you sure you want to remove all the Directory Server instances?  Enter \"Yes\" to continue: ")
         if answer != 'Yes':
diff --git a/src/lib389/lib389/utils.py b/src/lib389/lib389/utils.py
index b9eacfdea..587c7b07b 100644
--- a/src/lib389/lib389/utils.py
+++ b/src/lib389/lib389/utils.py
@@ -1244,9 +1244,10 @@ def get_ldapurl_from_serverid(instance):
         return ("ldap://{}:{}".format(host, port), None)
 
 
-def get_instance_list(prefix=None):
+def get_instance_list():
     # List all server instances
-    conf_dir = (prefix or "") + "/etc/dirsrv/"
+    paths = Paths()
+    conf_dir = os.path.join(paths.sysconf_dir, 'dirsrv')
     insts = []
     try:
         for inst in os.listdir(conf_dir):
@@ -1254,6 +1255,9 @@ def get_instance_list(prefix=None):
                 insts.append(inst)
     except OSError as e:
         log.error("Failed to check directory: {} - {}".format(conf_dir, str(e)))
+    except IOError as e:
+        log.error(e)
+        log.error("Perhaps you need to be a different user?")
     insts.sort()
     return insts
 
-- 
2.21.1