|
|
e40f95 |
From 15abdd481c5babd4128f3f0a9f0ac2f983bf1c89 Mon Sep 17 00:00:00 2001
|
|
|
e40f95 |
From: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
|
|
|
e40f95 |
Date: Fri, 3 Apr 2020 13:01:06 +0530
|
|
|
e40f95 |
Subject: [PATCH 1/3] daemonized-mode: add interactive shell support
|
|
|
e40f95 |
|
|
|
e40f95 |
set interactive mode as default to make it appear similar to cli approach,
|
|
|
e40f95 |
|
|
|
e40f95 |
$ targetcli
|
|
|
e40f95 |
targetcli shell version 2.1.51
|
|
|
e40f95 |
Entering targetcli interactive mode for daemonized approach.
|
|
|
e40f95 |
Type 'exit' to quit.
|
|
|
e40f95 |
|
|
|
e40f95 |
/> pwd
|
|
|
e40f95 |
/
|
|
|
e40f95 |
/> cd /iscsi
|
|
|
e40f95 |
/> pwd
|
|
|
e40f95 |
/iscsi
|
|
|
e40f95 |
/> exit
|
|
|
e40f95 |
|
|
|
e40f95 |
Here we introduce a new global option daemon_use_batch_mode for switching between
|
|
|
e40f95 |
batch and interactive modes.
|
|
|
e40f95 |
|
|
|
e40f95 |
$ targetcli set global daemon_use_batch_mode=true
|
|
|
e40f95 |
Parameter daemon_use_batch_mode is now 'true'.
|
|
|
e40f95 |
|
|
|
e40f95 |
$ targetcli
|
|
|
e40f95 |
targetcli shell version 2.1.51
|
|
|
e40f95 |
Entering targetcli batch mode for daemonized approach.
|
|
|
e40f95 |
Enter multiple commands separated by newline and type 'exit' to run them
|
|
|
e40f95 |
all in one go.
|
|
|
e40f95 |
|
|
|
e40f95 |
/> pwd
|
|
|
e40f95 |
/> cd /iscsi
|
|
|
e40f95 |
/> pwd
|
|
|
e40f95 |
/
|
|
|
e40f95 |
/iscsi
|
|
|
e40f95 |
|
|
|
e40f95 |
Fixes: #160
|
|
|
e40f95 |
Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
|
|
|
e40f95 |
---
|
|
|
e40f95 |
scripts/targetcli | 57 ++++++++++++++++++++++++++++----------------
|
|
|
e40f95 |
targetcli/ui_node.py | 3 +++
|
|
|
e40f95 |
targetclid.8 | 31 ++++++++++++++++++++++--
|
|
|
e40f95 |
3 files changed, 69 insertions(+), 22 deletions(-)
|
|
|
e40f95 |
|
|
|
e40f95 |
diff --git a/scripts/targetcli b/scripts/targetcli
|
|
|
e40f95 |
index f11ece4..3496126 100755
|
|
|
e40f95 |
--- a/scripts/targetcli
|
|
|
e40f95 |
+++ b/scripts/targetcli
|
|
|
e40f95 |
@@ -64,6 +64,7 @@ class TargetCLI(ConfigShell):
|
|
|
e40f95 |
'max_backup_files': '10',
|
|
|
e40f95 |
'auto_add_default_portal': True,
|
|
|
e40f95 |
'auto_use_daemon': False,
|
|
|
e40f95 |
+ 'daemon_use_batch_mode': False,
|
|
|
e40f95 |
}
|
|
|
e40f95 |
|
|
|
e40f95 |
def usage():
|
|
|
e40f95 |
@@ -160,9 +161,8 @@ def call_daemon(shell, req):
|
|
|
e40f95 |
|
|
|
e40f95 |
sock.send(b'-END@OF@DATA-')
|
|
|
e40f95 |
sock.close()
|
|
|
e40f95 |
- sys.exit(0)
|
|
|
e40f95 |
|
|
|
e40f95 |
-def get_arguments(shell):
|
|
|
e40f95 |
+def switch_to_daemon(shell, interactive):
|
|
|
e40f95 |
readline.set_completer(completer)
|
|
|
e40f95 |
readline.set_completer_delims('')
|
|
|
e40f95 |
|
|
|
e40f95 |
@@ -173,27 +173,40 @@ def get_arguments(shell):
|
|
|
e40f95 |
|
|
|
e40f95 |
if len(sys.argv) > 1:
|
|
|
e40f95 |
command = " ".join(sys.argv[1:])
|
|
|
e40f95 |
+ call_daemon(shell, command.encode())
|
|
|
e40f95 |
+ sys.exit(0)
|
|
|
e40f95 |
+
|
|
|
e40f95 |
+ if interactive:
|
|
|
e40f95 |
+ shell.con.display("targetcli shell version %s\n"
|
|
|
e40f95 |
+ "Entering targetcli interactive mode for daemonized approach.\n"
|
|
|
e40f95 |
+ "Type 'exit' to quit.\n"
|
|
|
e40f95 |
+ % targetcli_version)
|
|
|
e40f95 |
else:
|
|
|
e40f95 |
- inputs = []
|
|
|
e40f95 |
shell.con.display("targetcli shell version %s\n"
|
|
|
e40f95 |
- "Entering targetcli batch mode for daemonized approach.\n"
|
|
|
e40f95 |
- "Enter multiple commands separated by newline and "
|
|
|
e40f95 |
- "type 'exit' to run them all in one go.\n"
|
|
|
e40f95 |
- % targetcli_version)
|
|
|
e40f95 |
- while True:
|
|
|
e40f95 |
- shell.con.raw_write("/> ")
|
|
|
e40f95 |
- command = six.moves.input()
|
|
|
e40f95 |
- if command.lower() == "exit":
|
|
|
e40f95 |
- break
|
|
|
e40f95 |
+ "Entering targetcli batch mode for daemonized approach.\n"
|
|
|
e40f95 |
+ "Enter multiple commands separated by newline and "
|
|
|
e40f95 |
+ "type 'exit' to run them all in one go.\n"
|
|
|
e40f95 |
+ % targetcli_version)
|
|
|
e40f95 |
+
|
|
|
e40f95 |
+ inputs = []
|
|
|
e40f95 |
+ real_exit=False
|
|
|
e40f95 |
+ while True:
|
|
|
e40f95 |
+ shell.con.raw_write("/> ")
|
|
|
e40f95 |
+ command = six.moves.input()
|
|
|
e40f95 |
+ if command.lower() == "exit":
|
|
|
e40f95 |
+ real_exit=True
|
|
|
e40f95 |
+ if not interactive:
|
|
|
e40f95 |
inputs.append(command)
|
|
|
e40f95 |
- command = '%'.join(inputs) # delimit multiple commands with '%'
|
|
|
e40f95 |
-
|
|
|
e40f95 |
- if not command:
|
|
|
e40f95 |
- sys.exit(1)
|
|
|
e40f95 |
-
|
|
|
e40f95 |
- usage_version(command);
|
|
|
e40f95 |
+ if real_exit:
|
|
|
e40f95 |
+ command = '%'.join(inputs) # delimit multiple commands with '%'
|
|
|
e40f95 |
+ call_daemon(shell, command.encode())
|
|
|
e40f95 |
+ break
|
|
|
e40f95 |
+ else:
|
|
|
e40f95 |
+ if real_exit:
|
|
|
e40f95 |
+ break
|
|
|
e40f95 |
+ call_daemon(shell, command.encode())
|
|
|
e40f95 |
|
|
|
e40f95 |
- return command
|
|
|
e40f95 |
+ sys.exit(0)
|
|
|
e40f95 |
|
|
|
e40f95 |
def main():
|
|
|
e40f95 |
'''
|
|
|
e40f95 |
@@ -225,8 +238,12 @@ def main():
|
|
|
e40f95 |
if sys.argv[1] in ("disable-daemon", "--disable-daemon"):
|
|
|
e40f95 |
disable_daemon=True
|
|
|
e40f95 |
|
|
|
e40f95 |
+ interactive_mode = True
|
|
|
e40f95 |
+ if shell.prefs['daemon_use_batch_mode']:
|
|
|
e40f95 |
+ interactive_mode = False
|
|
|
e40f95 |
+
|
|
|
e40f95 |
if use_daemon and not disable_daemon:
|
|
|
e40f95 |
- call_daemon(shell, get_arguments(shell).encode())
|
|
|
e40f95 |
+ switch_to_daemon(shell, interactive_mode)
|
|
|
e40f95 |
# does not return
|
|
|
e40f95 |
|
|
|
e40f95 |
try:
|
|
|
e40f95 |
diff --git a/targetcli/ui_node.py b/targetcli/ui_node.py
|
|
|
e40f95 |
index 58a70c6..0485950 100644
|
|
|
e40f95 |
--- a/targetcli/ui_node.py
|
|
|
e40f95 |
+++ b/targetcli/ui_node.py
|
|
|
e40f95 |
@@ -52,6 +52,9 @@ class UINode(ConfigNode):
|
|
|
e40f95 |
self.define_config_group_param(
|
|
|
e40f95 |
'global', 'auto_use_daemon', 'bool',
|
|
|
e40f95 |
'If true, commands will be sent to targetclid.')
|
|
|
e40f95 |
+ self.define_config_group_param(
|
|
|
e40f95 |
+ 'global', 'daemon_use_batch_mode', 'bool',
|
|
|
e40f95 |
+ 'If true, use batch mode for daemonized approach.')
|
|
|
e40f95 |
|
|
|
e40f95 |
def assert_root(self):
|
|
|
e40f95 |
'''
|
|
|
e40f95 |
diff --git a/targetclid.8 b/targetclid.8
|
|
|
e40f95 |
index a783091..5760168 100644
|
|
|
e40f95 |
--- a/targetclid.8
|
|
|
e40f95 |
+++ b/targetclid.8
|
|
|
e40f95 |
@@ -30,11 +30,38 @@ $ targetcli set global auto_use_daemon=true
|
|
|
e40f95 |
.br
|
|
|
e40f95 |
$ targetcli ls
|
|
|
e40f95 |
.TP
|
|
|
e40f95 |
-You can use batch mode for sending multiple commands in one go,
|
|
|
e40f95 |
+You can use interactive mode,
|
|
|
e40f95 |
.br
|
|
|
e40f95 |
$ targetcli <hit-enter>
|
|
|
e40f95 |
.br
|
|
|
e40f95 |
-targetcli shell version 2.1.50
|
|
|
e40f95 |
+targetcli shell version 2.1.51
|
|
|
e40f95 |
+.br
|
|
|
e40f95 |
+Entering targetcli interactive mode for daemonized approach.
|
|
|
e40f95 |
+.br
|
|
|
e40f95 |
+Type 'exit' to quit.
|
|
|
e40f95 |
+.br
|
|
|
e40f95 |
+/> pwd
|
|
|
e40f95 |
+.br
|
|
|
e40f95 |
+/
|
|
|
e40f95 |
+.br
|
|
|
e40f95 |
+/> cd /iscsi
|
|
|
e40f95 |
+.br
|
|
|
e40f95 |
+/> pwd
|
|
|
e40f95 |
+.br
|
|
|
e40f95 |
+/iscsi
|
|
|
e40f95 |
+.br
|
|
|
e40f95 |
+/> exit
|
|
|
e40f95 |
+.br
|
|
|
e40f95 |
+.TP
|
|
|
e40f95 |
+You can also use batch mode for sending multiple commands in one go,
|
|
|
e40f95 |
+.br
|
|
|
e40f95 |
+$ targetcli set global daemon_use_batch_mode=true
|
|
|
e40f95 |
+.br
|
|
|
e40f95 |
+Parameter daemon_use_batch_mode is now 'true'.
|
|
|
e40f95 |
+.br
|
|
|
e40f95 |
+$ targetcli <hit-enter>
|
|
|
e40f95 |
+.br
|
|
|
e40f95 |
+targetcli shell version 2.1.51
|
|
|
e40f95 |
.br
|
|
|
e40f95 |
Entering targetcli batch mode for daemonized approach.
|
|
|
e40f95 |
.br
|
|
|
e40f95 |
--
|
|
|
e40f95 |
2.21.0
|
|
|
e40f95 |
|