aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-10-01 11:14:58 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2012-10-01 11:14:58 +0300
commit78b25d9756403fef919684738f7aecb2cdcee465 (patch)
treed43f312f8f994be9d485dcc9c7c8ded3f415898f
parentf2ce145a8d27d18db064fc35313b7495f868b18b (diff)
downloadeclat-78b25d9756403fef919684738f7aecb2cdcee465.tar.gz
eclat-78b25d9756403fef919684738f7aecb2cdcee465.tar.bz2
Implement get-console-output command.
* etc/Makefile.am: Add new files. * etc/get-console-output.fln: New file. * lib/forlan.c: New built-in function "decode". * lib/forlangrm.y: Fix grammar to allow functions to return any data type, not only node. * src/Makefile.am (eclat_SOURCES): Add new files. * src/eclat.c: Register get-console-output command. * src/eclat.h (eclat_get_console_output): New proto. * src/getconout.c: New file. * tests/Makefile.am: Add new files. * tests/testsuite.at: Include new files. * tests/decode.at: New test case. * tests/get-console-output.at: New test case. * tests/last.at: Minor change.
-rw-r--r--etc/Makefile.am1
-rw-r--r--etc/get-console-output.fln18
-rw-r--r--lib/forlan.c28
-rw-r--r--lib/forlangrm.y29
-rw-r--r--src/Makefile.am1
-rw-r--r--src/eclat.c2
-rw-r--r--src/eclat.h1
-rw-r--r--src/getconout.c40
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/decode.at28
-rw-r--r--tests/get-console-output.at47
-rw-r--r--tests/last.at2
-rw-r--r--tests/testsuite.at2
13 files changed, 183 insertions, 18 deletions
diff --git a/etc/Makefile.am b/etc/Makefile.am
index 2b1c84d..6ef5e1a 100644
--- a/etc/Makefile.am
+++ b/etc/Makefile.am
@@ -24,6 +24,7 @@ FLNFILES=\
describe-instances.fln\
describe-tags.fln\
describe-volumes.fln\
+ get-console-output.fln\
reboot-instances.fln\
start-instances.fln\
stop-instances.fln
diff --git a/etc/get-console-output.fln b/etc/get-console-output.fln
new file mode 100644
index 0000000..382ffba
--- /dev/null
+++ b/etc/get-console-output.fln
@@ -0,0 +1,18 @@
+/* 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 (.GetConsoleOutputResponse.output)
+ print(decode(last), "\n"); \ No newline at end of file
diff --git a/lib/forlan.c b/lib/forlan.c
index 6c4a44a..f12e00b 100644
--- a/lib/forlan.c
+++ b/lib/forlan.c
@@ -808,12 +808,40 @@ func_sort(forlan_eval_env_t env, struct grecs_list *list)
grecs_tree_sort(val->v.node, node_ident_cmp);
}
+void
+func_decode(forlan_eval_env_t env, struct grecs_list *list)
+{
+ struct forlan_value *val = list->head->data;
+ struct grecs_txtacc *acc = grecs_txtacc_create();
+ char *p;
+
+ for (p = val->v.string; *p; ) {
+ size_t ilen, olen;
+ unsigned char *optr;
+
+ while (*p && isspace(*p))
+ p++;
+ if (!*p)
+ break;
+ ilen = strcspn(p, " \t\f\n");
+ eclat_base64_decode(p, ilen, &optr, &olen);
+ grecs_txtacc_grow(acc, optr, olen);
+ free(optr);
+
+ p += ilen;
+ }
+ grecs_txtacc_grow_char(acc, 0);
+ env->retval.v.string = grecs_txtacc_finish(acc, 1);
+ grecs_txtacc_free(acc);
+}
+
static struct forlan_function functab[] = {
{ "dump", forlan_value_void, "n", 1, 1, func_dump },
{ "print", forlan_value_void, "", 1, -1, func_print },
{ "error", forlan_value_void, "", 1, -1, func_error },
{ "parent", forlan_value_node, "n", 1, 1, func_parent },
{ "sort", forlan_value_void, "n", 1, 1, func_sort },
+ { "decode", forlan_value_literal, "s", 1, 1, func_decode },
{ NULL }
};
diff --git a/lib/forlangrm.y b/lib/forlangrm.y
index 6261c5e..884ff1e 100644
--- a/lib/forlangrm.y
+++ b/lib/forlangrm.y
@@ -66,11 +66,11 @@ free_comp(void *p)
%left AND
%left NOT
-%type <node> stmt stmt_cond stmt_expr stmt_blk cond bool node funcall arg
+%type <node> stmt stmt_cond stmt_expr stmt_blk cond bool node funcall arg rval
%type <node> stmt_let stmt_for stmt_ctrl stmt_asgn
%type <list> stmtlist arglist
-%type <complist> complist
%type <string> string
+%type <complist> complist
%type <comp> comp
%%
@@ -158,16 +158,8 @@ bool : node
}
;
-node : funcall
- {
- $$ = forlan_node_create(forlan_type_comp);
- $$->comp.root = $1;
- $$->comp.wildcards = 0;
- $$->comp.argc = 0;
- $$->comp.argv = NULL;
- $$->comp.labelv = NULL;
- }
- | funcall '.' complist
+node : rval
+ | rval '.' complist
{
$$ = create_comp_node($1, $3.list, $3.wildcards);
}
@@ -297,6 +289,14 @@ funcall : IDENT '(' ')'
}
;
+rval : funcall
+ | STRING
+ {
+ $$ = forlan_node_create(forlan_type_lit);
+ $$->lit.string = $1;
+ }
+ ;
+
arglist : arg
{
$$ = forlan_stmt_list();
@@ -310,11 +310,6 @@ arglist : arg
;
arg : node
- | STRING
- {
- $$ = forlan_node_create(forlan_type_lit);
- $$->lit.string = $1;
- }
;
stmt_expr : funcall ';'
diff --git a/src/Makefile.am b/src/Makefile.am
index e09049f..c344b5b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -29,6 +29,7 @@ eclat_SOURCES=\
eclat.c\
eclat.h\
genericcl.c\
+ getconout.c\
startinst.c\
util.c
diff --git a/src/eclat.c b/src/eclat.c
index 1d5e51c..9464dd2 100644
--- a/src/eclat.c
+++ b/src/eclat.c
@@ -236,6 +236,8 @@ struct command cmdtab[] = {
eclat_associate_address },
{ "disassociate-address", "DisassociateAddress",
eclat_disassociate_address },
+ { "get-console-output", "GetConsoleOutput",
+ eclat_get_console_output }
};
size_t cmdcnt = sizeof(cmdtab) / sizeof(cmdtab[0]);
diff --git a/src/eclat.h b/src/eclat.h
index 86f7498..e24b591 100644
--- a/src/eclat.h
+++ b/src/eclat.h
@@ -67,6 +67,7 @@ int eclat_associate_address(CURL *curl, int argc, char **argv);
int eclat_disassociate_address(CURL *curl, int argc, char **argv);
int eclat_describe_addresses(CURL *curl, int argc, char **argv);
int eclat_describe_volumes(CURL *curl, int argc, char **argv);
+int eclat_get_console_output(CURL *curl, int argc, char **argv);
char *region_to_endpoint(const char *region);
diff --git a/src/getconout.c b/src/getconout.c
new file mode 100644
index 0000000..abf08c0
--- /dev/null
+++ b/src/getconout.c
@@ -0,0 +1,40 @@
+/* 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_get_console_output(CURL *curl, int argc, char **argv)
+{
+ int i;
+ struct ec2_query *q;
+
+ generic_parse_options("eclat get-console-output",
+ "retrieve onsole output for the specified "
+ "instance",
+ argc, argv, &i);
+ argv += i;
+ argc -= i;
+
+ if (i == 0)
+ die(EX_USAGE, "not enough arguments");
+ else if (i > 1)
+ die(EX_USAGE, "only one argument is allowed");
+
+ q = describe_query_create(curl, "GetConsoleOutput", argc, argv,
+ "InstanceId");
+ return eclat_send_query(curl, q);
+}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0f6a9c7..181f2f0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -41,11 +41,13 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
TESTSUITE_AT = \
associate-address.at\
+ decode.at\
describe-addresses.at\
describe-instance-status.at\
describe-instances.at\
describe-tags.at\
describe-volumes.at\
+ get-console-output.at\
dump01.at\
dump02.at\
forlan01.at\
diff --git a/tests/decode.at b/tests/decode.at
new file mode 100644
index 0000000..208de1b
--- /dev/null
+++ b/tests/decode.at
@@ -0,0 +1,28 @@
+# 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/>.
+
+AT_SETUP(base64 decode function)
+
+AT_DATA([prog],[
+print(decode("RXN0ZSBlcyB1biBudWV2byBkaWEgcGEnIGVtcGV6YXIgZGUgbnVldm8K"));
+])
+
+AT_CHECK([tforlan prog /dev/null],
+[0],
+[Este es un nuevo dia pa' empezar de nuevo
+])
+
+AT_CLEANUP \ No newline at end of file
diff --git a/tests/get-console-output.at b/tests/get-console-output.at
new file mode 100644
index 0000000..70a6e21
--- /dev/null
+++ b/tests/get-console-output.at
@@ -0,0 +1,47 @@
+# 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([GetConsoleOutput],
+[GetConsoleOutput],
+[get-console-output.fln],
+[<GetConsoleOutputResponse xmlns="http://ec2.amazonaws.com/doc/2012-08-15/">
+ <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
+ <instanceId>i-28a64341</instanceId>
+ <timestamp>2010-10-14T01:12:41.000Z</timestamp>
+ <output>TGludXggdmVyc2lvbiAyLjYuMTYteGVuVSAoYnVpbGRlckBwYXRjaGJhdC5hbWF6b25zYSkgKGdj
+YyB2ZXJzaW9uIDQuMC4xIDIwMDUwNzI3IChSZWQgSGF0IDQuMC4xLTUpKSAjMSBTTVAgVGh1IE9j
+dCAyNiAwODo0MToyNiBTQVNUIDIwMDYKQklPUy1wcm92aWRlZCBwaHlzaWNhbCBSQU0gbWFwOgpY
+ZW46IDAwMDAwMDAwMDAwMDAwMDAgLSAwMDAwMDAwMDZhNDAwMDAwICh1c2FibGUpCjk4ME1CIEhJ
+R0hNRU0gYXZhaWxhYmxlLgo3MjdNQiBMT1dNRU0gYXZhaWxhYmxlLgpOWCAoRXhlY3V0ZSBEaXNh
+YmxlKSBwcm90ZWN0aW9uOiBhY3RpdmUKSVJRIGxvY2t1cCBkZXRlY3Rpb24gZGlzYWJsZWQKQnVp
+bHQgMSB6b25lbGlzdHMKS2VybmVsIGNvbW1hbmQgbGluZTogcm9vdD0vZGV2L3NkYTEgcm8gNApF
+bmFibGluZyBmYXN0IEZQVSBzYXZlIGFuZCByZXN0b3JlLi4uIGRvbmUuCg==</output>
+</GetConsoleOutputResponse>
+],
+[Linux version 2.6.16-xenU (builder@patchbat.amazonsa) (gcc version 4.0.1 20050727 (Red Hat 4.0.1-5)) #1 SMP Thu Oct 26 08:41:26 SAST 2006
+BIOS-provided physical RAM map:
+Xen: 0000000000000000 - 000000006a400000 (usable)
+980MB HIGHMEM available.
+727MB LOWMEM available.
+NX (Execute Disable) protection: active
+IRQ lockup detection disabled
+Built 1 zonelists
+Kernel command line: root=/dev/sda1 ro 4
+Enabling fast FPU save and restore... done.
+
+])
+
+
diff --git a/tests/last.at b/tests/last.at
index 10c29c6..6aa4b27 100644
--- a/tests/last.at
+++ b/tests/last.at
@@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with Eclat. If not, see <http://www.gnu.org/licenses/>.
-AT_SETUP([the last function])
+AT_SETUP([the last statement])
AT_KEYWORDS([forlan last])
AT_DATA([input],[//
diff --git a/tests/testsuite.at b/tests/testsuite.at
index f05baca..1776e3b 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -47,6 +47,7 @@ m4_include([dump02.at])
m4_include([print01.at])
m4_include([print02.at])
m4_include([print03.at])
+m4_include([decode.at])
m4_include([last.at])
m4_include([let.at])
m4_include([listall.at])
@@ -59,6 +60,7 @@ m4_include([describe-instance-status.at])
m4_include([describe-instances.at])
m4_include([describe-tags.at])
m4_include([describe-volumes.at])
+m4_include([get-console-output.at])
m4_include([start-instances.at])
m4_include([stop-instances.at])

Return to:

Send suggestions and report system problems to the System administrator.