From fabee8f75c56f18c949b79dcc751c2855b5c7514 Mon Sep 17 00:00:00 2001 From: Sachin Pandit Date: Thu, 20 Feb 2014 14:00:22 +0530 Subject: cli/snapshot : snapshot delete CLI changes. Syntax: gluster snapshot delete Change-Id: I5de7b9a79eeba12e4f0b8abfbe96a2db738f25c0 Signed-off-by: Sachin Pandit Reviewed-on: http://review.gluster.org/7144 Reviewed-by: Rajesh Joseph Tested-by: Rajesh Joseph --- cli/src/cli-cmd-parser.c | 82 +++++++++++++++++++++++++++++++++------------- cli/src/cli-cmd-snapshot.c | 2 +- 2 files changed, 61 insertions(+), 23 deletions(-) (limited to 'cli') diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 6b8f2929f..f14fc702c 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -3409,6 +3409,52 @@ out: return ret; } +/* snapshot delete + * @arg-0, dict : Request Dictionary to be sent to server side. + * @arg-1, words : Contains individual words of CLI command. + * @arg-2, wordcount: Contains number of words present in the CLI command. + * @arg-3, cmdi : command index, here cmdi is "2" (gluster snapshot delete) + * + * return value : -1 on failure + * 0 on success + */ +int +cli_snap_delete_parse (dict_t *dict, const char **words, int wordcount, + unsigned int cmdi, struct cli_state *state) { + + int ret = -1; + const char *question = NULL; + gf_answer_t answer = GF_ANSWER_NO; + + question = "Deleting snap will erase all the information about " + "the snap. Do you still want to continue?"; + + GF_ASSERT (words); + GF_ASSERT (dict); + + if (wordcount != 3) { + gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; + } + + ret = dict_set_str (dict, "snap-name", (char *)words[cmdi]); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Unable to save snap-name %s", + words[cmdi]); + goto out; + } + + answer = cli_cmd_get_confirmation (state, question); + if (GF_ANSWER_NO == answer) { + ret = -1; + gf_log ("cli", GF_LOG_DEBUG, "User cancelled " + "snapshot delete operation"); + goto out; + } +out : + return ret; +} + int32_t cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, @@ -3518,29 +3564,21 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, break; } - case GF_SNAP_OPTION_TYPE_DELETE: - { - /*syntax: - snapshot remove [ -s | -c ] - */ - w = str_getunamb (words[2], opwords); - if (w) { - gf_log ("", GF_LOG_ERROR, "Opword Mismatch"); - goto out; - } - - cmdi = 2; + case GF_SNAP_OPTION_TYPE_DELETE: + { + /* Syntax : + * gluster snapshot delete + */ + ret = cli_snap_delete_parse (dict, words, wordcount, + cmdi, state); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed to parse " + "snapshot delete command"); + goto out; + } + break; + } - ret = cli_snap_remove_parse (dict, words, - wordcount, cmdi, state); - if (ret) { - if (ret < 0) - gf_log ("", GF_LOG_ERROR, - "remove command parsing failed."); - goto out; - } - break; - } case GF_SNAP_OPTION_TYPE_CONFIG: { /* snapshot config [snap-max-hard-limit | diff --git a/cli/src/cli-cmd-snapshot.c b/cli/src/cli-cmd-snapshot.c index 4d824a007..93e154eab 100644 --- a/cli/src/cli-cmd-snapshot.c +++ b/cli/src/cli-cmd-snapshot.c @@ -103,7 +103,7 @@ struct cli_cmd snapshot_cmds[] = { cli_cmd_snapshot_cbk, "Snapshot Config." }, - {"snapshot delete ( -s | -c ) [force]", + {"snapshot delete ", cli_cmd_snapshot_cbk, "Snapshot Delete." }, -- cgit