aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-09-30 18:38:09 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2012-09-30 18:38:09 +0300
commite3060ee47d58dac8827288614aaa86d5ad40e0ff (patch)
tree7e50e101a2ede83ae03def7617fa6ce5faface35
parent1de5ac257cb92f45f585e1a17b7cd7d2c5b7203c (diff)
downloadeclat-e3060ee47d58dac8827288614aaa86d5ad40e0ff.tar.gz
eclat-e3060ee47d58dac8827288614aaa86d5ad40e0ff.tar.bz2
Implement the describe-volumes command.
* etc/Makefile.am (FLNFILES): Add describe-volumes.fln (install-formats): New rule. * etc/describe-volumes.fln: New file. * src/Makefile.am (eclat_SOURCES): Add dscrvols.c (AM_LDFLAGS): Remove. (LDADD): Add $(CURL_LIBS) * src/accfile.c (get_access_creds): Minor changes. * src/cmdline.opt: New option --format-expression. * src/dscrinsts.c: Minor change. * src/dscrvols.c: New file. * src/eclat.c: New command "describe-volumes". * src/eclat.h (eclat_describe_volumes): New proto. * tests/describe-volumes.at: New file. * tests/Makefile.am: Add new file. * tests/testsuite.at: Include new file.
-rw-r--r--etc/Makefile.am7
-rw-r--r--etc/describe-volumes.fln31
-rw-r--r--src/Makefile.am4
-rw-r--r--src/accfile.c8
-rw-r--r--src/cmdline.opt6
-rw-r--r--src/dscrinsts.c2
-rw-r--r--src/dscrvols.c62
-rw-r--r--src/eclat.c19
-rw-r--r--src/eclat.h1
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/describe-volumes.at46
-rw-r--r--tests/testsuite.at1
12 files changed, 182 insertions, 6 deletions
diff --git a/etc/Makefile.am b/etc/Makefile.am
index 8539e93..7c852c4 100644
--- a/etc/Makefile.am
+++ b/etc/Makefile.am
@@ -23,6 +23,7 @@ FLNFILES=\
describe-instance-status.fln\
describe-instances.fln\
describe-tags.fln\
+ describe-volumes.fln\
start-instances.fln\
stop-instances.fln
@@ -51,6 +52,12 @@ CLEANFILES=eclat.conf $(FORMATFILES)
.cfin.conf:
$(AM_V_GEN)sed 's^FORMATDIR^$(formatdir)^;s^FORMATNAME^$(FORMATNAME)^' $< > $@
+install-formats: $(FORMATFILES)
+ ${INSTALL} -d $(DESTDIR)$(formatdir); \
+ for file in $(FORMATFILES); do \
+ ${INSTALL} -m 644 $$file $(DESTDIR)$(formatdir)/$$file; \
+ done
+
install-data-local:
@test -z "$(DESTDIR)$(sysconfdir)" || $(mkdir_p) "$(DESTDIR)$(sysconfdir)"
@if [ -r $(DESTDIR)$(sysconfdir)/eclat.conf ]; then :; \
diff --git a/etc/describe-volumes.fln b/etc/describe-volumes.fln
new file mode 100644
index 0000000..345f077
--- /dev/null
+++ b/etc/describe-volumes.fln
@@ -0,0 +1,31 @@
+/* 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 (.DescribeVolumesResponse.volumeSet.item) {
+ for (var in .DescribeVolumesResponse.volumeSet.item) {
+ print(var.volumeId,"\t",
+ var.size,"\t",
+ var.status);
+ if (var.attachmentSet) {
+ for (att in var.attachmentSet.item) {
+ print("\t", att.volumeId, "\t", att.instanceId, "\t",
+ att.device, "\t", att.status);
+ }
+ }
+ print("\n");
+ }
+}
+
diff --git a/src/Makefile.am b/src/Makefile.am
index dff9319..e09049f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -25,14 +25,14 @@ eclat_SOURCES=\
dscrtags.c\
dscrinsts.c\
dscrinststat.c\
+ dscrvols.c\
eclat.c\
eclat.h\
genericcl.c\
startinst.c\
util.c
-AM_LDFLAGS = $(CURL_LIBS)
-LDADD=../lib/libeclat.a @LIBOBJS@ ../grecs/src/libgrecs.a
+LDADD=../lib/libeclat.a @LIBOBJS@ ../grecs/src/libgrecs.a $(CURL_LIBS)
INCLUDES = -I$(top_srcdir)/grecs/src/ -I$(top_srcdir)/lib $(CURL_CFLAGS)
AM_CPPFLAGS= \
-DSYSCONFDIR=\"$(sysconfdir)\"\
diff --git a/src/accfile.c b/src/accfile.c
index 1d39717..07c9c2e 100644
--- a/src/accfile.c
+++ b/src/accfile.c
@@ -144,12 +144,20 @@ get_access_creds(const char *id, char **access_key_ptr, char **secret_key_ptr)
glob_t g;
int rc = 1;
+ if (!access_file_name) {
+ debug(ECLAT_DEBCAT_MAIN, 1, ("no access file given"));
+ return 1;
+ }
debug(ECLAT_DEBCAT_MAIN, 1, ("Looking for authentication credentials"));
switch (glob(access_file_name, 0, globerrfunc, &g)) {
case 0:
break;
case GLOB_NOSPACE:
grecs_alloc_die();
+ case GLOB_NOMATCH:
+ debug(ECLAT_DEBCAT_MAIN, 1,
+ ("No file matching %s", access_file_name));
+ return 1;
default:
err("globbing error");
return 1;
diff --git a/src/cmdline.opt b/src/cmdline.opt
index 357f7ef..03e94dd 100644
--- a/src/cmdline.opt
+++ b/src/cmdline.opt
@@ -115,6 +115,12 @@ BEGIN
format_name_option = optarg;
END
+OPTION(format-expression,e,EXPR,
+ [<format expression>])
+BEGIN
+ format_expr_option = optarg;
+END
+
OPTION(format-file,F,FILE,
[<use FILE to format the output>])
ALIAS(formfile)
diff --git a/src/dscrinsts.c b/src/dscrinsts.c
index 392fe37..145c50d 100644
--- a/src/dscrinsts.c
+++ b/src/dscrinsts.c
@@ -91,7 +91,7 @@ parse_options(int argc, char *argv[], int *index)
{ "subnet-id", FILTER_STRING },
{ "tag-key", FILTER_STRING },
{ "tag-value", FILTER_STRING },
- { "tag:key", FILTER_STRING },
+ { "tag:<KEY>", FILTER_STRING },
{ "virtualization-type", FILTER_STRING, virt_type_str },
{ "vpc-id", FILTER_STRING },
{ "hypervisor", FILTER_ENUM, hypervisor_str },
diff --git a/src/dscrvols.c b/src/dscrvols.c
new file mode 100644
index 0000000..f7d8087
--- /dev/null
+++ b/src/dscrvols.c
@@ -0,0 +1,62 @@
+/* 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"
+
+static char *attachment_status_str[] = {
+ "attaching", "attached", "detaching", "detached", NULL
+};
+static char *status_str[] = {
+ "creating", "available", "in-use", "deleting", "deleted", "error", NULL
+};
+static char *volume_type_str[] = { "standard", "io1", NULL };
+static struct filter_descr filters[] = {
+ { "attachment.attach-time", FILTER_DATE },
+ { "attachment.delete-on-termination", FILTER_BOOL },
+ { "attachment.device", FILTER_STRING },
+ { "attachment.instance-id", FILTER_STRING },
+ { "attachment.status", FILTER_ENUM, attachment_status_str },
+ { "availability-zone", FILTER_STRING },
+ { "create-time", FILTER_DATE },
+ { "size", FILTER_INT },
+ { "snapshot-id", FILTER_STRING },
+ { "status", FILTER_ENUM, status_str },
+ { "tag-key", FILTER_STRING },
+ { "tag-value", FILTER_STRING },
+ { "tag:<KEY>", FILTER_STRING },
+ { "volume-id", FILTER_STRING },
+ { "volume-type", FILTER_ENUM, volume_type_str },
+ { NULL }
+};
+
+
+int
+eclat_describe_volumes(CURL *curl, int argc, char **argv)
+{
+ int i;
+ struct ec2_query *q;
+
+ available_filters = filters;
+ generic_proginfo->print_help_hook = list_filters;
+ generic_parse_options("eclat describe-volumes",
+ "describe Amazon EBS volumes",
+ argc, argv, &i);
+ argv += i;
+ argc -= i;
+
+ q = describe_query_create(curl, "DescribeVolumes", argc, argv, NULL);
+ return eclat_send_query(curl, q);
+}
diff --git a/src/eclat.c b/src/eclat.c
index c245214..0da8c38 100644
--- a/src/eclat.c
+++ b/src/eclat.c
@@ -26,6 +26,7 @@ int use_ssl;
char *access_key;
char *secret_key;
char *region_name;
+char *format_expr_option;
char *format_file_option;
char *format_name_option;
int sort_option;
@@ -228,6 +229,8 @@ struct command cmdtab[] = {
eclat_describe_instance_status },
{ "describe-instances", "DescribeInstances",
eclat_describe_instances },
+ { "describe-volumes", "DescribeVolumes",
+ eclat_describe_volumes },
{ "associate-address", "AssociateAddress",
eclat_associate_address },
{ "disassociate-address", "DisassociateAddress",
@@ -452,10 +455,20 @@ read_format(struct command *cmd)
{
forlan_eval_env_t env = NULL;
- if (format_name_option)
- env = find_format(format_name_option);
- else if (format_file_option)
+ if (format_expr_option) {
+ struct grecs_locus_point pt;
+
+ pt.file = "<tty>";
+ pt.line = 1;
+ pt.col = 0;
+
+ env = forlan_parse_buffer(format_expr_option,
+ strlen(format_expr_option),
+ &pt);
+ } else if (format_file_option)
env = compile_format_file(format_file_option);
+ else if (format_name_option)
+ env = find_format(format_name_option);
else if (!cmd)
return NULL;
else if (cmd->fmt)
diff --git a/src/eclat.h b/src/eclat.h
index 587e2e4..9cc0176 100644
--- a/src/eclat.h
+++ b/src/eclat.h
@@ -65,6 +65,7 @@ int eclat_describe_instances(CURL *curl, int argc, char **argv);
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);
char *region_to_endpoint(const char *region);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 16a7dba..0f6a9c7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -45,6 +45,7 @@ TESTSUITE_AT = \
describe-instance-status.at\
describe-instances.at\
describe-tags.at\
+ describe-volumes.at\
dump01.at\
dump02.at\
forlan01.at\
diff --git a/tests/describe-volumes.at b/tests/describe-volumes.at
new file mode 100644
index 0000000..c3447bc
--- /dev/null
+++ b/tests/describe-volumes.at
@@ -0,0 +1,46 @@
+# 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([DescribeVolumes],
+[DescribeVolumes],
+[describe-volumes.fln],
+[<DescribeVolumesResponse xmlns="http://ec2.amazonaws.com/doc/2012-08-15/">
+ <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
+ <volumeSet>
+ <item>
+ <volumeId>vol-4282672b</volumeId>
+ <size>80</size>
+ <snapshotId/>
+ <availabilityZone>us-east-1a</availabilityZone>
+ <status>in-use</status>
+ <createTime>2008-05-07T11:51:50.000Z</createTime>
+ <attachmentSet>
+ <item>
+ <volumeId>vol-4282672b</volumeId>
+ <instanceId>i-6058a509</instanceId>
+ <device>/dev/sdh</device>
+ <status>attached</status>
+ <attachTime>2008-05-07T12:51:50.000Z</attachTime>
+ <deleteOnTermination>false</deleteOnTermination>
+ </item>
+ </attachmentSet>
+ <volumeType>standard</volumeType>
+ </item>
+ </volumeSet>
+</DescribeVolumesResponse>
+],
+[vol-4282672b 80 in-use vol-4282672b i-6058a509 /dev/sdh attached
+])
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 89f275d..f05baca 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -58,6 +58,7 @@ m4_include([describe-addresses.at])
m4_include([describe-instance-status.at])
m4_include([describe-instances.at])
m4_include([describe-tags.at])
+m4_include([describe-volumes.at])
m4_include([start-instances.at])
m4_include([stop-instances.at])

Return to:

Send suggestions and report system problems to the System administrator.