aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2015-02-02 14:53:19 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2015-02-02 15:12:25 +0200
commit4a72c67c34b1c5b348e61ab900fb0b64305b9f97 (patch)
treebd3c91c42a14ac50f2406ba8153b04d2099cd9ab
parentf9536d8285625d4263c5b2dd0ab2a6773dd2b618 (diff)
downloadeclat-4a72c67c34b1c5b348e61ab900fb0b64305b9f97.tar.gz
eclat-4a72c67c34b1c5b348e61ab900fb0b64305b9f97.tar.bz2
New options: --check-permissions and --add-parameter
* NEWS: Update. * doc/eclat-stop.1: Update. * doc/eclat.1man: Update. * etc/default.fln: Special handling for DryRunOperation and UnauthorizedOperation codes. * lib/paramlist.c: New file. * lib/Makefile.am (libeclat_a_SOURCES): Add paramlist.c * lib/forlan.c: New function dequote. * lib/libeclat.h (eclat_request_add_param0) (ec2_param_free, ec2_param_list_create) (ec2_param_list_append) (eclat_request_add_param_list): New protos. * lib/reqcreat.c (ec2_param_free): Remove static qualifier. * src/stop-cl.opt: New file. * src/Makefile.am (OPTFILES): Add stop-cl.opt * src/cmdline.opt: New options: --check-permissions and --add-parameter. * src/eclat.c (extra_param): New global. (find_format): print error message if no such format is found. * src/startstop.c (eclat_stop_instance): Use parse_stop_options
-rw-r--r--NEWS20
-rw-r--r--doc/eclat-stop.18
-rw-r--r--doc/eclat.1man10
-rw-r--r--etc/default.fln9
-rw-r--r--lib/Makefile.am1
-rw-r--r--lib/forlan.c17
-rw-r--r--lib/libeclat.h9
-rw-r--r--lib/paramlist.c57
-rw-r--r--lib/reqcreat.c2
-rw-r--r--src/Makefile.am3
-rw-r--r--src/cmdline.opt16
-rw-r--r--src/eclat.c8
-rw-r--r--src/startstop.c12
-rw-r--r--src/stop-cl.opt33
14 files changed, 192 insertions, 13 deletions
diff --git a/NEWS b/NEWS
index 781203c..ed97650 100644
--- a/NEWS
+++ b/NEWS
@@ -1,2 +1,2 @@
-Eclat NEWS -- history of user-visible changes. 2015-01-23
+Eclat NEWS -- history of user-visible changes. 2015-02-02
Copyright (C) 2012-2015 Sergey Poznyakoff
@@ -14,2 +14,20 @@ Version 1.0.92, (Git)
+* New options:
+
+ -A, --add-parameter=NAME=VALUE
+
+Adds parameter NAME with the given VALUE to the generated AWS request.
+This option is intended for testing new AWS functionality for which
+eclat does not yet provide native support.
+
+ -p, --check-permissions
+
+Checks if you have the required permissions for the action, without
+actually making the request.
+
+* forcibly stop the instance
+
+eclat stop now supports -f (--force) option, which stops the instance
+forcibly.
+
* Implement signature version 4 signing
diff --git a/doc/eclat-stop.1 b/doc/eclat-stop.1
index 5adbe61..a8f61a8 100644
--- a/doc/eclat-stop.1
+++ b/doc/eclat-stop.1
@@ -15,3 +15,3 @@
.\" along with Eclat. If not, see <http://www.gnu.org/licenses/>.
-.TH ECLAT-STOP 1 "January 26, 2015" "ECLAT" "Eclat User Reference"
+.TH ECLAT-STOP 1 "February 2, 2015" "ECLAT" "Eclat User Reference"
.SH NAME
@@ -19,3 +19,3 @@ eclat-stop, eclat-stop-instances \- stop EC2 instances
.SH SYNOPSIS
-\fBeclat stop\fR \fIID\fR [\fIID\fR...]
+\fBeclat stop\fR [\fB\-f\fR] [\fB\-\-force\fR] \fIID\fR [\fIID\fR...]
.PP
@@ -26,2 +26,6 @@ The command
stops running Amazon EBS-backed instances.
+.SH OPTIONS
+.TP
+\fB\-f\fR, \fB\-\-force\fR
+Forcibly stop the instance.
.SH OUTPUT
diff --git a/doc/eclat.1man b/doc/eclat.1man
index 50cc3e2..829bec6 100644
--- a/doc/eclat.1man
+++ b/doc/eclat.1man
@@ -15,3 +15,3 @@
.\" along with Eclat. If not, see <http://www.gnu.org/licenses/>.
-.TH ECLAT 1 "January 21, 2015" "ECLAT" "Eclat User Reference"
+.TH ECLAT 1 "February 2, 2015" "ECLAT" "Eclat User Reference"
.SH NAME
@@ -468,2 +468,10 @@ Dump configuration grammar traces.
Dump lexical analyzer traces.
+.TP
+\fB\-p\fR, \fB\-\-check\-permissions\fR
+Check if you have the required permissions for the action, without
+actually making the request. This is equivalent to
+\fB\-\-add\-parameter=DryRun=true\fR.
+.TP
+\fB\-A\fR, \fB\-\-add\-parameter=\fINAME\fB=\fIVALUE\fR
+Add parameter to the AWS request.
.SS Help and additional information
diff --git a/etc/default.fln b/etc/default.fln
index 178af18..d3da5eb 100644
--- a/etc/default.fln
+++ b/etc/default.fln
@@ -17,5 +17,12 @@
if (.Response.Errors) {
- error("Error: ",.Response.Errors.Error.Message,"\n");
+ if (.Response.Errors.Error.Code[DryRunOperation]) {
+ print(dequote(.Response.Errors.Error.Message),"\n");
+ } else if (.Response.Errors.Error.Code[UnauthorizedOperation]) {
+ error(dequote(.Response.Errors.Error.Message),"\n");
exit(1);
} else {
+ error("Error: ",dequote(.Response.Errors.Error.Message),"\n");
+ exit(1);
+ }
+} else {
error("Unrecognized response:\n");
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 5cfa67a..711bc98 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -55,2 +55,3 @@ libeclat_a_SOURCES=\
map.c\
+ paramlist.c\
path.c\
diff --git a/lib/forlan.c b/lib/forlan.c
index 2275bc7..977271d 100644
--- a/lib/forlan.c
+++ b/lib/forlan.c
@@ -1051,2 +1051,18 @@ func_decode(forlan_eval_env_t env, struct grecs_list *list)
static void
+func_dequote(forlan_eval_env_t env, struct grecs_list *list)
+{
+ struct forlan_value *val = list->head->data;
+ char *s = val->v.string;
+ size_t l = strlen(s);
+
+ if (l >= 2 && s[0] == '"' && s[l-1] == '"') {
+ s++;
+ l -= 2;
+ }
+ env->retval.v.string = grecs_malloc(l + 1);
+ memcpy(env->retval.v.string, s, l);
+ env->retval.v.string[l] = 0;
+}
+
+static void
func_exit(forlan_eval_env_t env, struct grecs_list *list)
@@ -1129,2 +1145,3 @@ static struct forlan_function functab[] = {
{ "decode", forlan_value_literal, "s", 1, 1, func_decode },
+ { "dequote", forlan_value_literal, "s", 1, 1, func_dequote },
{ "exit", forlan_value_void, "s", 1, 1, func_exit },
diff --git a/lib/libeclat.h b/lib/libeclat.h
index b33f0a2..770fb7d 100644
--- a/lib/libeclat.h
+++ b/lib/libeclat.h
@@ -107,2 +107,4 @@ struct ec2_request *eclat_request_create(int flags, const char *endpoint,
void eclat_request_free(struct ec2_request *);
+void eclat_request_add_param0(struct ec2_request *req, const char *name,
+ const char *value, int encoded);
void eclat_request_add_param(struct ec2_request *req, const char *name,
@@ -121,2 +123,9 @@ void eclat_request_finalize(struct ec2_request *req);
+void ec2_param_free(void *ptr);
+
+struct grecs_list *ec2_param_list_create(void);
+void ec2_param_list_append(struct grecs_list **lp, char const *name,
+ char const *val);
+void eclat_request_add_param_list(struct ec2_request *req,
+ struct grecs_list *lp);
diff --git a/lib/paramlist.c b/lib/paramlist.c
new file mode 100644
index 0000000..6d6c40a
--- /dev/null
+++ b/lib/paramlist.c
@@ -0,0 +1,57 @@
+/* This file is part of Eclat.
+ Copyright (C) 2012-2015 Sergey Poznyakoff.
+
+ Eclat is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ Eclat is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include <string.h>
+#include "libeclat.h"
+#include "grecs.h"
+
+struct grecs_list *
+ec2_param_list_create()
+{
+ struct grecs_list *lp = grecs_list_create();
+ lp->free_entry = ec2_param_free;
+ return lp;
+}
+
+void
+ec2_param_list_append(struct grecs_list **lpp, char const *name,
+ char const *val)
+{
+ struct ec2_param *p;
+ if (!*lpp)
+ *lpp = ec2_param_list_create();
+ p = grecs_zalloc(sizeof(*p));
+ p->name = grecs_strdup(name);
+ p->value = grecs_strdup(val);
+ p->encoded = 0;
+ grecs_list_append(*lpp, p);
+}
+
+void
+eclat_request_add_param_list(struct ec2_request *req, struct grecs_list *lp)
+{
+ struct grecs_list_entry *ep;
+
+ if (!lp)
+ return;
+ for (ep = lp->head; ep; ep = ep->next) {
+ struct ec2_param *param = ep->data;
+ eclat_request_add_param0(req,
+ param->name, param->value,
+ param->encoded);
+ }
+}
diff --git a/lib/reqcreat.c b/lib/reqcreat.c
index 65f7880..58d7829 100644
--- a/lib/reqcreat.c
+++ b/lib/reqcreat.c
@@ -20,3 +20,3 @@
-static void
+void
ec2_param_free(void *ptr)
diff --git a/src/Makefile.am b/src/Makefile.am
index 1aa8703..7ec7c66 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -104,3 +104,4 @@ OPTFILES=\
setiattr-cl.opt\
- setaattr-cl.opt
+ setaattr-cl.opt\
+ stop-cl.opt
diff --git a/src/cmdline.opt b/src/cmdline.opt
index 6da23c2..8a707ec 100644
--- a/src/cmdline.opt
+++ b/src/cmdline.opt
@@ -261,2 +261,8 @@ END
+OPTION(check-permissions,p,,
+ [<check if the requested action is permitted for current account>])
+BEGIN
+ ec2_param_list_append(&extra_param, "DryRun", "true");
+END
+
OPTION(dump-grammar-trace,,,
@@ -281,2 +287,12 @@ END
+OPTION(add-parameter,A,NAME=VALUE,
+ [<pass additional parameter to the AWS request>])
+BEGIN
+ char *p = strchr(optarg, '=');
+ if (!p)
+ die(EX_USAGE, "malformed parameter: %s", optarg);
+ *p++ = 0;
+ ec2_param_list_append(&extra_param, optarg, p);
+END
+
GROUP([<Additional help>])
diff --git a/src/eclat.c b/src/eclat.c
index 8cadebd..69efa8e 100644
--- a/src/eclat.c
+++ b/src/eclat.c
@@ -45,2 +45,4 @@ enum eclat_confirm_mode confirm_mode;
int translate_option = -1;
+struct grecs_list *extra_param;
+
@@ -568,5 +570,6 @@ find_format(const char *name)
defn = grecs_symtab_lookup_or_install(format_table, &key, NULL);
- if (!defn)
+ if (!defn) {
+ err("no such format: %s", name);
return NULL;
-
+ }
env = forlan_parse_buffer(defn->text, strlen(defn->text),
@@ -658,2 +661,3 @@ eclat_do_command(eclat_command_env_t *env, struct eclat_command *command,
security_token);
+ eclat_request_add_param_list(env->request, extra_param);
}
diff --git a/src/startstop.c b/src/startstop.c
index f5346c4..98f4e12 100644
--- a/src/startstop.c
+++ b/src/startstop.c
@@ -63,2 +63,7 @@ eclat_start_instance(eclat_command_env_t *env, int argc, char **argv)
+
+static int force;
+
+#include "stop-cl.h"
+
int
@@ -68,7 +73,6 @@ eclat_stop_instance(eclat_command_env_t *env, int argc, char **argv)
- parse_options(env->cmd,
- "Stop named instances",
- argc, argv, &i);
-
+ parse_stop_options(env, argc, argv, &i);
debug(ECLAT_DEBCAT_MAIN, 1, ("stopping instances"));
+ if (force)
+ eclat_request_add_param(env->request, "Force", "1");
return start_stop_instance(env, argc - i, argv + i);
diff --git a/src/stop-cl.opt b/src/stop-cl.opt
new file mode 100644
index 0000000..a2aae61
--- /dev/null
+++ b/src/stop-cl.opt
@@ -0,0 +1,33 @@
+/* This file is part of Eclat.
+ Copyright (C) 2012-2015 Sergey Poznyakoff.
+
+ Eclat is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ Eclat is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
+
+ECLAT_CL_BEGIN([<Stop named instances>],
+ [<ID [ID...]>])
+
+
+OPTION(force,f,,
+ [<force stopping the instance>])
+BEGIN
+ force = 1;
+END
+
+ECLAT_CL_END
+
+ECLAT_CL_PARSER(parse_stop_options, [<int argc, char *argv[], int *index>], [<
+{
+ GETOPT(argc, argv, *index)
+}
+>]) \ No newline at end of file

Return to:

Send suggestions and report system problems to the System administrator.