diff options
author | Prasanna Kumar Kalever <prasanna.kalever@redhat.com> | 2019-10-18 18:00:06 +0530 |
---|---|---|
committer | Prasanna Kumar Kalever <prasanna.kalever@redhat.com> | 2019-10-30 15:57:15 +0530 |
commit | b36f0a0e27cdea9128cdf71e696e05bdfd12e462 (patch) | |
tree | 9e6687570c9dd59879fd8d8152940b4bc5f18893 | |
parent | 332e7c0e6fceffc620a426cf2d765b62b8dfe406 (diff) | |
download | targetcli-b36f0a0e27cdea9128cdf71e696e05bdfd12e462.tar.gz |
cli: provide a way to disable using daemon
Problem:
-------
Currently when auto_use_daemon is set to true and in case for some
reasons user do not want to start the daemon or the dameon is not starting
succefully for some unknown reason, then there is no way to bypass the
calls to dameon and use cli directly
$ targetcli pwd
[Errno 111] Connection refused
Solution:
--------
Provide an option with cli to turn auto_use_daemon to false.
$ targetcli pwd
[Errno 111] Connection refused
Currently auto_use_daemon is true, hence please make sure targetclid daemon is running ...
(or)
Incase if you wish to turn auto_use_daemon to false then run '#targetcli --disable-daemon'
$ targetcli --help
Usage: ./scripts/targetcli [--version|--help|CMD|--tcp|--disable-daemon]
[...]
--disable-daemon Turn-off the global auto use daemon flag
See man page for more information.
$ targetcli --disable-daemon
Parameter auto_use_daemon is now 'false'.
$ targetcli pwd
/
Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
-rwxr-xr-x | scripts/targetcli | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/scripts/targetcli b/scripts/targetcli index 1be3120..9009a14 100755 --- a/scripts/targetcli +++ b/scripts/targetcli @@ -67,13 +67,14 @@ class TargetCLI(ConfigShell): } def usage(): - print("Usage: %s [--version|--help|CMD|--tcp]" % sys.argv[0], file=err) + print("Usage: %s [--version|--help|CMD|--tcp|--disable-daemon]" % sys.argv[0], file=err) print(" --version\t\tPrint version", file=err) print(" --help\t\tPrint this information", file=err) print(" CMD\t\t\tRun targetcli shell command and exit", file=err) print(" <nothing>\t\tEnter configuration shell", file=err) print(" --tcp CMD\t\tPass targetcli command to targetclid", file=err) print(" --tcp <nothing>\tEnter multi-line command mode for targetclid", file=err) + print(" --disable-daemon\tTurn-off the global auto use daemon flag", file=err) print("See man page for more information.", file=err) sys.exit(-1) @@ -135,7 +136,9 @@ def call_daemon(shell, req): shell.con.display(shell.con.render_text(err, 'red')) shell.con.display( shell.con.render_text("Currently auto_use_daemon is true, " - "hence please make sure targetclid daemon is running ...", 'red')) + "hence please make sure targetclid daemon is running ...\n" + "(or)\nIncase if you wish to turn auto_use_daemon to false " + "then run '#targetcli --disable-daemon'", 'red')) sys.exit(1) try: @@ -215,12 +218,15 @@ def main(): if shell.prefs['auto_use_daemon']: use_daemon = True + disable_daemon=False if len(sys.argv) > 1: usage_version(sys.argv[1]) if sys.argv[1] in ("tcp", "--tcp", "-t"): use_daemon = True + elif sys.argv[1] in ("disable-daemon", "--disable-daemon"): + disable_daemon=True - if use_daemon: + if use_daemon and not disable_daemon: call_daemon(shell, get_arguments().encode()) # does not return @@ -235,7 +241,10 @@ def main(): if len(sys.argv) > 1: try: - shell.run_cmdline(" ".join(sys.argv[1:])) + if disable_daemon: + shell.run_cmdline('set global auto_use_daemon=false') + else: + shell.run_cmdline(" ".join(sys.argv[1:])) except Exception as e: print(str(e), file=sys.stderr) sys.exit(1) |