aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-02-09 15:34:03 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2013-02-09 15:57:58 +0200
commitdaae7b2e4fbcecbb11f85949358c189fc25291b6 (patch)
treea9a3c8a4e8fb77f74f277639c25d28e66950a85b /src
parent0618216327920bc87032948daea267f247db317a (diff)
downloadeclat-daae7b2e4fbcecbb11f85949358c189fc25291b6.tar.gz
eclat-daae7b2e4fbcecbb11f85949358c189fc25291b6.tar.bz2
Make all tag-related subcommands accept the same set of options.
* src/dscrtags-cl.opt: New file. * src/Makefile.am (OPTFILES): Add dscrtags-cl.opt * src/cretags.c (process_tags): New parameter "require_tags". All uses updated. * src/dscrtags.c: Include dscrtags-cl.h. (eclat_describe_tags): Accept the same set of arguments as eclat_create_tags and eclat_delete_tags. * src/eclat.h (describe_query_update): New proto. * src/util.c (describe_query_update): New function. (describe_query_create): Rewrite as an entry point to describe_query_update. * doc/eclat-delete-tags.1: Update. * doc/eclat-describe-tags.1: Update * grecs: Upgrade * src/dscrsnapattr.c (eclat_modify_snapshot_attribute) (eclat_reset_snapshot_attribute): Remove unused locals.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/cretags.c10
-rw-r--r--src/dscrsnapattr.c6
-rw-r--r--src/dscrtags-cl.opt121
-rw-r--r--src/dscrtags.c59
-rw-r--r--src/eclat.h3
-rw-r--r--src/util.c15
7 files changed, 164 insertions, 51 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 996f2d8..10c5cf0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -69,6 +69,7 @@ OPTFILES=\
dscrinststat-cl.opt\
dscrsecgrps-cl.opt\
dscrsnap-cl.opt\
+ dscrtags-cl.opt\
generic-cl.opt\
reladdr-cl.opt
diff --git a/src/cretags.c b/src/cretags.c
index 872c319..08aa201 100644
--- a/src/cretags.c
+++ b/src/cretags.c
@@ -18,7 +18,7 @@
#include "cretags-cl.h"
static int
-process_tags(eclat_command_env_t *env, int argc, char **argv)
+process_tags(eclat_command_env_t *env, int argc, char **argv, int require_tags)
{
int i, j;
struct ec2_query *q = env->query;
@@ -26,13 +26,15 @@ process_tags(eclat_command_env_t *env, int argc, char **argv)
size_t bufsize = 0;
struct grecs_list_entry *ep;
+ if (!require_tags)
+ proginfo.args_doc = "[TAG[=VALUE...]]";
parse_options(argc, argv, &i);
argv += i;
argc -= i;
if (!reslist->head)
die(EX_USAGE, "no resource IDs supplied");
- if (argc == 0 && !from_file)
+ if (require_tags && argc == 0 && !from_file)
die(EX_USAGE, "no tags supplied");
for (ep = reslist->head, i = 1; ep; ep = ep->next, i++) {
@@ -113,7 +115,7 @@ eclat_create_tags(eclat_command_env_t *env, int argc, char **argv)
{
proginfo.progname = "eclat create-tags";
proginfo.docstring = "create tags for the specified resources";
- return process_tags(env, argc, argv);
+ return process_tags(env, argc, argv, 1);
}
int
@@ -121,5 +123,5 @@ eclat_delete_tags(eclat_command_env_t *env, int argc, char **argv)
{
proginfo.progname = "eclat delete-tags";
proginfo.docstring = "delete tags from the specified resources";
- return process_tags(env, argc, argv);
+ return process_tags(env, argc, argv, 0);
}
diff --git a/src/dscrsnapattr.c b/src/dscrsnapattr.c
index 83b3117..92778db 100644
--- a/src/dscrsnapattr.c
+++ b/src/dscrsnapattr.c
@@ -92,7 +92,6 @@ eclat_modify_snapshot_attribute(eclat_command_env_t *env,
{
int i;
struct ec2_query *q = env->query;
- const char *attrname;
char *bufptr = NULL;
size_t bufsize = 0;
@@ -106,7 +105,7 @@ eclat_modify_snapshot_attribute(eclat_command_env_t *env,
if (argc < 2)
die(EX_USAGE, "wrong number of arguments");
for (i = 0; i < argc - 1; i++) {
- const char *action, *what, *arg;
+ const char *action, *what;
switch (argv[i][0]) {
case 'u':
@@ -152,9 +151,6 @@ eclat_reset_snapshot_attribute(eclat_command_env_t *env,
{
int i;
struct ec2_query *q = env->query;
- const char *attrname;
- char *bufptr = NULL;
- size_t bufsize = 0;
generic_proginfo->args_doc = "SNAP-ID";
generic_parse_options("eclat reset-snapshot-attribute",
diff --git a/src/dscrtags-cl.opt b/src/dscrtags-cl.opt
new file mode 100644
index 0000000..4adfea0
--- /dev/null
+++ b/src/dscrtags-cl.opt
@@ -0,0 +1,121 @@
+/* This file is part of Eclat.
+ Copyright (C) 2012, 2013 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/>. */
+
+static struct grecs_list *reslist;
+
+struct resource {
+ char *map;
+ char *resid;
+};
+
+OPTIONS_BEGIN("eclat describe-tags",
+ [<List tags and their values>],
+ [<[FILTER...]>],
+ [<gnu>],
+ [<nousage>],
+ [<noversion>])
+
+OPTION(resource-id,r,[<[MAP:]ID>],
+ [<resource for which to list the tags>])
+BEGIN
+ struct resource *res = grecs_malloc(sizeof(*res));
+ char *p = strchr(optarg, ':');
+ if (p) {
+ res->map = optarg;
+ *p++ = 0;
+ res->resid = p;
+ } else {
+ res->map = NULL;
+ res->resid = optarg;
+ }
+ grecs_list_append(reslist, res);
+END
+
+OPTION(instance,i,[<ID>],
+ [<instance ID>])
+BEGIN
+ struct resource *res = grecs_malloc(sizeof(*res));
+ res->map = "InstanceId";
+ res->resid = optarg;
+ grecs_list_append(reslist, res);
+END
+
+OPTION(volume,v,[<ID>],
+ [<volume ID>])
+BEGIN
+ struct resource *res = grecs_malloc(sizeof(*res));
+ res->map = "VolumeId";
+ res->resid = optarg;
+ grecs_list_append(reslist, res);
+END
+
+OPTION(ami,a,[<ID>],
+ [<AMI ID>])
+BEGIN
+ struct resource *res = grecs_malloc(sizeof(*res));
+ res->map = "ImageId";
+ res->resid = optarg;
+ grecs_list_append(reslist, res);
+END
+
+OPTION(snapshot,s,[<ID>],
+ [<snapshot ID>])
+BEGIN
+ struct resource *res = grecs_malloc(sizeof(*res));
+ res->map = "SnapshotId";
+ res->resid = optarg;
+ grecs_list_append(reslist, res);
+END
+
+OPTIONS_END
+
+static void
+parse_options(int argc, char *argv[], int *index)
+{
+ static char *resource_types[] = {
+ "customer-gateway",
+ "dhcp-options",
+ "image",
+ "instance",
+ "internet-gateway",
+ "network-acl",
+ "reserved-instances",
+ "route-table",
+ "security-group",
+ "snapshot",
+ "spot-instances-request",
+ "subnet",
+ "volume",
+ "vpc",
+ "vpn-connection",
+ "vpn-gateway",
+ NULL
+ };
+
+ static struct filter_descr filters[] = {
+ { "key", FILTER_STRING },
+ { "resource-id", FILTER_STRING },
+ { "resource-type", FILTER_ENUM, resource_types },
+ { "value", FILTER_STRING },
+ { NULL }
+ };
+
+ available_filters = filters;
+ proginfo.print_help_hook = list_filters;
+
+ reslist = grecs_list_create();
+ GETOPT(argc, argv, *index, exit(EX_USAGE))
+}
diff --git a/src/dscrtags.c b/src/dscrtags.c
index 5081e28..3530e62 100644
--- a/src/dscrtags.c
+++ b/src/dscrtags.c
@@ -15,55 +15,36 @@
along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
#include "eclat.h"
-
-static void
-parse_options(int argc, char *argv[], int *index)
-{
- static char *resource_types[] = {
- "customer-gateway",
- "dhcp-options",
- "image",
- "instance",
- "internet-gateway",
- "network-acl",
- "reserved-instances",
- "route-table",
- "security-group",
- "snapshot",
- "spot-instances-request",
- "subnet",
- "volume",
- "vpc",
- "vpn-connection",
- "vpn-gateway",
- NULL
- };
-
- static struct filter_descr filters[] = {
- { "key", FILTER_STRING },
- { "resource-id", FILTER_STRING },
- { "resource-type", FILTER_ENUM, resource_types },
- { "value", FILTER_STRING },
- { NULL }
- };
-
- available_filters = filters;
- generic_proginfo->print_help_hook = list_filters;
- return generic_parse_options("eclat describe-tags",
- "List tags and their values",
- argc, argv, index);
-}
+#include "dscrtags-cl.h"
int
eclat_describe_tags(eclat_command_env_t *env, int argc, char **argv)
{
int i;
+ char *bufptr = NULL;
+ size_t bufsize = 0;
+ struct grecs_list_entry *ep;
+ int n = 1;
parse_options(argc, argv, &i);
argv += i;
argc -= i;
translate_resource_ids(argc, argv);
- describe_query_create(env, argc, argv, NULL);
+ if (reslist->head) {
+ eclat_query_add_param(env->query,
+ "Filter.1.Name", "resource-id");
+ for (ep = reslist->head, i = 1; ep; ep = ep->next, i++) {
+ struct resource *res = ep->data;
+ if (res->map)
+ translate_ids(1, &res->resid, res->map);
+ grecs_asprintf(&bufptr, &bufsize,
+ "Filter.1.Value.%d", i);
+ eclat_query_add_param(env->query, bufptr, res->resid);
+ }
+ n++;
+ }
+ describe_query_update(env, argc, argv, NULL, n, NULL);
+
return 0;
}
diff --git a/src/eclat.h b/src/eclat.h
index 2fab8cf..ba5d57b 100644
--- a/src/eclat.h
+++ b/src/eclat.h
@@ -116,6 +116,9 @@ void set_command_format(const char *name, const char *format,
void describe_query_create(eclat_command_env_t *env, int argc, char **argv,
const char *uparm);
+void describe_query_update(eclat_command_env_t *env, int argc, char **argv,
+ const char *uparm, int n_in, int *n_out);
+
int eclat_send_query(CURL *curl, struct ec2_query *q);
int eclat_actcmp(const char *a, const char *b);
diff --git a/src/util.c b/src/util.c
index 8925c9f..22696d9 100644
--- a/src/util.c
+++ b/src/util.c
@@ -149,8 +149,8 @@ get_scr_cols()
void
-describe_query_create(eclat_command_env_t *env, int argc, char **argv,
- const char *uparm)
+describe_query_update(eclat_command_env_t *env, int argc, char **argv,
+ const char *uparm, int n_in, int *n_out)
{
int i, j, k;
struct ec2_query *q = env->query;
@@ -162,7 +162,7 @@ describe_query_create(eclat_command_env_t *env, int argc, char **argv,
ws.ws_delim = ",";
wsflags = WRDSF_DEFFLAGS | WRDSF_DELIM;
- for (i = 0, j = 1; i < argc; i++) {
+ for (i = 0, j = n_in; i < argc; i++) {
char *p = strchr(argv[i], '=');
if (!p) {
if (uparm) {
@@ -192,8 +192,17 @@ describe_query_create(eclat_command_env_t *env, int argc, char **argv,
if (wsflags & WRDSF_REUSE)
wordsplit_free(&ws);
free(bufptr);
+ if (n_out)
+ *n_out = j;
}
+void
+describe_query_create(eclat_command_env_t *env, int argc, char **argv,
+ const char *uparm)
+{
+ describe_query_update(env, argc, argv, uparm, 1, NULL);
+}
+
int
eclat_send_query(CURL *curl, struct ec2_query *q)
{

Return to:

Send suggestions and report system problems to the System administrator.