diff options
| author | Pranith Kumar K <pranithk@gluster.com> | 2010-09-07 04:03:31 +0000 | 
|---|---|---|
| committer | Vijay Bellur <vijay@dev.gluster.com> | 2010-09-07 07:45:50 -0700 | 
| commit | cb0352cd4f4748ee6e33bc64d2e2b09d09fe20eb (patch) | |
| tree | 933e86e16cce120e4c3197668b310c36c1feade8 /cli | |
| parent | 406e42973feeae6b78626f2db19971dc8f79c25f (diff) | |
cli: add script mode for gluster
Signed-off-by: Pranith Kumar K <pranithk@gluster.com>
Signed-off-by: Vijay Bellur <vijay@dev.gluster.com>
BUG: 1554 (add script mode for gluster)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1554
Diffstat (limited to 'cli')
| -rw-r--r-- | cli/src/cli-cmd-misc.c | 10 | ||||
| -rw-r--r-- | cli/src/cli-cmd-volume.c | 50 | ||||
| -rw-r--r-- | cli/src/cli-cmd.h | 5 | ||||
| -rw-r--r-- | cli/src/cli.h | 4 | ||||
| -rw-r--r-- | cli/src/input.c | 22 | 
5 files changed, 69 insertions, 22 deletions
diff --git a/cli/src/cli-cmd-misc.c b/cli/src/cli-cmd-misc.c index 306a7628faa..7833456b730 100644 --- a/cli/src/cli-cmd-misc.c +++ b/cli/src/cli-cmd-misc.c @@ -61,8 +61,10 @@ cli_cmd_display_help (struct cli_state *state, struct cli_cmd_word *in_word,          for (cmd = cli_probe_cmds; cmd->pattern; cmd++)                  cli_out ("%s - %s", cmd->pattern, cmd->desc); -        for (cmd = cli_misc_cmds; cmd->pattern; cmd++) -                cli_out ("%s - %s", cmd->pattern, cmd->desc); +        for (cmd = cli_misc_cmds; cmd->pattern; cmd++) { +                if (cmd->cbk) +                        cli_out ("%s - %s", cmd->pattern, cmd->desc); +        }          if (!state->rl_enabled)                  exit (0); @@ -79,6 +81,10 @@ struct cli_cmd cli_misc_cmds[] = {             cli_cmd_display_help,             "display command options"}, +        { "mode script", +           NULL, +           "assign gluster execution mode"}, +          { NULL, NULL, NULL }  }; diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index ce831055740..01fff9bf11a 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -236,6 +236,24 @@ out:          return ret;  } +gf_answer_t +cli_cmd_get_confirmation (struct cli_state *state, const char *question) +{ +        char                    answer = '\0'; +        char                    flush = '\0'; + +        if (GLUSTER_MODE_SCRIPT == state->mode) +                return GF_ANSWER_YES; +        printf ("%s (y/n) ", question); +        answer = getchar (); +        flush = answer; +        while ('\n' != flush) +                flush = getchar (); +        if ('y' != answer) { +                return GF_ANSWER_NO; +        } +        return GF_ANSWER_YES; +}  int  cli_cmd_volume_stop_cbk (struct cli_state *state, struct cli_cmd_word *word, @@ -246,8 +264,10 @@ cli_cmd_volume_stop_cbk (struct cli_state *state, struct cli_cmd_word *word,          call_frame_t            *frame = NULL;          int                     flags   = 0;          gf1_cli_stop_vol_req    req = {0,}; -        char                    answer; -        char                    flush; +        gf_answer_t             answer = GF_ANSWER_NO; + +        const char *question = "Stopping volume will make its data inaccessible. " +                               "Do you want to Continue?";          frame = create_frame (THIS, THIS->ctx->pool);          if (!frame) @@ -272,13 +292,9 @@ cli_cmd_volume_stop_cbk (struct cli_state *state, struct cli_cmd_word *word,                  }          } -        printf ("Stopping volume will make its data inaccessible. " -                "Do you want to Continue? (y/n) "); -        answer = getchar (); -        flush = answer; -        while ('\n' != flush) -                flush = getchar (); -        if ('y' != answer) { +        answer = cli_cmd_get_confirmation (state, question); + +        if (GF_ANSWER_NO == answer) {                  ret = 0;                  goto out;          } @@ -473,8 +489,10 @@ cli_cmd_volume_remove_brick_cbk (struct cli_state *state,          rpc_clnt_procedure_t    *proc = NULL;          call_frame_t            *frame = NULL;          dict_t                  *options = NULL; -        char                    answer; -        char                    flush; +        gf_answer_t             answer = GF_ANSWER_NO; + +        const char *question = "Removing brick(s) can result in data loss. " +                               "Do you want to Continue?";          frame = create_frame (THIS, THIS->ctx->pool);          if (!frame) @@ -487,13 +505,9 @@ cli_cmd_volume_remove_brick_cbk (struct cli_state *state,                  goto out;          } -        printf ("Removing brick(s) can result in data loss. " -                "Do you want to Continue? (y/n) "); -        answer = getchar (); -        flush = answer; -        while ('\n' != flush) -                flush = getchar (); -        if ('y' != answer) { +        answer = cli_cmd_get_confirmation (state, question); + +        if (GF_ANSWER_NO == answer) {                  ret = 0;                  goto out;          } diff --git a/cli/src/cli-cmd.h b/cli/src/cli-cmd.h index b7cd7aadc63..7dda509dd0c 100644 --- a/cli/src/cli-cmd.h +++ b/cli/src/cli-cmd.h @@ -27,6 +27,11 @@  #include "cli.h" +typedef enum { +        GF_ANSWER_YES = 1, +        GF_ANSWER_NO  = 2 +} gf_answer_t; +  struct cli_cmd {          const char     *pattern;          cli_cmd_cbk_t  *cbk; diff --git a/cli/src/cli.h b/cli/src/cli.h index fdf53421f49..eaa638c29d6 100644 --- a/cli/src/cli.h +++ b/cli/src/cli.h @@ -39,6 +39,9 @@ enum argp_option_keys {  	ARGP_PORT_KEY = 'p',  }; +enum gluster_mode { +        GLUSTER_MODE_SCRIPT = 1 +};  struct cli_state;  struct cli_cmd_word;  struct cli_cmd_tree; @@ -96,6 +99,7 @@ struct cli_state {          char                **matchesp;          int                   remote_port; +        int                   mode;  };  struct cli_local { diff --git a/cli/src/input.c b/cli/src/input.c index e762fbd1385..2c67b354d4c 100644 --- a/cli/src/input.c +++ b/cli/src/input.c @@ -41,7 +41,11 @@ cli_batch (void *d)          state = d; -        ret = cli_cmd_process (state, state->argc, state->argv); +        if (state->mode == GLUSTER_MODE_SCRIPT) +                ret = cli_cmd_process (state, state->argc - 2, state->argv + 2); +        else +                ret = cli_cmd_process (state, state->argc, state->argv); +          gf_log ("", GF_LOG_NORMAL, "Exiting with: %d", ret);          exit (ret); @@ -82,8 +86,22 @@ int  cli_input_init (struct cli_state *state)  {          int  ret = 0; +        gf_boolean_t  is_batch = _gf_false; + +        if (1 < state->argc) { +                if (!strcmp ("mode", state->argv[0]) && +                    !strcmp ("script", state->argv[1])) { +                        state->mode = GLUSTER_MODE_SCRIPT; +                        if (2 < state->argc) +                                is_batch = _gf_true; +                } else { +                        is_batch = _gf_true; +                } +        } else if (1 == state->argc) { +                is_batch = _gf_true; +        } -        if (state->argc) { +        if (is_batch) {                  ret = pthread_create (&state->input, NULL, cli_batch, state);                  return ret;          }  | 
