aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-09-28 11:23:09 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2012-09-28 11:32:04 +0300
commitac1d6cbbcf5323d5db59886b98a24c45bafa64b8 (patch)
treef2a77092e072faa680b47d9d6d960e7214e46876
parentd902742081bc31a6eda274268da0178107e4abb4 (diff)
downloadeclat-ac1d6cbbcf5323d5db59886b98a24c45bafa64b8.tar.gz
eclat-ac1d6cbbcf5323d5db59886b98a24c45bafa64b8.tar.bz2
Improve testsuite. Reorganize directory structure.
* Makefile.am (SUBDIRS): Add etc (distuninstallcheck_listfiles): Ignore *.forlan files. * configure.ac: New options --split-format and --format-dir * etc/Makefile.am: New file. * etc/default.fln: New file. * etc/describe-instance-status.fln: New file. * etc/describe-instances.fln: New file. * etc/describe-tags.fln: New file. * etc/eclat.cfin: New file. * etc/flncat.c: New file. * etc/start-instances.fln: New file. * etc/stop-instances.fln: New file. * src/Makefile.am: Remove eclat.conf. It is built in /etc now. * src/eclat.conf: Remove. * src/cmdline.opt: Update. * src/config.c: New configuration statement "format-file". * src/eclat.c (format_file_option): New global. (main): Read format from format-file, if supplied. Expand keywords in its argument. * src/eclat.h (format_file_option): New extern. * tests/.gitignore: Update. * tests/Makefile.am: Add new files. * tests/describe-instance-status.at: New test case. * tests/describe-instances.at: New test case. * tests/describe-tags.at: New test case. * tests/dscrinststat.at: New test case. * tests/start-instances.at: New test case. * tests/stop-instances.at: New test case. * tests/testsuite.at (ECLAT_TEST_FORMAT): New macro. Include new test cases. * tests/trws.c: New file.
-rw-r--r--Makefile.am4
-rw-r--r--configure.ac26
-rw-r--r--etc/.gitignore3
-rw-r--r--etc/Makefile.am60
-rw-r--r--etc/default.fln22
-rw-r--r--etc/describe-instance-status.fln36
-rw-r--r--etc/describe-instances.fln69
-rw-r--r--etc/describe-tags.fln24
-rw-r--r--etc/eclat.cfin32
-rw-r--r--etc/flncat.c94
-rw-r--r--etc/start-instances.fln23
-rw-r--r--etc/stop-instances.fln23
-rw-r--r--src/Makefile.am8
-rw-r--r--src/cmdline.opt2
-rw-r--r--src/config.c4
-rw-r--r--src/eclat.c72
-rw-r--r--src/eclat.conf165
-rw-r--r--src/eclat.h1
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/Makefile.am6
-rw-r--r--tests/describe-instance-status.at154
-rw-r--r--tests/describe-instances.at274
-rw-r--r--tests/describe-tags.at68
-rw-r--r--tests/dscrinststat.at128
-rw-r--r--tests/start-instances.at38
-rw-r--r--tests/stop-instances.at39
-rw-r--r--tests/testsuite.at17
-rw-r--r--tests/trws.c46
28 files changed, 1245 insertions, 194 deletions
diff --git a/Makefile.am b/Makefile.am
index 171250b..d78d1f6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -18,3 +18,3 @@ ACLOCAL_AMFLAGS = -I grecs/am
-SUBDIRS = grecs lib src tests
+SUBDIRS = grecs lib src etc tests
@@ -27,2 +27,2 @@ ChangeLog:
-distuninstallcheck_listfiles = find . -type f -not -name 'eclat.conf' -print
+distuninstallcheck_listfiles = find . -type f -not -name 'eclat.conf' -not -name '*.forlan' -print
diff --git a/configure.ac b/configure.ac
index 8f8ccfc..7c744ff 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,2 +65,25 @@ GRECS_SETUP([grecs],[tests getopt git2chg])
+#
+AC_SUBST(FORMATDIR)
+AC_ARG_ENABLE([split-format],
+ [AC_HELP_STRING([--enable-split-format],
+ [build split format files])],
+ [split_fmt=$enableval],
+ [split_fmt=no])
+
+if test $split_fmt = yes; then
+ FORMATDIR="\$(sysconfdir)/\$(PACKAGE)"
+else
+ FORMATDIR="\$(sysconfdir)"
+fi
+AM_CONDITIONAL([SPLIT_FORMATS],[test $split_fmt = yes])
+
+AC_ARG_WITH([format-dir],
+ [AC_HELP_STRING([--format-dir=DIR],
+ [install format files to that directory])],
+ [case $withval in
+ /*) FORMATDIR=$withval;;
+ *) FORMATDIR='$(prefix)/'$withval
+ esac])
+
# Initialize the test suite.
@@ -72,3 +95,4 @@ AC_CONFIG_FILES([Makefile
lib/Makefile
- src/Makefile])
+ src/Makefile
+ etc/Makefile])
diff --git a/etc/.gitignore b/etc/.gitignore
new file mode 100644
index 0000000..b22bf5d
--- /dev/null
+++ b/etc/.gitignore
@@ -0,0 +1,3 @@
+*.forlan
+eclat.conf
+flncat
diff --git a/etc/Makefile.am b/etc/Makefile.am
new file mode 100644
index 0000000..5eec565
--- /dev/null
+++ b/etc/Makefile.am
@@ -0,0 +1,60 @@
+# 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/>.
+
+noinst_PROGRAMS = flncat
+
+FLNFILES=\
+ describe-instance-status.fln\
+ describe-instances.fln\
+ describe-tags.fln\
+ start-instances.fln\
+ stop-instances.fln
+
+EXTRA_DIST=$(FLNFILES) default.fln eclat.cfin
+
+noinst_SCRIPTS=eclat.conf
+CLEANFILES=eclat.conf
+SUFFIXES=.cfin .conf
+
+if SPLIT_FORMATS
+SUFFIXES += .forlan .fln
+.fln.forlan:
+ $(AM_V_GEN)$(abs_builddir)/flncat $< default.fln > $@
+formatdir = @FORMATDIR@
+noinst_SCRIPTS += $(FLNFILES:.fln=.forlan)
+CLEANFILES += $(FLNFILES:.fln=.forlan)
+FORMATNAME = $${command}
+else
+formatdir = @FORMATDIR@
+noinst_SCRIPTS += eclat.forlan
+CLEANFILES += eclat.forlan
+eclat.forlan: $(FLNFILES) default.fln
+ $(AM_V_GEN)(cd $(srcdir); $(abs_builddir)/flncat $(FLNFILES) default.fln) > eclat.forlan
+FORMATNAME = eclat
+endif
+
+.cfin.conf:
+ $(AM_V_GEN)sed 's^FORMATDIR^$(formatdir)^;s^FORMATNAME^$(FORMATNAME)^' $< > $@
+
+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; \
+ for file in $(noinst_SCRIPTS); do \
+ ${INSTALL} -m 644 $$file $(DESTDIR)$(formatdir)/$$file; \
+ done; \
+ fi
diff --git a/etc/default.fln b/etc/default.fln
new file mode 100644
index 0000000..2e2f690
--- /dev/null
+++ b/etc/default.fln
@@ -0,0 +1,22 @@
+/* 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/>. */
+
+if (.Response.Errors)
+ error("Error: ",.Response.Errors.Error.Message,"\n");
+else {
+ error("Unrecognized response:\n");
+ dump(.);
+}
diff --git a/etc/describe-instance-status.fln b/etc/describe-instance-status.fln
new file mode 100644
index 0000000..85b88b3
--- /dev/null
+++ b/etc/describe-instance-status.fln
@@ -0,0 +1,36 @@
+/* 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/>. */
+
+if (.DescribeInstanceStatusResponse.instanceStatusSet) {
+ for (var in .DescribeInstanceStatusResponse.instanceStatusSet.item) {
+ print(var.instanceId,"\t",
+ var.availabilityZone,"\t",
+ var.instanceState.name);
+ if (var.instanceState.name[running]) {
+ print("\t",var.systemStatus.status);
+ for (detail in var.systemStatus.details.item) {
+ print("\tSys.",detail.name,"=",detail.status);
+ }
+ for (detail in var.instanceStatus.details.item) {
+ print("\tInst.",detail.name,"=",detail.status);
+ }
+ }
+ print("\n");
+ for (event in var.eventsSet.item) {
+ error(var.instanceId,"\t","Event: ", event.description,"\n");
+ }
+ }
+}
diff --git a/etc/describe-instances.fln b/etc/describe-instances.fln
new file mode 100644
index 0000000..538aa5c
--- /dev/null
+++ b/etc/describe-instances.fln
@@ -0,0 +1,69 @@
+/* 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/>. */
+
+if (.DescribeInstancesResponse.reservationSet) {
+ for (var in .DescribeInstancesResponse.reservationSet.item) {
+ print("Reservation ID: ", var.reservationId, "\n");
+ print("Owner ID: ", var.ownerId, "\n");
+ if (var.groupSet) {
+ print("Groups:\n");
+ for (grp in var.groupSet.item)
+ print("\t", grp.groupId,"\t", grp.groupName, "\n");
+ }
+ if (var.instancesSet) {
+ // print("Instances:\n");
+ for (inst in var.instancesSet.item) {
+ print("\nInstance: ", inst.instanceId, "\n");
+ print("\tImage ID: ", inst.imageId, "\n");
+ print("\tState: ", inst.instanceState.name, "\n");
+ print("\tKernel ID: ", inst.kernelId, "\n");
+ print("\tArchitecture: ", inst.architecture, "\n");
+ print("\tPrivate DNS: ", inst.privateDnsName, "\n");
+ print("\tPublic DNS: ", inst.dnsName, "\n");
+ print("\tKey: ", inst.keyName, "\n");
+ print("\tType: ", inst.instanceType, "\n");
+ print("\tLaunch Time: ", inst.launchTime, "\n");
+ print("\tAvailability Zone: ", inst.placement.availabilityZone, "\n");
+ print("\tGroup Name: ", inst.placement.groupName, "\n");
+ print("\tTenancy: ", inst.placement.tenancy, "\n");
+ print("\tPrivate IP: ", inst.privateIpAddress, "\n");
+ print("\tPublic IP: ", inst.ipAddress, "\n");
+ if (inst.groupSet.item) {
+ print("\tGroups:\n");
+ for (grp in inst.groupSet.item)
+ print("\t\t", inst.groupSet.item.groupId, " -- ", inst.groupSet.item.groupName, "\n");
+ }
+ print("\tRoot Device Type: ", inst.rootDeviceType, "\n");
+ print("\tRoot Device Name: ", inst.rootDeviceName, "\n");
+ print("\tDevice mapping:\n");
+ for (dev in inst.blockDeviceMapping.item) {
+ print("\t\t", dev.deviceName, " ", dev.ebs.volumeId, " ",
+ dev.ebs.status, " ", dev.ebs.attachTime, " ",
+ dev.ebs.deleteOnTermination, "\n");
+ }
+ print("\tVirtualization: ", inst.virtualizationType, "\n");
+ print("\tTag Set:\n");
+ for (tag in inst.tagSet.item) {
+ print("\t\t", tag.key, "=", tag.value, "\n");
+ }
+ print("\tHypervisor: ", inst.hypervisor, "\n");
+ // FIXME: networkInterfaceSet
+ print("\tEBS Optimized: ", inst.ebsOptimized, "\n");
+ print("End of instance\n\n");
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/etc/describe-tags.fln b/etc/describe-tags.fln
new file mode 100644
index 0000000..30d8798
--- /dev/null
+++ b/etc/describe-tags.fln
@@ -0,0 +1,24 @@
+/* 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/>. */
+
+if (.DescribeTagsResponse) {
+ for (var in .DescribeTagsResponse.tagSet.item) {
+ print(var.resourceId,"\t",
+ var.resourceType,"\t",
+ var.key,"\t",
+ var.value,"\n");
+ }
+} \ No newline at end of file
diff --git a/etc/eclat.cfin b/etc/eclat.cfin
new file mode 100644
index 0000000..006f6d9
--- /dev/null
+++ b/etc/eclat.cfin
@@ -0,0 +1,32 @@
+/* Default configuration file for Eclat.
+ *
+ * See eclat.conf(5) or run "info eclat configuration" for a detailed
+ * description.
+ */
+
+# Use this endpoint by default.
+default-endpoint "ec2.amazonaws.com";
+
+# Declare what endpoints to use for each availability region.
+# The syntax is:
+# region REGNAME ENDPOINT;
+
+# US East (Northern Virginia) Region
+region us-east-1 ec2.us-east-1.amazonaws.com;
+# US West (Oregon) Region
+region us-west-2 ec2.us-west-2.amazonaws.com;
+# US West (Northern California) Region
+region us-west-1 ec2.us-west-1.amazonaws.com;
+# EU (Ireland) Region
+region eu-west-1 ec2.eu-west-1.amazonaws.com;
+# Asia Pacific (Singapore) Region
+region ap-southeast-1 ec2.ap-southeast-1.amazonaws.com;
+# Asia Pacific (Tokyo) Region
+region ap-northeast-1 ec2.ap-northeast-1.amazonaws.com;
+# South America (Sao Paulo) Region
+region sa-east-1 ec2.sa-east-1.amazonaws.com;
+
+format-file "FORMATDIR/FORMATNAME.forlan";
+
+
+
diff --git a/etc/flncat.c b/etc/flncat.c
new file mode 100644
index 0000000..6f67e0e
--- /dev/null
+++ b/etc/flncat.c
@@ -0,0 +1,94 @@
+/* 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 <stdio.h>
+#include <ctype.h>
+#include <assert.h>
+
+int
+comment(FILE *fp, int c)
+{
+ if (c != '/') {
+ ungetc(c, fp);
+ return 0;
+ }
+
+ if ((c = getc(fp)) == '/') {
+ while ((c = getc(fp)) != EOF && c != '\n')
+ ;
+ return 1;
+ }
+
+ if (c == '*') {
+ do {
+ while ((c = getc(fp)) != '*') {
+ if (c == EOF)
+ return 0;
+ }
+ } while ((c = getc(fp)) != '/');
+ return 1;
+ }
+ ungetc(c, fp);
+ ungetc('/', fp);
+ return 0;
+}
+
+int
+main(int argc, char **argv)
+{
+ int i;
+ FILE *fp;
+ int c;
+ char buf[128];
+ size_t lev = 0;
+
+ for (i = 1; i < argc; i++) {
+ fp = fopen(*++argv, "r");
+ if (!fp) {
+ perror(*argv);
+ return 1;
+ }
+
+ if (i > 1) {
+ /* Skip whitespace and comment lines */
+ do {
+ while ((c = fgetc(fp)) != EOF && isspace(c))
+ ;
+ } while (c != EOF && comment(fp, c));
+ printf(" else ");
+ }
+
+ while ((c = fgetc(fp)) != EOF) {
+ putchar(c);
+ if (c == '}') {
+ lev = 0;
+ while ((c = fgetc(fp)) != EOF &&
+ isspace(c)) {
+ assert(lev < sizeof(buf));
+ buf[lev++] = c;
+ }
+ if (c == EOF)
+ break;
+ else {
+ buf[lev++] = c;
+ fwrite(buf, lev, 1, stdout);
+ }
+ }
+ }
+ fclose(fp);
+ }
+ return 0;
+}
diff --git a/etc/start-instances.fln b/etc/start-instances.fln
new file mode 100644
index 0000000..137a202
--- /dev/null
+++ b/etc/start-instances.fln
@@ -0,0 +1,23 @@
+/* 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/>. */
+
+if (.StartInstancesResponse) {
+ for (var in .StartInstancesResponse.instancesSet.item) {
+ print(var.instanceId,": ",
+ var.previousState.name," => ",
+ var.currentState.name,"\n");
+ }
+} \ No newline at end of file
diff --git a/etc/stop-instances.fln b/etc/stop-instances.fln
new file mode 100644
index 0000000..bb45347
--- /dev/null
+++ b/etc/stop-instances.fln
@@ -0,0 +1,23 @@
+/* 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/>. */
+
+if (.StopInstancesResponse) {
+ for (var in .StopInstancesResponse.instancesSet.item) {
+ print(var.instanceId,": ",
+ var.previousState.name," => ",
+ var.currentState.name,"\n");
+ }
+} \ No newline at end of file
diff --git a/src/Makefile.am b/src/Makefile.am
index 5b114cc..7f3e1f0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -58,4 +58,3 @@ EXTRA_DIST=\
cmdline.opt\
- $(OPTFILES)\
- eclat.conf
+ $(OPTFILES)
@@ -66,6 +65 @@ 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/cmdline.opt b/src/cmdline.opt
index d07309f..3f0549f 100644
--- a/src/cmdline.opt
+++ b/src/cmdline.opt
@@ -114,3 +114,3 @@ OPTION(format,F,FILE,
BEGIN
- format_file = optarg;
+ format_file_option = optarg;
END
diff --git a/src/config.c b/src/config.c
index 82033d3..aa60323 100644
--- a/src/config.c
+++ b/src/config.c
@@ -141,3 +141,5 @@ static struct grecs_keyword eclat_kw[] = {
"Set default format for the <command>",
- grecs_type_string, GRECS_MULT, NULL, 0, cb_format },
+ grecs_type_string, GRECS_MULT, NULL, 0, cb_format },
+ { "format-file", "file", "Read format from <file>",
+ grecs_type_string, GRECS_DFLT, &format_file },
{ NULL }
diff --git a/src/eclat.c b/src/eclat.c
index a8c5728..31f2144 100644
--- a/src/eclat.c
+++ b/src/eclat.c
@@ -28,4 +28,5 @@ char *secret_key;
char *region_name;
-char *format_file;
+char *format_file_option;
int sort_option;
+char *format_file;
@@ -335,13 +336,2 @@ compile_format_file(const char *fmtfile)
-forlan_eval_env_t
-compile_default_format(struct command *cmd)
-{
- forlan_eval_env_t env;
-
- env = forlan_parse_buffer(cmd->fmt, strlen(cmd->fmt), &cmd->locus.beg);
- if (!env)
- exit(EX_UNAVAILABLE);
-
- return env;
-}
@@ -396,2 +386,53 @@ list_filters(FILE *fp)
+static forlan_eval_env_t
+read_format(struct command *cmd)
+{
+ forlan_eval_env_t env = NULL;
+
+ if (format_file_option)
+ env = compile_format_file(format_file_option);
+ else if (cmd && cmd->fmt)
+ env = forlan_parse_buffer(cmd->fmt, strlen(cmd->fmt),
+ &cmd->locus.beg);
+ else if (format_file) {
+ struct wordsplit ws;
+ const char *kve[5];
+ struct grecs_locus_point pt;
+ FILE *fp;
+
+ kve[0] = "command";
+ kve[1] = cmd->ident;
+ kve[2] = "action";
+ kve[3] = cmd->tag;
+ kve[4] = NULL;
+
+ ws.ws_env = kve;
+ if (wordsplit(format_file, &ws,
+ WRDSF_NOSPLIT | WRDSF_NOCMD |
+ WRDSF_ENV | WRDSF_ENV_KV))
+ die(EX_SOFTWARE,
+ "error expanding format-file: %s",
+ wordsplit_strerror(&ws));
+
+ fp = fopen(ws.ws_wordv[0], "r");
+ if (!fp)
+ die(EX_UNAVAILABLE,
+ "cannot open format file %s: %s",
+ ws.ws_wordv[0], strerror(errno));
+
+ pt.file = ws.ws_wordv[0];
+ pt.line = 1;
+ pt.col = 0;
+
+ env = forlan_parse_file(fp, &pt);
+ fclose(fp);
+ wordsplit_free(&ws);
+ } else
+ return NULL;
+
+ if (!env)
+ exit(EX_UNAVAILABLE);
+ return env;
+}
+
@@ -450,7 +491,4 @@ main(int argc, char **argv)
- if (format_file)
- env = compile_format_file(format_file);
- else if (command && command->fmt)
- env = compile_default_format(command);
-
+ env = read_format(command);
+
if (lint_mode)
diff --git a/src/eclat.conf b/src/eclat.conf
deleted file mode 100644
index ec371e3..0000000
--- a/src/eclat.conf
+++ /dev/null
@@ -1,165 +0,0 @@
-/* Default configuration file for Eclat.
- *
- * See eclat.conf(5) or run "info eclat configuration" for a detailed
- * description.
- */
-
-# Use this endpoint by default.
-default-endpoint "ec2.amazonaws.com";
-
-# Declare what endpoints to use for each availability region.
-# The syntax is:
-# region REGNAME ENDPOINT;
-
-# US East (Northern Virginia) Region
-region us-east-1 ec2.us-east-1.amazonaws.com;
-# US West (Oregon) Region
-region us-west-2 ec2.us-west-2.amazonaws.com;
-# US West (Northern California) Region
-region us-west-1 ec2.us-west-1.amazonaws.com;
-# EU (Ireland) Region
-region eu-west-1 ec2.eu-west-1.amazonaws.com;
-# Asia Pacific (Singapore) Region
-region ap-southeast-1 ec2.ap-southeast-1.amazonaws.com;
-# Asia Pacific (Tokyo) Region
-region ap-northeast-1 ec2.ap-northeast-1.amazonaws.com;
-# South America (Sao Paulo) Region
-region sa-east-1 ec2.sa-east-1.amazonaws.com;
-
-format "DescribeTags" <<\EOT
-if (.DescribeTagsResponse) {
- for (var in .DescribeTagsResponse.tagSet.item) {
- print(var.resourceId,"\t",
- var.resourceType,"\t",
- var.key,"\t",
- var.value,"\n");
- }
-} else if (.Response.Errors)
- error("Error: ",.Response.Errors.Error.Message,"\n");
-else {
- error("Unrecognized response:\n");
- dump(.);
-}
-EOT;
-
-format "DescribeInstanceStatus" <<\EOT
-if (.DescribeInstanceStatusResponse.instanceStatusSet) {
- for (var in .DescribeInstanceStatusResponse.instanceStatusSet.item) {
- print(var.instanceId,"\t",
- var.availabilityZone,"\t",
- var.instanceState.name);
- if (var.instanceState.name[running]) {
- print("\t",var.systemStatus.status);
- for (detail in var.systemStatus.details.item) {
- print("\tSys.",detail.name,"=",detail.status);
- }
- for (detail in var.instanceStatus.details.item) {
- print("\tInst.",detail.name,"=",detail.status);
- }
- }
- print("\n");
- for (event in var.eventsSet.item) {
- error(var.instanceId,"\t","Event: ", event.description,"\n");
- }
- }
-} else if (.Response.Errors)
- error("Error: ",.Response.Errors.Error.Message,"\n");
-else {
- error("Unrecognized response:\n");
- dump(.);
-}
-EOT;
-
-format "StartInstances" <<\EOT
-if (.StartInstancesResponse) {
- for (var in .StartInstancesResponse.instancesSet.item) {
- print(var.instanceId,": ",
- var.previousState.name," => ",
- var.currentState.name,"\n");
- }
-} else if (.Response.Errors)
- error("Error: ",.Response.Errors.Error.Message,"\n");
-else {
- error("Unrecognized response:\n");
- dump(.);
-}
-EOT;
-
-format "StopInstances" <<\EOT
-if (.StopInstancesResponse) {
- for (var in .StopInstancesResponse.instancesSet.item) {
- print(var.instanceId,": ",
- var.previousState.name," => ",
- var.currentState.name,"\n");
- }
-} else if (.Response.Errors)
- error("Error: ",.Response.Errors.Error.Message,"\n");
-else {
- error("Unrecognized response:\n");
- dump(.);
-}
-EOT;
-
-format "DescribeInstances" <<\EOT
-if (.DescribeInstancesResponse.reservationSet) {
- for (var in .DescribeInstancesResponse.reservationSet.item) {
- print("Reservation ID: ", var.reservationId, "\n");
- print("Owner ID: ", var.ownerId, "\n");
- if (var.groupSet) {
- print("Groups:\n");
- for (grp in var.groupSet.item)
- print("\t", grp.groupId,"\t", grp.groupName, "\n");
- }
- if (var.instancesSet) {
- // print("Instances:\n");
- for (inst in var.instancesSet.item) {
- print("\nInstance: ", inst.instanceId, "\n");
- print("\tImage ID: ", inst.imageId, "\n");
- print("\tState: ", inst.instanceState.name, "\n");
- print("\tKernel ID: ", inst.kernelId, "\n");
- print("\tArchitecture: ", inst.architecture, "\n");
- print("\tPrivate DNS: ", inst.privateDnsName, "\n");
- print("\tPublic DNS: ", inst.dnsName, "\n");
- print("\tKey: ", inst.keyName, "\n");
- print("\tType: ", inst.instanceType, "\n");
- print("\tLaunch Time: ", inst.launchTime, "\n");
- print("\tAvailability Zone: ", inst.placement.availabilityZone, "\n");
- print("\tGroup Name: ", inst.placement.groupName, "\n");
- print("\tTenancy: ", inst.placement.tenancy, "\n");
- print("\tPrivate IP: ", inst.privateIpAddress, "\n");
- print("\tPublic IP: ", inst.ipAddress, "\n");
- if (inst.groupSet.item) {
- print("\tGroups:\n");
- for (grp in inst.groupSet.item)
- print("\t\t", inst.groupSet.item.groupId, " -- ", inst.groupSet.item.groupName, "\n");
- }
- print("\tRoot Device Type: ", inst.rootDeviceType, "\n");
- print("\tRoot Device Name: ", inst.rootDeviceName, "\n");
- print("\tDevice mapping:\n");
- for (dev in inst.blockDeviceMapping.item) {
- print("\t\t", dev.deviceName, " ", dev.ebs.volumeId, " ",
- dev.ebs.status, " ", dev.ebs.attachTime, " ",
- dev.ebs.deleteOnTermination, "\n");
- }
- print("\tVirtualization: ", inst.virtualizationType, "\n");
- print("\tTag Set:\n");
- for (tag in inst.tagSet.item) {
- print("\t\t", tag.key, "=", tag.value, "\n");
- }
- print("\tHypervisor: ", inst.hypervisor, "\n");
- // FIXME: networkInterfaceSet
- print("\tEBS Optimized: ", inst.ebsOptimized, "\n");
- print("End of instance\n\n");
- }
- }
- }
-} else if (.Response.Errors)
- error("Error: ",.Response.Errors.Error.Message,"\n");
-else {
- error("Unrecognized response:\n");
- dump(.);
-}
-EOT;
-
-
-
diff --git a/src/eclat.h b/src/eclat.h
index bd7a86b..242861b 100644
--- a/src/eclat.h
+++ b/src/eclat.h
@@ -45,2 +45,3 @@ extern char *access_key;
extern char *secret_key;
+extern char *format_file;
diff --git a/tests/.gitignore b/tests/.gitignore
index 8b76ee0..06ac629 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -8,2 +8,3 @@ tforlan
thmac
+trws
turlenc
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 4af19e3..99c2ae6 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -42,2 +42,5 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
TESTSUITE_AT = \
+ describe-instance-status.at\
+ describe-instances.at\
+ describe-tags.at\
dump01.at\
@@ -54,2 +57,4 @@ TESTSUITE_AT = \
print03.at\
+ start-instances.at\
+ stop-instances.at\
tagshairy.at\
@@ -83,2 +88,3 @@ noinst_PROGRAMS = \
thmac\
+ trws\
turlenc\
diff --git a/tests/describe-instance-status.at b/tests/describe-instance-status.at
new file mode 100644
index 0000000..e01b5fc
--- /dev/null
+++ b/tests/describe-instance-status.at
@@ -0,0 +1,154 @@
+# This file is part of Eclat -*- Autotest -*-
+# 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/>.
+
+ECLAT_TEST_FORMAT([DescribeInstanceStatus],
+[DescribeInstanceStatus],
+[describe-instance-status.fln],
+[<DescribeInstanceStatusResponse xmlns='http://ec2.amazonaws.com/doc/2012-04-01/'>
+ <requestId>3be1508e-c4