[node-patches] Change in ovirt-node[master]: tools: Enhance password tool usability

fabiand at fedoraproject.org fabiand at fedoraproject.org
Mon Aug 26 10:38:18 UTC 2013


Fabian Deutsch has uploaded a new change for review.

Change subject: tools: Enhance password tool usability
......................................................................

tools: Enhance password tool usability

Previously the usability of the new password tool was suboptimal. This
patch improves it to get the user more informations and a better
starting point.

Change-Id: Ib2fd12962c82d09fc00748d834c26e5b9051d10f
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=977479
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M src/ovirt/node/tools/password.py
M src/ovirt/node/utils/security.py
2 files changed, 67 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/01/18501/1

diff --git a/src/ovirt/node/tools/password.py b/src/ovirt/node/tools/password.py
index 58f3e93..79c9d9d 100644
--- a/src/ovirt/node/tools/password.py
+++ b/src/ovirt/node/tools/password.py
@@ -28,7 +28,7 @@
 
 
 class PasswordTool(cmd.Cmd):
-    intro = "\n\n Password Configuration\n\n Enter ? for help.\n"
+    intro ="\n\n Password Configuration\n\n"
     prompt = "> "
     is_debug = False
 
@@ -37,20 +37,73 @@
         self.logger = logging.getLogger(__name__)
         self.is_debug = debug
 
-    def do_set_root_password(self, line):
-        """Set root password
+    def preloop(self):
+        print(self.intro)
+        print("Possible commands:")
+        self.do_help("")
+        print("")
+        self.do_get_ssh_password_authentication("")
+        print("")
+        self.intro = None
+
+    def do_help(self, line=None):
+        """Show this help. [`help --all` to show all available functions]
         """
+        show_all = line.strip() == "--all"
+        funcs = []
+        for name in sorted(self.get_names()):
+            if name.startswith("do_"):
+                doc = getattr(self, name).__doc__
+                doc = doc or ""
+                doc = doc.strip()
+                funcs.append((name[3:], doc))
+
+        max_name_len = max(len(n) for n, d in funcs if d)
+
+        def print_doc(name, doc):
+            print("%s  %s" % (name.ljust(max_name_len), doc))
+
+        if line in (n for n, _ in funcs):
+            print_doc(line, dict(funcs)[line])
+        else:
+            for name, doc in ((n, d) for n, d in funcs if d):
+                print_doc(name, doc)
+
+            if show_all:
+                print("\nCommands without help")
+                for name, doc in ((n, d) for n, d in funcs if not d):
+                    print_doc(name, "")
+
+    def do_root(self, line):
+        """Set the password of the user 'root'
+        """
+        return self.do_set_root_password(line)
+
+    def do_admin(self, line):
+        """Set the password of the user 'admin'
+        """
+        return self.do_set_admin_password(line)
+
+    def do_ssh(self, line):
+        """Enable or disable the SSH password authentication
+        """
+        return self.do_set_root_password(line)
+
+    def do_set_root_password(self, line):
         self.__ask_and_set_user_pasword("root")
 
     def do_set_admin_password(self, line):
-        """Set admin user password
-        """
         self.__ask_and_set_user_pasword("admin")
 
+    def do_get_ssh_password_authentication(self, line):
+        is_enabled = security.Ssh().password_authentication() 
+        status = "enabled" if is_enabled else "disabled"
+        self.logger.info("SSH password authentication is currently %s" %
+                         status)
+
     def do_set_ssh_password_authentication(self, line):
-        """Toggle SSH password authentication
-        """
         print("\n SSH password authentication\n")
+        self.do_get_ssh_password_authentication(line)
         prompt = "Enable SSH password authentication ([Y]es/[N]o)?"
         do_enable = self.__ask_yes_or_no(prompt)
         self.logger.debug("Setting SSH password authentication")
@@ -59,8 +112,13 @@
         self.logger.info("SSH password authentication is "
                          "currently %s." % state)
 
+    def do_q(self, line):
+        """Quit this tool
+        """
+        return self.do_quit(line)
+
     def do_quit(self, line):
-        """Quit
+        """Quit this tool
         """
         return True
 
diff --git a/src/ovirt/node/utils/security.py b/src/ovirt/node/utils/security.py
index f4e590e..7219008 100644
--- a/src/ovirt/node/utils/security.py
+++ b/src/ovirt/node/utils/security.py
@@ -166,7 +166,7 @@
             ofunc.ovirt_store_config("/etc/ssh/sshd_config")
             self.restart()
         state = str(aug.get(augpath)).lower()
-        if state not in ["yes", "no"]:
+        if state not in ["yes", "no", "none"]:
             raise RuntimeError("Failed to set SSH password authentication" +
                                "(%s)" % state)
         return state == "yes"


-- 
To view, visit http://gerrit.ovirt.org/18501
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib2fd12962c82d09fc00748d834c26e5b9051d10f
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>



More information about the node-patches mailing list