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