diff options
-rw-r--r-- | configure.ac | 6 | ||||
-rw-r--r-- | src/Makefile.am | 8 | ||||
-rw-r--r-- | src/accfile.c | 3 | ||||
-rw-r--r-- | src/cmdline.opt | 8 | ||||
-rw-r--r-- | src/descrtags.c | 81 | ||||
-rw-r--r-- | src/eclat.c | 6 | ||||
-rw-r--r-- | src/eclat.h | 6 | ||||
-rw-r--r-- | src/startinst.c | 19 |
8 files changed, 125 insertions, 12 deletions
diff --git a/configure.ac b/configure.ac index c6384ab..fd22d37 100644 --- a/configure.ac +++ b/configure.ac @@ -52,2 +52,8 @@ fi +# Check for libexpat +AC_CHECK_HEADER([expat.h], [], + [AC_MSG_ERROR([expat.h is not found])]) +AC_CHECK_LIB([expat], [XML_Parse],[], + [AC_MSG_ERROR([required library libexpat is not found])]) + # Grecs subsystem diff --git a/src/Makefile.am b/src/Makefile.am index a16aff8..b5f7912 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -22,2 +22,3 @@ eclat_SOURCES=\ config.c\ + descrtags.c\ diag.c\ @@ -37,3 +38,3 @@ AM_CPPFLAGS= \ BUILT_SOURCES=cmdline.h -EXTRA_DIST=cmdline.opt +EXTRA_DIST=cmdline.opt eclat.conf @@ -44 +45,6 @@ SUFFIXES=.opt .c .h +install-data-local: + @test -z "$(DESTDIR)$(sysconfdir)" || $(mkdir_p) "$(DESTDIR)$(sysconfdir)" + @if [ -r $(DESTDIR)$(sysconfdir)/eclat.conf ]; then :; \ + else ${INSTALL} -m 644 $(top_srcdir)/src/eclat.conf \ + $(DESTDIR)$(sysconfdir)/eclat.conf; fi diff --git a/src/accfile.c b/src/accfile.c index 3fe669d..0c4912e 100644 --- a/src/accfile.c +++ b/src/accfile.c @@ -74,3 +74,3 @@ access_file_lookup(const char *id, char **access_key_ptr, char **secret_key_ptr) acc = grecs_txtacc_create(); - while ((c = getc(fp)) != EOF && c != ':') { + while (c != EOF && c != ':') { if (c == '\n') { @@ -81,2 +81,3 @@ access_file_lookup(const char *id, char **access_key_ptr, char **secret_key_ptr) grecs_txtacc_grow_char(acc, c); + c = getc(fp); } diff --git a/src/cmdline.opt b/src/cmdline.opt index 25dc542..82e0e95 100644 --- a/src/cmdline.opt +++ b/src/cmdline.opt @@ -61,2 +61,4 @@ BEGIN dry_run_mode = 1; + parse_debug_level("main.1"); + parse_debug_level("curl.1"); END @@ -83,2 +85,8 @@ END +OPTION(describe-tags,,, + [<describe tags>]) +BEGIN + eclat_command = eclat_command_describe_tags; +END + GROUP(Modifiers) diff --git a/src/descrtags.c b/src/descrtags.c new file mode 100644 index 0000000..2fc44ef --- /dev/null +++ b/src/descrtags.c @@ -0,0 +1,81 @@ +/* This file is part of Eclat. + Copyright (C) 2012 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 "eclat.h" + +int +eclat_describe_tags(CURL *curl, int argc, char **argv) +{ + int i, j, k; + struct ec2_query *q; + char *url; + char *bufptr = NULL; + size_t bufsize = 0; + size_t bs; + CURLcode res; + struct wordsplit ws; + int wsflags; + + q = eclat_query_create(use_ssl ? EC2_QF_HTTPS : 0, endpoint, "/"); + eclat_query_add_param(q, "Action", "DescribeTags"); + + ws.ws_delim = ","; + wsflags = WRDSF_DEFFLAGS | WRDSF_DELIM; + for (i = 0, j = 1; i < argc; i++) { + char *p = strchr(argv[i], '='); + if (!p) + die(EX_USAGE, "maformed filter: %s", argv[i]); + *p++ = 0; + grecs_asprintf(&bufptr, &bufsize, "Filter.%d.Name", j); + eclat_query_add_param(q, bufptr, argv[i]); + + if (wordsplit(p, &ws, wsflags)) + die(EX_SOFTWARE, "wordsplit failed at \"%s\": %s", + p, wordsplit_strerror(&ws)); + wsflags |= WRDSF_REUSE; + + for (k = 0; k < ws.ws_wordc; k++) { + grecs_asprintf(&bufptr, &bufsize, "Filter.%d.Value.%d", + j, k+1); + eclat_query_add_param(q, bufptr, ws.ws_wordv[k]); + } + } + if (wsflags & WRDSF_REUSE) + wordsplit_free(&ws); + free(bufptr); + + eclat_query_add_param(q, "AWSAccessKeyId", access_key); + + eclat_query_signature(q, secret_key); + url = eclat_query_to_url(q, NULL); + + debug(ECLAT_DEBCAT_MAIN, 1, ("using URL: %s", url)); + curl_easy_setopt(curl, CURLOPT_URL, url); + + free(url); + eclat_query_free(q); + + if (dry_run_mode) + debug(ECLAT_DEBCAT_MAIN, 1, ("not sending request")); + else { + res = curl_easy_perform(curl); + + if (res != CURLE_OK) + err("CURL: %s", curl_easy_strerror(res)); + } + + return 0; +} diff --git a/src/eclat.c b/src/eclat.c index f0440e3..c5994fe 100644 --- a/src/eclat.c +++ b/src/eclat.c @@ -179,3 +179,4 @@ eclat_command_handler_t handler_tab[] = { eclat_start_instance, - eclat_stop_instance + eclat_stop_instance, + eclat_describe_tags }; @@ -236,3 +237,4 @@ main(int argc, char **argv) } - + debug(ECLAT_DEBCAT_MAIN, 1, ("using access key %s", access_key)); + if (eclat_command == eclat_command_unspecified) diff --git a/src/eclat.h b/src/eclat.h index 31914a0..b0d46ac 100644 --- a/src/eclat.h +++ b/src/eclat.h @@ -25,2 +25,3 @@ #include <curl/curl.h> +#include <expat.h> #include "grecs.h" @@ -41,2 +42,3 @@ extern char *endpoint; extern int use_ssl; +extern int dry_run_mode; extern char *region_name; @@ -72,3 +74,4 @@ enum eclat_command { eclat_command_start_instances, - eclat_command_stop_instances + eclat_command_stop_instances, + eclat_command_describe_tags }; @@ -81,2 +84,3 @@ int eclat_start_instance(CURL *curl, int argc, char **argv); int eclat_stop_instance(CURL *curl, int argc, char **argv); +int eclat_describe_tags(CURL *curl, int argc, char **argv); diff --git a/src/startinst.c b/src/startinst.c index d2b9cad..bf1c364 100644 --- a/src/startinst.c +++ b/src/startinst.c @@ -46,3 +46,3 @@ start_stop_instance(CURL *curl, const char *action, int argc, char **argv) - debug(ECLAT_DEBCAT_MAIN, 2, ("using URL: %s", url)); + debug(ECLAT_DEBCAT_MAIN, 1, ("using URL: %s", url)); curl_easy_setopt(curl, CURLOPT_URL, url); @@ -52,9 +52,12 @@ start_stop_instance(CURL *curl, const char *action, int argc, char **argv) - res = curl_easy_perform(curl); - - if (res != CURLE_OK) - err("CURL: %s", curl_easy_strerror(res)); - - return 0; + if (dry_run_mode) + debug(ECLAT_DEBCAT_MAIN, 1, ("not sending request")); + else { + res = curl_easy_perform(curl); + + if (res != CURLE_OK) + err("CURL: %s", curl_easy_strerror(res)); + } + return 0; } @@ -64,2 +67,3 @@ eclat_start_instance(CURL *curl, int argc, char **argv) { + debug(ECLAT_DEBCAT_MAIN, 1, ("starting instances")); start_stop_instance(curl, "StartInstances", argc, argv); @@ -70,2 +74,3 @@ eclat_stop_instance(CURL *curl, int argc, char **argv) { + debug(ECLAT_DEBCAT_MAIN, 1, ("stopping instances")); start_stop_instance(curl, "StopInstances", argc, argv); |