diff options
author | Atin Mukherjee <amukherj@redhat.com> | 2014-06-30 10:33:25 +0530 |
---|---|---|
committer | Kaushal M <kaushal@redhat.com> | 2014-08-26 04:17:51 -0700 |
commit | c080403393987f807b9ca81be140618fa5e994f1 (patch) | |
tree | ff49f5f43e6d2208dbf15b9aac9b3f8a50bd8702 /cli/src/cli-xml-output.c | |
parent | acabde2c297c4175946565017ba17a251ad3fb1c (diff) |
cli/glusterd: Support of volume get for a specific volume option
This patch introduces a cli command to display a specific volume option/all
volume options of a specific volume with the following usage:
Usage: volume get <VOLNAME> <key|all>
Change-Id: Ic88edb33c5509d7a37cd5ade6341e45e3cdbf59d
BUG: 983317
Signed-off-by: Atin Mukherjee <amukherj@redhat.com>
Reviewed-on: http://review.gluster.org/8305
Reviewed-by: Kaushal M <kaushal@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Diffstat (limited to 'cli/src/cli-xml-output.c')
-rw-r--r-- | cli/src/cli-xml-output.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/cli/src/cli-xml-output.c b/cli/src/cli-xml-output.c index da178d903e8..840ff32e52b 100644 --- a/cli/src/cli-xml-output.c +++ b/cli/src/cli-xml-output.c @@ -5693,3 +5693,81 @@ out: #endif /* HAVE_LIB_XML */ } +int +cli_xml_output_vol_getopts (dict_t *dict, int op_ret, int op_errno, + char *op_errstr) +{ +#if (HAVE_LIB_XML) + int i = 0; + int ret = -1; + int count = 0; + xmlTextWriterPtr writer = NULL; + xmlDocPtr doc = NULL; + char *key = NULL; + char *value = NULL; + char dict_key[50] = {0,}; + + ret = cli_begin_xml_output (&writer, &doc); + if (ret) + goto out; + + ret = cli_xml_output_common (writer, op_ret, op_errno, op_errstr); + if (ret) + goto out; + + ret = xmlTextWriterStartElement (writer, (xmlChar *)"volGetopts"); + XML_RET_CHECK_AND_GOTO (ret, out); + + ret = dict_get_int32 (dict, "count", &count); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed to retrieve count " + "from the dictionary"); + goto out; + } + if (count <= 0) { + gf_log ("cli", GF_LOG_ERROR, "Value of count :%d is " + "invalid", count); + ret = -1; + goto out; + } + ret = xmlTextWriterWriteFormatElement (writer, (xmlChar *)"count", + "%d", count); + + XML_RET_CHECK_AND_GOTO (ret, out); + + for (i=1; i<=count; i++) { + sprintf (dict_key, "key%d", i); + ret = dict_get_str (dict, dict_key, &key); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed to" + " retrieve %s from the " + "dictionary", dict_key); + goto out; + } + sprintf (dict_key, "value%d", i); + ret = dict_get_str (dict, dict_key, &value); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed to " + "retrieve key value for %s from" + "the dictionary", dict_key); + goto out; + } + ret = xmlTextWriterWriteFormatElement (writer, + (xmlChar *)"Option", + "%s", key); + XML_RET_CHECK_AND_GOTO (ret, out); + + ret = xmlTextWriterWriteFormatElement (writer, + (xmlChar *)"Value", + "%s", value); + XML_RET_CHECK_AND_GOTO (ret, out); + } + ret = cli_end_xml_output (writer, doc); + +out: + gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); + return ret; +#else + return 0; +#endif /* HAVE_LIB_XML */ +} |