summaryrefslogtreecommitdiffstats
path: root/cli/src/cli-cmd-parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'cli/src/cli-cmd-parser.c')
-rw-r--r--cli/src/cli-cmd-parser.c220
1 files changed, 20 insertions, 200 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index 727206a..adfb85e 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -3201,211 +3201,36 @@ out:
return ret;
}
-/* remove command takes either the snapname or the cg name.
- If snap has to be remvoed for a volume, then the volume name
- also should be given in the command. If cg should be removed,
- then volume name is not necessary. Giving "force" will delete
- the snapshot without giving notification.
- "gluster snapshot delete (<volname> -s <snapname> | -c <cgname>) [force]"
- return value: -1 on failure
- 1 if user cancels the operation
- 0 on success
-*/
-int32_t
-cli_snap_remove_parse (dict_t *dict, const char **words, int wordcount,
- unsigned int cmdi, struct cli_state *state)
-{
- uint32_t name_opt_loc = 0;
- int32_t ret = -1;
- uint32_t i = 0;
- gf_boolean_t is_cg = _gf_false;
- const char *question = NULL;
- gf_answer_t answer = GF_ANSWER_NO;
-
- question = "Deleting snap will erase all information about the snap. "
- "Do you want to continue?";
-
- GF_ASSERT (dict);
- GF_ASSERT (words);
-
- /* Finding the "-s or -c" in the cli */
- for (i = cmdi; i < wordcount; i++) {
- if (!strcmp (words[i], "-s") || !strcmp (words[i], "-c")) {
- name_opt_loc = i;
- if (!strcmp (words[i], "-c"))
- is_cg = _gf_true;
- break;
- }
- }
-
- if (name_opt_loc == 0) {
- gf_log ("", GF_LOG_ERROR, "options -s/-c is not found in the "
- "command");
- goto out;
- }
-
- if (name_opt_loc == (wordcount - 1)) {
- gf_log ("", GF_LOG_ERROR, "%s name is not given",
- is_cg?"cg":"snap");
- goto out;
- }
-
- if (!is_cg) {
- if (!strcmp (words[cmdi], "-s")) {
- gf_log ("", GF_LOG_ERROR, "Volume name is not given "
- "for the snapshot deletion");
- ret = -1;
- goto out;
- }
- } else {
- if (strcmp (words[cmdi], "-c")) {
- gf_log ("", GF_LOG_ERROR, "volume name is not needed "
- "for consistency group deletion");
- ret = -1;
- goto out;
- }
- }
-
- /* Saving snapname/cg-name in dict */
- if (name_opt_loc >= cmdi) {
- /* Decide if it's a cg-name or a snapname */
- if (is_cg) {
- ret = dict_set_str (dict, "cgname",
- (char *)words[name_opt_loc + 1]);
- if (ret) {
- gf_log ("", GF_LOG_ERROR, "Unable to save cg-name");
- goto out;
- }
- } else {
- ret = dict_set_int64 (dict, "volcount", 1);
- if (ret) {
- gf_log ("", GF_LOG_ERROR, "failed to set "
- "volcount");
- goto out;
- }
- ret = dict_set_str (dict, "volname1",
- (char *)words[name_opt_loc - 1]);
- if (ret) {
- gf_log ("", GF_LOG_ERROR, "Unable to save volname");
- goto out;
- }
- ret = dict_set_str (dict, "snapname",
- (char *)words[name_opt_loc + 1]);
- if (ret) {
- gf_log ("", GF_LOG_ERROR, "Unable to save snapname");
- goto out;
- }
- }
- }
-
- if ((strcmp (words[wordcount - 1], "force"))) {
- answer = cli_cmd_get_confirmation (state, question);
- if (GF_ANSWER_NO == answer) {
- ret = 1;
- gf_log ("", GF_LOG_DEBUG, "User cancelled "
- "snapshot delete operation");
- goto out;
- }
- }
-
-out:
- return ret;
-}
-
-/* Syntax:
- * snapshot restore (-v <volname> <snapname> | -c <cg-name> )
+/* snapshot restore <snapname>
+ * @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 restore)
+ *
+ * return value : -1 on failure
+ * 0 on success
*/
int
cli_snap_restore_parse (dict_t *dict, const char **words, int wordcount,
- unsigned int cmdi)
-{
- int ret = -1; /* Failure */
- const char* vol_name = NULL;
- const char* snap_name = NULL;
- const char* cg_name = NULL;
+ unsigned int cmdi) {
+
+ int ret = -1;
- GF_ASSERT (dict);
GF_ASSERT (words);
+ GF_ASSERT (dict);
- /* At least CG_INDEX argument should be there for a valid command */
- if (wordcount <= cmdi) {
- gf_log ("cli", GF_LOG_ERROR, "Invalid command: Not enough "
- "arguments");
+ if (wordcount != 3) {
+ gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
goto out;
}
- if (0 == strcmp (words[cmdi], "-v")) {
- /* snapshot restore -v <volname> <snapname>
- *
- * cmdi points to -v, therefore wordcount should be exactly
- * equal to (cmdi + 2) + 1. +1 is added to convert index to
- * count
- */
- if ((cmdi + 3) != wordcount) {
- gf_log ("cli", GF_LOG_ERROR, "Invalid argument count");
- goto out;
- }
-
- vol_name = words[++cmdi];
- snap_name = words[++cmdi];
-
- if ((NULL == vol_name) || (NULL == snap_name)) {
- gf_log ("cli", GF_LOG_ERROR, "Volume or snap "
- "name missing");
- goto out;
- }
-
- /* Single volume should be represented by volcount 1
- * and a volname in dictionary
- */
- ret = dict_set_int64 (dict, "volcount", 1);
- if (ret) {
- gf_log ("cli", GF_LOG_ERROR, "Failed to set "
- "vol count");
- goto out;
- }
-
- /* TODO: Change the index to 0 once Jarvis code is fixed */
- ret = dict_set_str (dict, "volname1", (char *)vol_name);
- if (ret) {
- gf_log ("cli", GF_LOG_ERROR, "Failed to set "
- "volume name");
- goto out;
- }
-
- ret = dict_set_str (dict, "snapname", (char *)snap_name);
- if (ret) {
- gf_log ("cli", GF_LOG_ERROR, "Failed to set "
- "snap name");
- goto out;
- }
- } else if (0 == strcmp (words[cmdi], "-c")) {
- /* If -c option is provided then command should look like
- * snapshot restore -c <cg-name>
- *
- * cmdi points to -c, therefore wordcount should be exactly
- * equal to (cmdi + 1) + 1. +1 is added to convert index to
- * count
- */
- if ((cmdi + 2) != wordcount) {
- gf_log ("cli", GF_LOG_ERROR, "Invalid argument count");
- goto out;
- }
- cg_name = words[++cmdi];
- ret = dict_set_str (dict, "cgname", (char *)cg_name);
- if (ret) {
- gf_log ("cli", GF_LOG_ERROR, "Failed to set "
- "CG name");
- goto out;
- }
- } else {
- gf_log ("cli", GF_LOG_ERROR, "Invalid (%s) option",
- words[cmdi]);
+ ret = dict_set_str (dict, "snapname", (char *)words[cmdi]);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Unable to save snap-name %s",
+ words[cmdi]);
goto out;
}
-
- ret = 0; /* Success */
-out:
+out :
return ret;
}
@@ -3605,13 +3430,8 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options,
case GF_SNAP_OPTION_TYPE_RESTORE:
{
/* Syntax:
- * snapshot restore (-v <volname> <snapname> |
- * -c <cg-name> )
+ * snapshot restore <snapname>
*/
-
- /* Start parsing from the first option after "restore" */
- cmdi = 2;
-
ret = cli_snap_restore_parse (dict, words, wordcount,
cmdi);
if (ret) {