aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-09-26 22:27:04 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2012-09-26 22:30:07 +0300
commit0c8a7ab953a86426a13aa0eccaf2b2c46f8271c0 (patch)
tree6f507697a5914bfb0ba9425aef3701ac00d94ec7
parent22084e1264031d59b8954b684c1d9f40733c8786 (diff)
downloadeclat-0c8a7ab953a86426a13aa0eccaf2b2c46f8271c0.tar.gz
eclat-0c8a7ab953a86426a13aa0eccaf2b2c46f8271c0.tar.bz2
Improve documentation output.
* src/dscrinststat-cl.opt: Document available filters. * src/dscrtags-cl.opt: Likewise. * src/eclat.c (list_filters): New function. * src/eclat.h (FILTER_STRING,FILTER_DATE) (FILTER_ENUM): : New defines. (filter_descr): New struct. * src/util.c (get_scr_cols): New function. (describe_query_create): Minor fix.
-rw-r--r--src/dscrinststat-cl.opt71
-rw-r--r--src/dscrtags-cl.opt30
-rw-r--r--src/eclat.c49
-rw-r--r--src/eclat.h16
-rw-r--r--src/util.c21
5 files changed, 185 insertions, 2 deletions
diff --git a/src/dscrinststat-cl.opt b/src/dscrinststat-cl.opt
index 13f5046..56fee03 100644
--- a/src/dscrinststat-cl.opt
+++ b/src/dscrinststat-cl.opt
@@ -32,5 +32,76 @@ OPTIONS_END
static void
parse_options(int argc, char *argv[], int *index)
{
+ static char *event_codes[] = {
+ "instance-reboot",
+ "system-reboot",
+ "system-maintenance",
+ "instance-retirement",
+ NULL
+ };
+ static char *instance_state_name[] = {
+ "pending",
+ "running",
+ "shutting-down",
+ "terminated",
+ "stopping",
+ "stopped",
+ NULL
+ };
+ static char *instance_state_code[] = {
+ "0 (pending)",
+ "16 (running)",
+ "32 (shutting-down)",
+ "48 (terminated)",
+ "64 (stopping)",
+ "80 (stopped)"
+ };
+ static char *system_status[] = {
+ "ok",
+ "impaired",
+ "initializing",
+ "insufficient-data",
+ "not-applicable",
+ NULL
+ };
+ static char *system_reachability[] = {
+ "passed",
+ "failed",
+ "initializing",
+ "insufficient-data",
+ NULL
+ };
+ static char *instance_status[] = {
+ "ok",
+ "impaired",
+ "initializing",
+ "insufficient-data",
+ "not-applicable"
+ };
+ static char *instance_reachability[] = {
+ "passed",
+ "failed",
+ "initializing",
+ "insufficient-data",
+ NULL
+ };
+ static struct filter_descr filters[] = {
+ { "availability-zone", FILTER_STRING },
+ { "event.code", FILTER_ENUM, event_codes },
+ { "event.description", FILTER_STRING },
+ { "event.not-after", FILTER_DATE },
+ { "instance-state-name", FILTER_ENUM, instance_state_name },
+ { "instance-state-code", FILTER_ENUM, instance_state_code },
+ { "system-status.status",FILTER_ENUM, system_status },
+ { "system-status.reachability",
+ FILTER_ENUM, system_reachability },
+ { "instance-status.status",
+ FILTER_ENUM, instance_status },
+ { "instance-status.reachability",
+ FILTER_ENUM, instance_reachability },
+ { NULL }
+ };
+ available_filters = filters;
+ proginfo.print_help_hook = list_filters;
GETOPT(argc, argv, *index, exit(EX_USAGE))
}
diff --git a/src/dscrtags-cl.opt b/src/dscrtags-cl.opt
index 230031a..adada32 100644
--- a/src/dscrtags-cl.opt
+++ b/src/dscrtags-cl.opt
@@ -26,5 +26,35 @@ 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;
GETOPT(argc, argv, *index, exit(EX_USAGE))
}
diff --git a/src/eclat.c b/src/eclat.c
index 8fafc72..a93c7ae 100644
--- a/src/eclat.c
+++ b/src/eclat.c
@@ -367,7 +367,56 @@ compile_default_format(struct command *cmd)
return env;
}
+
+struct filter_descr *available_filters;
+
+static char *aws_typestr[] = {
+ "String",
+ "dateType"
+};
+
+void
+list_filters(FILE *fp)
+{
+ struct filter_descr *flt;
+ size_t ncols = get_scr_cols();
+ size_t col, start;
+ fprintf(fp, "Available filters are:\n");
+ for (flt = available_filters; flt->name; flt++) {
+ col = fprintf(fp, " %-25s", flt->name);
+ if (col > 26) {
+ col = start = 26;
+ fprintf(fp, "\n%*.*s", start, start, "");
+ }
+ if (flt->type != FILTER_ENUM)
+ fprintf(fp, "%s", aws_typestr[flt->type]);
+ else {
+ int i;
+ char *delim;
+ size_t len;
+
+ col += fprintf(fp, "One of:");
+ start = col + 1;
+ delim = " ";
+ for (i = 0; flt->avail[i]; i++) {
+ len = strlen(delim) + strlen(flt->avail[i]);
+ if (col + len >= ncols) {
+ fprintf(fp, ",\n%*.*s",
+ start, start, "");
+ col = start;
+ delim = "";
+ }
+ col += fprintf(fp, "%s%s", delim,
+ flt->avail[i]);
+ delim = ", ";
+ }
+ }
+ fputc('\n', fp);
+ }
+ fputc('\n', fp);
+}
+
int
diff --git a/src/eclat.h b/src/eclat.h
index 641d0ad..9cc1c74 100644
--- a/src/eclat.h
+++ b/src/eclat.h
@@ -69,3 +69,19 @@ struct ec2_query *describe_query_create(CURL *curl, const char *verb,
int eclat_send_query(CURL *curl, struct ec2_query *q);
#define XML_DUMP_FILE_NAME "eclat.dump.xml"
+
+#define FILTER_STRING 0
+#define FILTER_DATE 1
+#define FILTER_ENUM 2
+
+struct filter_descr {
+ char *name;
+ int type;
+ char **avail;
+};
+
+struct filter_descr *available_filters;
+
+void list_filters(FILE *fp);
+int get_scr_cols(void);
+
diff --git a/src/util.c b/src/util.c
index 146567c..30b3979 100644
--- a/src/util.c
+++ b/src/util.c
@@ -15,6 +15,23 @@
along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
#include "eclat.h"
+#include <termios.h>
+#include <sys/ioctl.h>
+
+int
+get_scr_cols()
+{
+ struct winsize ws;
+
+ ws.ws_col = ws.ws_row = 0;
+ if ((ioctl(1, TIOCGWINSZ, (char *) &ws) < 0) || ws.ws_col == 0) {
+ const char *p = getenv ("COLUMNS");
+ if (p)
+ ws.ws_col = strtol(p, NULL, 10);
+ }
+ return ws.ws_col ? ws.ws_col : 80;
+}
+
struct ec2_query *
describe_query_create(CURL *curl, const char *verb, int argc, char **argv)
@@ -33,14 +50,14 @@ describe_query_create(CURL *curl, const char *verb, int argc, char **argv)
ws.ws_delim = ",";
wsflags = WRDSF_DEFFLAGS | WRDSF_DELIM;
- for (i = 0, j = 1; i < argc; i++) {
+ for (i = 0, j = 1; i < argc; i++, j++) {
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));

Return to:

Send suggestions and report system problems to the System administrator.