[6.0] 95e9cfe6b Add JSON support for the "storage.list" CLI command.

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Oct 31 13:08:29 UTC 2018


commit 95e9cfe6b95bc641e1d0a67613b0c61bc77d462c
Author: Geoff Simmons <geoff at uplex.de>
Date:   Tue Sep 25 09:15:06 2018 +0200

    Add JSON support for the "storage.list" CLI command.

diff --git a/bin/varnishd/storage/mgt_stevedore.c b/bin/varnishd/storage/mgt_stevedore.c
index 3f66c3af3..c204a3e53 100644
--- a/bin/varnishd/storage/mgt_stevedore.c
+++ b/bin/varnishd/storage/mgt_stevedore.c
@@ -82,10 +82,36 @@ stv_cli_list(struct cli *cli, const char * const *av, void *priv)
 		VCLI_Out(cli, "\tstorage.%s = %s\n", stv->ident, stv->name);
 }
 
+static void v_matchproto_(cli_func_t)
+stv_cli_list_json(struct cli *cli, const char * const *av, void *priv)
+{
+	struct stevedore *stv;
+	int n = 0;
+
+	(void)priv;
+	ASSERT_MGT();
+	VCLI_JSON_begin(cli, 2, av);
+	VCLI_Out(cli, ",\n");
+	STV_Foreach(stv) {
+		VCLI_Out(cli, "%s", n ? ",\n" : "");
+		n++;
+		VCLI_Out(cli, "{\n");
+		VSB_indent(cli->sb, 2);
+		VCLI_Out(cli, "\"name\": ");
+		VCLI_JSON_str(cli, stv->ident);
+		VCLI_Out(cli, ",\n");
+		VCLI_Out(cli, "\"storage\": ");
+		VCLI_JSON_str(cli, stv->name);
+		VSB_indent(cli->sb, -2);
+		VCLI_Out(cli, "\n}");
+	}
+	VCLI_JSON_end(cli);
+}
+
 /*--------------------------------------------------------------------*/
 
 static struct cli_proto cli_stv[] = {
-	{ CLICMD_STORAGE_LIST,		"", stv_cli_list },
+	{ CLICMD_STORAGE_LIST,		"", stv_cli_list, stv_cli_list_json },
 	{ NULL}
 };
 
diff --git a/bin/varnishtest/tests/b00032.vtc b/bin/varnishtest/tests/b00032.vtc
index 7aa6cddfa..d395fef69 100644
--- a/bin/varnishtest/tests/b00032.vtc
+++ b/bin/varnishtest/tests/b00032.vtc
@@ -1,6 +1,7 @@
 varnishtest "CLI coverage test"
 
 varnish v1 -cliok storage.list
+varnish v1 -clijson "storage.list -j"
 
 server s1 {
 	rxreq


More information about the varnish-commit mailing list