From d5999c107a89dda38e8107ab8660130e052418b6 Mon Sep 17 00:00:00 2001 From: Kaushal M Date: Tue, 20 Nov 2012 15:17:06 +0530 Subject: cli: XML output for "geo-replication {start|stop}" Change-Id: I8d2213cc00deb458fb765b848d0e3452574cc98f BUG: 864499 Signed-off-by: Kaushal M Reviewed-on: http://review.gluster.org/4217 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- cli/src/cli-rpc-ops.c | 4 +-- cli/src/cli-xml-output.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++ cli/src/cli.h | 4 +++ 3 files changed, 84 insertions(+), 2 deletions(-) (limited to 'cli/src') diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 19451e05..44202037 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -3307,8 +3307,8 @@ gf_cli_gsync_set_cbk (struct rpc_req *req, struct iovec *iov, goto out; if (global_state->mode & GLUSTER_MODE_XML) { - ret = cli_xml_output_dict ("volGeoRep", dict, rsp.op_ret, - rsp.op_errno, rsp.op_errstr); + ret = cli_xml_output_vol_gsync (dict, rsp.op_ret, rsp.op_errno, + rsp.op_errstr); if (ret) gf_log ("cli", GF_LOG_ERROR, "Error outputting to xml"); diff --git a/cli/src/cli-xml-output.c b/cli/src/cli-xml-output.c index 34b046cc..47c0854b 100644 --- a/cli/src/cli-xml-output.c +++ b/cli/src/cli-xml-output.c @@ -3168,3 +3168,81 @@ out: return 0; #endif } + +int +cli_xml_output_vol_gsync (dict_t *dict, int op_ret, int op_errno, + char *op_errstr) +{ +#if (HAVE_LIB_XML) + int ret = -1; + xmlTextWriterPtr writer = NULL; + xmlBufferPtr buf = NULL; + char *master = NULL; + char *slave = NULL; + + int type = 0; + + GF_ASSERT (dict); + + ret = cli_begin_xml_output (&writer, &buf); + if (ret) + goto out; + + ret = cli_xml_output_common (writer, op_ret, op_errno, op_errstr); + if (ret) + goto out; + + /* */ + ret = xmlTextWriterStartElement (writer, (xmlChar *)"geoRep"); + XML_RET_CHECK_AND_GOTO (ret, out); + + ret = dict_get_int32 (dict, "type", &type); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed to get type"); + goto out; + } + + ret = xmlTextWriterWriteFormatElement (writer, (xmlChar *)"type", + "%d", type); + XML_RET_CHECK_AND_GOTO (ret, out); + + switch (type) { + case GF_GSYNC_OPTION_TYPE_START: + case GF_GSYNC_OPTION_TYPE_STOP: + if (dict_get_str (dict, "master", &master) != 0) + master = "???"; + if (dict_get_str (dict, "slave", &slave) != 0) + slave = "???"; + + ret = xmlTextWriterWriteFormatElement (writer, + (xmlChar *)"master", + "%s", master); + XML_RET_CHECK_AND_GOTO (ret, out); + + ret = xmlTextWriterWriteFormatElement (writer, + (xmlChar *)"slave", + "%s", slave); + XML_RET_CHECK_AND_GOTO (ret, out); + + break; + + case GF_GSYNC_OPTION_TYPE_CONFIG: + case GF_GSYNC_OPTION_TYPE_STATUS: + // TODO: XML output for these two types. + default: + ret = 0; + break; + } + + /* */ + ret = xmlTextWriterEndElement (writer); + XML_RET_CHECK_AND_GOTO (ret, out); + + ret = cli_end_xml_output (writer, buf); +out: + gf_log ("cli",GF_LOG_DEBUG, "Returning %d", ret); + return ret; +#else + return 0; +#endif +} diff --git a/cli/src/cli.h b/cli/src/cli.h index 0221f2e8..a5f85ec8 100644 --- a/cli/src/cli.h +++ b/cli/src/cli.h @@ -361,4 +361,8 @@ cli_xml_output_vol_create (dict_t *dict, int op_ret, int op_errno, int cli_xml_output_generic_volume (char *op, dict_t *dict, int op_ret, int op_errno, char *op_errstr); + +int +cli_xml_output_vol_gsync (dict_t *dict, int op_ret, int op_errno, + char *op_errstr); #endif /* __CLI_H__ */ -- cgit