]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/spdk/scripts/spdkcli.py
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / scripts / spdkcli.py
index 743ed060757242ab1079d635b0d836e4a4bab17e..3d7c63baa8ee6db905c86973627a02e2f0c4738c 100755 (executable)
@@ -1,14 +1,11 @@
 #!/usr/bin/env python3
 import sys
 import argparse
-import configshell_fb
-from os import getuid
-from rpc.client import JSONRPCException
 from configshell_fb import ConfigShell, shell, ExecutionError
-from spdkcli import UIRoot
-import rpc.client
 from pyparsing import (alphanums, Optional, Suppress, Word, Regex,
                        removeQuotes, dblQuotedString, OneOrMore)
+from rpc.client import JSONRPCException, JSONRPCClient
+from spdkcli import UIRoot
 
 
 def add_quotes_to_shell(spdk_shell):
@@ -37,14 +34,24 @@ def main():
     add_quotes_to_shell(spdk_shell)
 
     parser = argparse.ArgumentParser(description="SPDK command line interface")
-    parser.add_argument("-s", dest="socket", help="RPC socket path", default="/var/tmp/spdk.sock")
+    parser.add_argument('-s', dest='server_addr',
+                        help='RPC domain socket path or IP address', default='/var/tmp/spdk.sock')
+    parser.add_argument('-p', dest='port',
+                        help='RPC port number (if server_addr is IP address)',
+                        default=None, type=int)
     parser.add_argument("-v", dest="verbose", help="Print request/response JSON for configuration calls",
                         default=False, action="store_true")
     parser.add_argument("commands", metavar="command", type=str, nargs="*", default="",
                         help="commands to execute by SPDKCli as one-line command")
     args = parser.parse_args()
 
-    with rpc.client.JSONRPCClient(args.socket) as client:
+    try:
+        client = JSONRPCClient(args.server_addr, port=args.port)
+    except JSONRPCException as e:
+        spdk_shell.log.error("%s. SPDK not running?" % e)
+        sys.exit(1)
+
+    with client:
         root_node = UIRoot(client, spdk_shell)
         root_node.verbose = args.verbose
         try:
@@ -52,7 +59,7 @@ def main():
         except BaseException:
             pass
 
-        if len(args.commands) > 0:
+        if args.commands:
             try:
                 spdk_shell.interactive = False
                 spdk_shell.run_cmdline(" ".join(args.commands))
@@ -63,11 +70,14 @@ def main():
 
         spdk_shell.con.display("SPDK CLI v0.1")
         spdk_shell.con.display("")
+
         while not spdk_shell._exit:
             try:
                 spdk_shell.run_interactive()
             except (JSONRPCException, ExecutionError) as e:
                 spdk_shell.log.error("%s" % e)
+            except BrokenPipeError as e:
+                spdk_shell.log.error("Lost connection with SPDK: %s" % e)
 
 
 if __name__ == "__main__":