summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2015-02-02 12:53:19 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2015-02-02 13:12:25 (GMT)
commit4a72c67c34b1c5b348e61ab900fb0b64305b9f97 (patch) (unidiff)
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
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--NEWS20
-rw-r--r--doc/eclat-stop.18
-rw-r--r--doc/eclat.1man10
-rw-r--r--etc/default.fln11
-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.c14
-rw-r--r--src/stop-cl.opt33
14 files changed, 194 insertions, 15 deletions
diff --git a/NEWS b/NEWS
index 781203c..ed97650 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
1Eclat NEWS -- history of user-visible changes. 2015-01-23 1Eclat NEWS -- history of user-visible changes. 2015-02-02
2Copyright (C) 2012-2015 Sergey Poznyakoff 2Copyright (C) 2012-2015 Sergey Poznyakoff
3See the end of file for copying conditions. 3See the end of file for copying conditions.
4 4
@@ -12,6 +12,24 @@ Version 1.0.92, (Git)
12 lsaattr describe-image-attribute 12 lsaattr describe-image-attribute
13 setaattr modify-image-attribute 13 setaattr modify-image-attribute
14 14
15* New options:
16
17 -A, --add-parameter=NAME=VALUE
18
19Adds parameter NAME with the given VALUE to the generated AWS request.
20This option is intended for testing new AWS functionality for which
21eclat does not yet provide native support.
22
23 -p, --check-permissions
24
25Checks if you have the required permissions for the action, without
26actually making the request.
27
28* forcibly stop the instance
29
30eclat stop now supports -f (--force) option, which stops the instance
31forcibly.
32
15* Implement signature version 4 signing 33* Implement signature version 4 signing
16 34
17The signature version 4 signing process is now the default. Version 35The signature version 4 signing process is now the default. Version
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
@@ -13,17 +13,21 @@
13.\" 13.\"
14.\" You should have received a copy of the GNU General Public License 14.\" You should have received a copy of the GNU General Public License
15.\" along with Eclat. If not, see <http://www.gnu.org/licenses/>. 15.\" along with Eclat. If not, see <http://www.gnu.org/licenses/>.
16.TH ECLAT-STOP 1 "January 26, 2015" "ECLAT" "Eclat User Reference" 16.TH ECLAT-STOP 1 "February 2, 2015" "ECLAT" "Eclat User Reference"
17.SH NAME 17.SH NAME
18eclat-stop, eclat-stop-instances \- stop EC2 instances 18eclat-stop, eclat-stop-instances \- stop EC2 instances
19.SH SYNOPSIS 19.SH SYNOPSIS
20\fBeclat stop\fR \fIID\fR [\fIID\fR...] 20\fBeclat stop\fR [\fB\-f\fR] [\fB\-\-force\fR] \fIID\fR [\fIID\fR...]
21.PP 21.PP
22\fBeclat stop\fR \fB\-\-help\fR 22\fBeclat stop\fR \fB\-\-help\fR
23.SH DESCRIPTION 23.SH DESCRIPTION
24The command 24The command
25.B stop 25.B stop
26stops running Amazon EBS-backed instances. 26stops running Amazon EBS-backed instances.
27.SH OPTIONS
28.TP
29\fB\-f\fR, \fB\-\-force\fR
30Forcibly stop the instance.
27.SH OUTPUT 31.SH OUTPUT
28The default output format lists on each line the instance ID, its 32The default output format lists on each line the instance ID, its
29previous and current states, separated by single horizontal tab 33previous and current states, separated by single horizontal tab
diff --git a/doc/eclat.1man b/doc/eclat.1man
index 50cc3e2..829bec6 100644
--- a/doc/eclat.1man
+++ b/doc/eclat.1man
@@ -13,7 +13,7 @@
13.\" 13.\"
14.\" You should have received a copy of the GNU General Public License 14.\" You should have received a copy of the GNU General Public License
15.\" along with Eclat. If not, see <http://www.gnu.org/licenses/>. 15.\" along with Eclat. If not, see <http://www.gnu.org/licenses/>.
16.TH ECLAT 1 "January 21, 2015" "ECLAT" "Eclat User Reference" 16.TH ECLAT 1 "February 2, 2015" "ECLAT" "Eclat User Reference"
17.SH NAME 17.SH NAME
18eclat \- EC2 Command Line Administrator Tool 18eclat \- EC2 Command Line Administrator Tool
19.SH SYNOPSIS 19.SH SYNOPSIS
@@ -466,6 +466,14 @@ Dump configuration grammar traces.
466.TP 466.TP
467\fB\-\-dump\-lex\-trace\fR 467\fB\-\-dump\-lex\-trace\fR
468Dump lexical analyzer traces. 468Dump lexical analyzer traces.
469.TP
470\fB\-p\fR, \fB\-\-check\-permissions\fR
471Check if you have the required permissions for the action, without
472actually making the request. This is equivalent to
473\fB\-\-add\-parameter=DryRun=true\fR.
474.TP
475\fB\-A\fR, \fB\-\-add\-parameter=\fINAME\fB=\fIVALUE\fR
476Add parameter to the AWS request.
469.SS Help and additional information 477.SS Help and additional information
470.TP 478.TP
471\fB\-\-config\-help 479\fB\-\-config\-help
diff --git a/etc/default.fln b/etc/default.fln
index 178af18..d3da5eb 100644
--- a/etc/default.fln
+++ b/etc/default.fln
@@ -15,8 +15,15 @@
15 along with Eclat. If not, see <http://www.gnu.org/licenses/>. */ 15 along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
16 16
17if (.Response.Errors) { 17if (.Response.Errors) {
18 error("Error: ",.Response.Errors.Error.Message,"\n"); 18 if (.Response.Errors.Error.Code[DryRunOperation]) {
19 exit(1); 19 print(dequote(.Response.Errors.Error.Message),"\n");
20 } else if (.Response.Errors.Error.Code[UnauthorizedOperation]) {
21 error(dequote(.Response.Errors.Error.Message),"\n");
22 exit(1);
23 } else {
24 error("Error: ",dequote(.Response.Errors.Error.Message),"\n");
25 exit(1);
26 }
20} else { 27} else {
21 error("Unrecognized response:\n"); 28 error("Unrecognized response:\n");
22 dump(.); 29 dump(.);
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 5cfa67a..711bc98 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -53,6 +53,7 @@ libeclat_a_SOURCES=\
53 hmac_sha256.c\ 53 hmac_sha256.c\
54 libeclat.h\ 54 libeclat.h\
55 map.c\ 55 map.c\
56 paramlist.c\
56 path.c\ 57 path.c\
57 req2url.c\ 58 req2url.c\
58 reqaddparm.c\ 59 reqaddparm.c\
diff --git a/lib/forlan.c b/lib/forlan.c
index 2275bc7..977271d 100644
--- a/lib/forlan.c
+++ b/lib/forlan.c
@@ -1049,6 +1049,22 @@ func_decode(forlan_eval_env_t env, struct grecs_list *list)
1049} 1049}
1050 1050
1051static void 1051static void
1052func_dequote(forlan_eval_env_t env, struct grecs_list *list)
1053{
1054 struct forlan_value *val = list->head->data;
1055 char *s = val->v.string;
1056 size_t l = strlen(s);
1057
1058 if (l >= 2 && s[0] == '"' && s[l-1] == '"') {
1059 s++;
1060 l -= 2;
1061 }
1062 env->retval.v.string = grecs_malloc(l + 1);
1063 memcpy(env->retval.v.string, s, l);
1064 env->retval.v.string[l] = 0;
1065}
1066
1067static void
1052func_exit(forlan_eval_env_t env, struct grecs_list *list) 1068func_exit(forlan_eval_env_t env, struct grecs_list *list)
1053{ 1069{
1054 struct forlan_value *val = list->head->data; 1070 struct forlan_value *val = list->head->data;
@@ -1127,6 +1143,7 @@ static struct forlan_function functab[] = {
1127 { "parent", forlan_value_node, "n", 1, 1, func_parent }, 1143 { "parent", forlan_value_node, "n", 1, 1, func_parent },
1128 { "sort", forlan_value_void, "nss", 1, 3, func_sort }, 1144 { "sort", forlan_value_void, "nss", 1, 3, func_sort },
1129 { "decode", forlan_value_literal, "s", 1, 1, func_decode }, 1145 { "decode", forlan_value_literal, "s", 1, 1, func_decode },
1146 { "dequote", forlan_value_literal, "s", 1, 1, func_dequote },
1130 { "exit", forlan_value_void, "s", 1, 1, func_exit }, 1147 { "exit", forlan_value_void, "s", 1, 1, func_exit },
1131 { "empty", forlan_value_boolean, "n", 1, 1, func_empty }, 1148 { "empty", forlan_value_boolean, "n", 1, 1, func_empty },
1132 { "timestamp", forlan_value_literal, "s", 1, 1, func_timestamp }, 1149 { "timestamp", forlan_value_literal, "s", 1, 1, func_timestamp },
diff --git a/lib/libeclat.h b/lib/libeclat.h
index b33f0a2..770fb7d 100644
--- a/lib/libeclat.h
+++ b/lib/libeclat.h
@@ -105,6 +105,8 @@ struct ec2_request *eclat_request_create(int flags, const char *endpoint,
105 const char *uri, char const *region, 105 const char *uri, char const *region,
106 char const *access_key, char const *token); 106 char const *access_key, char const *token);
107void eclat_request_free(struct ec2_request *); 107void eclat_request_free(struct ec2_request *);
108void eclat_request_add_param0(struct ec2_request *req, const char *name,
109 const char *value, int encoded);
108void eclat_request_add_param(struct ec2_request *req, const char *name, 110void eclat_request_add_param(struct ec2_request *req, const char *name,
109 const char *value); 111 const char *value);
110void eclat_request_add_param_encoded(struct ec2_request *req, const char *name, 112void eclat_request_add_param_encoded(struct ec2_request *req, const char *name,
@@ -119,6 +121,13 @@ char *eclat_request_to_url(struct ec2_request *req);
119void eclat_request_encode(struct ec2_request *req); 121void eclat_request_encode(struct ec2_request *req);
120void eclat_request_finalize(struct ec2_request *req); 122void eclat_request_finalize(struct ec2_request *req);
121 123
124void ec2_param_free(void *ptr);
125
126struct grecs_list *ec2_param_list_create(void);
127void ec2_param_list_append(struct grecs_list **lp, char const *name,
128 char const *val);
129void eclat_request_add_param_list(struct ec2_request *req,
130 struct grecs_list *lp);
122 131
123typedef struct eclat_partial_tree *eclat_partial_tree_t; 132typedef struct eclat_partial_tree *eclat_partial_tree_t;
124 133
diff --git a/lib/paramlist.c b/lib/paramlist.c
new file mode 100644
index 0000000..6d6c40a
--- a/dev/null
+++ b/lib/paramlist.c
@@ -0,0 +1,57 @@
1/* This file is part of Eclat.
2 Copyright (C) 2012-2015 Sergey Poznyakoff.
3
4 Eclat is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8
9 Eclat is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
16
17#include <config.h>
18#include <string.h>
19#include "libeclat.h"
20#include "grecs.h"
21
22struct grecs_list *
23ec2_param_list_create()
24{
25 struct grecs_list *lp = grecs_list_create();
26 lp->free_entry = ec2_param_free;
27 return lp;
28}
29
30void
31ec2_param_list_append(struct grecs_list **lpp, char const *name,
32 char const *val)
33{
34 struct ec2_param *p;
35 if (!*lpp)
36 *lpp = ec2_param_list_create();
37 p = grecs_zalloc(sizeof(*p));
38 p->name = grecs_strdup(name);
39 p->value = grecs_strdup(val);
40 p->encoded = 0;
41 grecs_list_append(*lpp, p);
42}
43
44void
45eclat_request_add_param_list(struct ec2_request *req, struct grecs_list *lp)
46{
47 struct grecs_list_entry *ep;
48
49 if (!lp)
50 return;
51 for (ep = lp->head; ep; ep = ep->next) {
52 struct ec2_param *param = ep->data;
53 eclat_request_add_param0(req,
54 param->name, param->value,
55 param->encoded);
56 }
57}
diff --git a/lib/reqcreat.c b/lib/reqcreat.c
index 65f7880..58d7829 100644
--- a/lib/reqcreat.c
+++ b/lib/reqcreat.c
@@ -18,7 +18,7 @@
18#include "libeclat.h" 18#include "libeclat.h"
19#include "grecs.h" 19#include "grecs.h"
20 20
21static void 21void
22ec2_param_free(void *ptr) 22ec2_param_free(void *ptr)
23{ 23{
24 struct ec2_param *p = ptr; 24 struct ec2_param *p = ptr;
diff --git a/src/Makefile.am b/src/Makefile.am
index 1aa8703..7ec7c66 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -102,7 +102,8 @@ OPTFILES=\
102 rmsg-cl.opt\ 102 rmsg-cl.opt\
103 sg-cl.opt\ 103 sg-cl.opt\
104 setiattr-cl.opt\ 104 setiattr-cl.opt\
105 setaattr-cl.opt 105 setaattr-cl.opt\
106 stop-cl.opt
106 107
107eclat_SOURCES += $(OPTFILES:.opt=.h) 108eclat_SOURCES += $(OPTFILES:.opt=.h)
108 109
diff --git a/src/cmdline.opt b/src/cmdline.opt
index 6da23c2..8a707ec 100644
--- a/src/cmdline.opt
+++ b/src/cmdline.opt
@@ -259,6 +259,12 @@ BEGIN
259 parse_debug_level("curl.1"); 259 parse_debug_level("curl.1");
260END 260END
261 261
262OPTION(check-permissions,p,,
263 [<check if the requested action is permitted for current account>])
264BEGIN
265 ec2_param_list_append(&extra_param, "DryRun", "true");
266END
267
262OPTION(dump-grammar-trace,,, 268OPTION(dump-grammar-trace,,,
263 [<dump configuration grammar traces>]) 269 [<dump configuration grammar traces>])
264BEGIN 270BEGIN
@@ -279,6 +285,16 @@ BEGIN
279 } 285 }
280END 286END
281 287
288OPTION(add-parameter,A,NAME=VALUE,
289 [<pass additional parameter to the AWS request>])
290BEGIN
291 char *p = strchr(optarg, '=');
292 if (!p)
293 die(EX_USAGE, "malformed parameter: %s", optarg);
294 *p++ = 0;
295 ec2_param_list_append(&extra_param, optarg, p);
296END
297
282GROUP([<Additional help>]) 298GROUP([<Additional help>])
283OPTION(config-help,,, 299OPTION(config-help,,,
284 [<show configuration file summary>]) 300 [<show configuration file summary>])
diff --git a/src/eclat.c b/src/eclat.c
index 8cadebd..69efa8e 100644
--- a/src/eclat.c
+++ b/src/eclat.c
@@ -43,6 +43,8 @@ char *format_file;
43char *test_map_name; 43char *test_map_name;
44enum eclat_confirm_mode confirm_mode; 44enum eclat_confirm_mode confirm_mode;
45int translate_option = -1; 45int translate_option = -1;
46struct grecs_list *extra_param;
47
46 48
47FILE *xml_dump_file; 49FILE *xml_dump_file;
48 50
@@ -566,9 +568,10 @@ find_format(const char *name)
566 return NULL; 568 return NULL;
567 key.name = (char*) name; 569 key.name = (char*) name;
568 defn = grecs_symtab_lookup_or_install(format_table, &key, NULL); 570 defn = grecs_symtab_lookup_or_install(format_table, &key, NULL);
569 if (!defn) 571 if (!defn) {
572 err("no such format: %s", name);
570 return NULL; 573 return NULL;
571 574 }
572 env = forlan_parse_buffer(defn->text, strlen(defn->text), 575 env = forlan_parse_buffer(defn->text, strlen(defn->text),
573 &defn->locus.beg); 576 &defn->locus.beg);
574 return env; 577 return env;
@@ -656,6 +659,7 @@ eclat_do_command(eclat_command_env_t *env, struct eclat_command *command,
656 endpoint, "/", 659 endpoint, "/",
657 region_name, access_key, 660 region_name, access_key,
658 security_token); 661 security_token);
662 eclat_request_add_param_list(env->request, extra_param);
659 } 663 }
660 664
661 if (command->tag) 665 if (command->tag)
diff --git a/src/startstop.c b/src/startstop.c
index f5346c4..98f4e12 100644
--- a/src/startstop.c
+++ b/src/startstop.c
@@ -61,19 +61,23 @@ eclat_start_instance(eclat_command_env_t *env, int argc, char **argv)
61 return start_stop_instance(env, argc - i, argv + i); 61 return start_stop_instance(env, argc - i, argv + i);
62} 62}
63 63
64
65static int force;
66
67#include "stop-cl.h"
68
64int 69int
65eclat_stop_instance(eclat_command_env_t *env, int argc, char **argv) 70eclat_stop_instance(eclat_command_env_t *env, int argc, char **argv)
66{ 71{
67 int i; 72 int i;
68 73
69 parse_options(env->cmd, 74 parse_stop_options(env, argc, argv, &i);
70 "Stop named instances",
71 argc, argv, &i);
72
73 debug(ECLAT_DEBCAT_MAIN, 1, ("stopping instances")); 75 debug(ECLAT_DEBCAT_MAIN, 1, ("stopping instances"));
76 if (force)
77 eclat_request_add_param(env->request, "Force", "1");
74 return start_stop_instance(env, argc - i, argv + i); 78 return start_stop_instance(env, argc - i, argv + i);
75} 79}
76 80
77int 81int
78eclat_reboot_instance(eclat_command_env_t *env, int argc, char **argv) 82eclat_reboot_instance(eclat_command_env_t *env, int argc, char **argv)
79{ 83{
diff --git a/src/stop-cl.opt b/src/stop-cl.opt
new file mode 100644
index 0000000..a2aae61
--- a/dev/null
+++ b/src/stop-cl.opt
@@ -0,0 +1,33 @@
1/* This file is part of Eclat.
2 Copyright (C) 2012-2015 Sergey Poznyakoff.
3
4 Eclat is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8
9 Eclat is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
16
17ECLAT_CL_BEGIN([<Stop named instances>],
18 [<ID [ID...]>])
19
20
21OPTION(force,f,,
22 [<force stopping the instance>])
23BEGIN
24 force = 1;
25END
26
27ECLAT_CL_END
28
29ECLAT_CL_PARSER(parse_stop_options, [<int argc, char *argv[], int *index>], [<
30{
31 GETOPT(argc, argv, *index)
32}
33>]) \ No newline at end of file

Return to:

Send suggestions and report system problems to the System administrator.