From 8ef81bf02c779e7d126a654bde28d319d0fa823d Mon Sep 17 00:00:00 2001 From: Mohammed Rafi KC Date: Tue, 31 Mar 2015 10:54:10 +0530 Subject: Snapshot/xml:xml output for snapshot clone Snapshot clone is used to create a regular volume from snapshot. Currently snapshot clone is not supporting xml outout. This change introduce a xml output for snapshot clone command Change-Id: I417b480d36f9d84ee088004999b041c9619edd50 BUG: 1207604 Signed-off-by: Mohammed Rafi KC Reviewed-on: http://review.gluster.org/10065 Reviewed-by: Avra Sengupta Tested-by: Avra Sengupta Smoke: Gluster Build System NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System Reviewed-by: Rajesh Joseph --- cli/src/cli-xml-output.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) (limited to 'cli') diff --git a/cli/src/cli-xml-output.c b/cli/src/cli-xml-output.c index d03ddb1239a..8ef12b9a3c9 100644 --- a/cli/src/cli-xml-output.c +++ b/cli/src/cli-xml-output.c @@ -4526,6 +4526,65 @@ out: return ret; } +/* This function will generate snapshot clone output in xml format. + * + * @param writer xmlTextWriterPtr + * @param doc xmlDocPtr + * @param dict dict containing create output + * + * @return 0 on success and -1 on failure + */ +static int +cli_xml_snapshot_clone (xmlTextWriterPtr writer, xmlDocPtr doc, dict_t *dict) +{ + int ret = -1; + char *str_value = NULL; + + GF_VALIDATE_OR_GOTO ("cli", writer, out); + GF_VALIDATE_OR_GOTO ("cli", doc, out); + GF_VALIDATE_OR_GOTO ("cli", dict, out); + + /* */ + ret = xmlTextWriterStartElement (writer, (xmlChar *)"CloneCreate"); + XML_RET_CHECK_AND_GOTO (ret, out); + + /* */ + ret = xmlTextWriterStartElement (writer, (xmlChar *)"volume"); + XML_RET_CHECK_AND_GOTO (ret, out); + + ret = dict_get_str (dict, "clonename", &str_value); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed to get clone name"); + goto out; + } + ret = xmlTextWriterWriteFormatElement (writer, (xmlChar *) "name", + "%s", str_value); + XML_RET_CHECK_AND_GOTO (ret, out); + + + ret = dict_get_str (dict, "snapuuid", &str_value); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed to get clone uuid"); + goto out; + } + + ret = xmlTextWriterWriteFormatElement (writer, (xmlChar *) "uuid", + "%s", str_value); + XML_RET_CHECK_AND_GOTO (ret, out); + + /* */ + ret = xmlTextWriterEndElement (writer); + XML_RET_CHECK_AND_GOTO (ret, out); + + /* */ + ret = xmlTextWriterEndElement (writer); + XML_RET_CHECK_AND_GOTO (ret, out); + + ret = 0; +out: + return ret; +} + /* This function will generate snapshot restore output in xml format. * @@ -5102,10 +5161,13 @@ cli_xml_snapshot_volume_status (xmlTextWriterPtr writer, xmlDocPtr doc, ret = dict_get_str (dict, key, &buffer); if (ret) { - gf_log ("cli", GF_LOG_ERROR, + gf_log ("cli", GF_LOG_INFO, "Unable to get Brick Running"); - goto out; + strcpy (buffer, "N/A"); } + ret = xmlTextWriterWriteFormatElement (writer, + (xmlChar *) "BrickRunning", "%s", buffer); + XML_RET_CHECK_AND_GOTO (ret, out); snprintf (key, sizeof (key), "%s.brick%d.pid", keyprefix, i); @@ -5955,6 +6017,14 @@ cli_xml_output_snapshot (int cmd_type, dict_t *dict, int op_ret, goto out; } break; + case GF_SNAP_OPTION_TYPE_CLONE: + ret = cli_xml_snapshot_clone (writer, doc, dict); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed to create " + "xml output for snapshot clone command"); + goto out; + } + break; case GF_SNAP_OPTION_TYPE_RESTORE: ret = cli_xml_snapshot_restore (writer, doc, dict); if (ret) { -- cgit