From: hamdyk@mellanox.com (Hamdy Khader)
Subject: [PATCH] Adds the ability to dump json to stdout
Date: Mon, 16 Jul 2018 14:58:20 +0300 [thread overview]
Message-ID: <1531742300-9888-1-git-send-email-hamdyk@mellanox.com> (raw)
---
nvmet/nvme.py | 3 +++
nvmetcli | 12 +++++++-----
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/nvmet/nvme.py b/nvmet/nvme.py
index 8253ea9..3ca8429 100644
--- a/nvmet/nvme.py
+++ b/nvmet/nvme.py
@@ -388,6 +388,9 @@ class Root(CFSNode):
d['hosts'] = [h.dump() for h in self.hosts]
return d
+ def dump_json(self):
+ return json.dumps(self.dump(), sort_keys=True, indent=2)
+
class Subsystem(CFSNode):
'''
diff --git a/nvmetcli b/nvmetcli
index 6b102a2..de189c1 100755
--- a/nvmetcli
+++ b/nvmetcli
@@ -583,6 +583,7 @@ def usage():
print(" %s restore [file_to_restore_from]" % sys.argv[0])
print(" %s clear" % sys.argv[0])
print(" %s ls" % sys.argv[0])
+ print(" %s dump" % sys.argv[0])
sys.exit(-1)
@@ -590,6 +591,10 @@ def save(to_file):
nvme.Root().save_to_file(to_file)
+def dump(unused):
+ print(nvme.Root().dump_json())
+
+
def restore(from_file):
try:
errors = nvme.Root().restore_from_file(from_file)
@@ -613,7 +618,7 @@ def ls(unused):
sys.exit(0)
-funcs = dict(save=save, restore=restore, clear=clear, ls=ls)
+funcs = dict(save=save, restore=restore, clear=clear, ls=ls, dump=dump)
def main():
@@ -621,10 +626,7 @@ def main():
print("%s: must run as root." % sys.argv[0], file=sys.stderr)
sys.exit(-1)
- if len(sys.argv) > 3:
- usage()
-
- if len(sys.argv) == 2 or len(sys.argv) == 3:
+ if len(sys.argv) >= 2:
if sys.argv[1] == "--help":
usage()
--
1.9.1
next reply other threads:[~2018-07-16 11:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-16 11:58 Hamdy Khader [this message]
-- strict thread matches above, loose matches on Subject: below --
2018-07-16 11:49 [PATCH] Adds the ability to dump json to stdout Hamdy Khader
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1531742300-9888-1-git-send-email-hamdyk@mellanox.com \
--to=hamdyk@mellanox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).