From 141a22cb7bb918a08698785f860a902ea4448b5c Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Thu, 6 Dec 2012 16:04:13 +0200 Subject: Implement the describe-regions command. * TODO: Update. * doc/Makefile.am: Add new files. * doc/eclat-describe-availability-zones.1: Mention describe-regions. * doc/eclat-describe-regions.1: New file. * doc/tmpl.1: Fix time-stamp-start setting. * etc/Makefile.am: Add new files. * etc/describe-regions.fln: New file. * src/Makefile.am: Add new files. * src/dscrregs.c: New file. * src/eclat.c: Register describe-regions. * src/eclat.h (eclat_describe_regions): New proto. --- TODO | 2 +- doc/Makefile.am | 1 + doc/eclat-describe-availability-zones.1 | 6 ++- doc/eclat-describe-regions.1 | 77 +++++++++++++++++++++++++++++++++ doc/tmpl.1 | 4 +- etc/Makefile.am | 1 + etc/describe-regions.fln | 21 +++++++++ src/Makefile.am | 1 + src/dscrregs.c | 50 +++++++++++++++++++++ src/eclat.c | 2 + src/eclat.h | 1 + 11 files changed, 162 insertions(+), 4 deletions(-) create mode 100644 doc/eclat-describe-regions.1 create mode 100644 etc/describe-regions.fln create mode 100644 src/dscrregs.c diff --git a/TODO b/TODO index 467c528..44fa7e7 100644 --- a/TODO +++ b/TODO @@ -87,7 +87,7 @@ DescribeNetworkAcls DSCRNETACLS [ ] [ ] DescribeNetworkInterfaceAttribute DSCRNETIFATTR [ ] [ ] DescribeNetworkInterfaces DSCRNETIFS [ ] [ ] DescribePlacementGroups DSCRPLCGRPS [ ] [ ] -DescribeRegions DSCRREGS [ ] [ ] +DescribeRegions DSCRREGS [X] [X] DescribeReservedInstances DSCRRSRVDINSTS [ ] [ ] DescribeReservedInstancesListings DSCRRSRVDINSTSLSTS [ ] [ ] DescribeReservedInstancesOfferings DSCRRSRVDINSTSOFRS [ ] [ ] diff --git a/doc/Makefile.am b/doc/Makefile.am index eb56d02..051b8e0 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -27,6 +27,7 @@ MANPAGES1=\ eclat-describe-instance-attribute.1\ eclat-describe-instance-status.1\ eclat-describe-instances.1\ + eclat-describe-regions.1\ eclat-describe-security-groups.1\ eclat-describe-snapshots.1\ eclat-describe-tags.1\ diff --git a/doc/eclat-describe-availability-zones.1 b/doc/eclat-describe-availability-zones.1 index 6e719ea..722becc 100644 --- a/doc/eclat-describe-availability-zones.1 +++ b/doc/eclat-describe-availability-zones.1 @@ -28,6 +28,9 @@ set by the configuration file statement or the .B \-\-region command line option. +.PP +If no arguments are given, the command will list all availability +zones. Otherwise, it will list only zones with the supplied names. .SH FILTERS Filters allow you to select only zones matching particular criteria. The following filters are defined: @@ -63,7 +66,8 @@ eu-west-1b available eu-west-1c available .fi .SH "SEE ALSO" -.BR eclat (1). +.BR eclat (1), +.BR eclat\-describe\-regions (1). .SH AUTHORS Sergey Poznyakoff .SH "BUG REPORTS" diff --git a/doc/eclat-describe-regions.1 b/doc/eclat-describe-regions.1 new file mode 100644 index 0000000..fe0c4fe --- /dev/null +++ b/doc/eclat-describe-regions.1 @@ -0,0 +1,77 @@ +.\" This file is part of Eclat -*- nroff -*- +.\" 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 . +.TH ECLAT\-DESCRIBE\-REGIONS 1 "December 6, 2012" "ECLAT" "Eclat User Reference" +.SH NAME +eclat describe\-regions \- describe EC2 regions +.SH SYNOPSIS +eclat describe\-regions [\fBFILTER\fR...] [\fBREGION\fR...] + +eclat describe\-regions \fB\-\-help\fR +.SH DESCRIPTION +This command lists the EC2 regions. If no arguments are provided, it +lists all regions available to the account. Otherwise, each argument +is treated as a name of the region to describe. +.SH FILTERS +Filters allow you to select only regions matching particular +criteria. The following filters are defined: +.TP +\fBendpoint\fR=\fIstring\fR +The endpoint of the region. +.TP +\fBregion\-name\fR=\fIstring\fR +The region name. It is the same as giving \fBstring\fR as a command +line argument. +.SH OUTPUT +The default output shows one region per line. Each line of output +contains region name and corresponding endpoint, separated by a single +horizontal tab character. +.SH EXAMPLE +.nf +.sp 2 +$ \fBeclat describe-regions\fR +eu-west-1 ec2.eu-west-1.amazonaws.com +sa-east-1 ec2.sa-east-1.amazonaws.com +us-east-1 ec2.us-east-1.amazonaws.com +ap-northeast-1 ec2.ap-northeast-1.amazonaws.com +us-west-2 ec2.us-west-2.amazonaws.com +us-west-1 ec2.us-west-1.amazonaws.com +ap-southeast-1 ec2.ap-southeast-1.amazonaws.com +ap-southeast-2 ec2.ap-southeast-2.amazonaws.com +.fi +.SH "SEE ALSO" +.BR eclat (1), +.BR eclat\-describe\-availability\-zones (1). +.SH AUTHORS +Sergey Poznyakoff +.SH "BUG REPORTS" +Report bugs to . +.SH COPYRIGHT +Copyright \(co 2012 Sergey Poznyakoff +.br +.na +License GPLv3+: GNU GPL version 3 or later +.br +.ad +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. +.\" Local variables: +.\" eval: (add-hook 'write-file-hooks 'time-stamp) +.\" time-stamp-start: ".TH [A-Z_][A-Z0-9_.\\-]* [0-9] \"" +.\" time-stamp-format: "%:B %:d, %:y" +.\" time-stamp-end: "\"" +.\" time-stamp-line-limit: 20 +.\" end: + diff --git a/doc/tmpl.1 b/doc/tmpl.1 index 7a9de87..077b07f 100644 --- a/doc/tmpl.1 +++ b/doc/tmpl.1 @@ -13,7 +13,7 @@ .\" .\" You should have received a copy of the GNU General Public License .\" along with Eclat. If not, see . -.TH ECLAT 1 "October 15, 2012" "ECLAT" "Eclat User Reference" +.TH ECLAT 1 "December 6, 2012" "ECLAT" "Eclat User Reference" .SH NAME eclat \- EC2 Command Line Administrator Tool .SH SYNOPSIS @@ -37,7 +37,7 @@ This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. .\" Local variables: .\" eval: (add-hook 'write-file-hooks 'time-stamp) -.\" time-stamp-start: ".TH [A-Z_][A-Z0-9_.-]* [0-9] \"" +.\" time-stamp-start: ".TH [A-Z_][A-Z0-9_.\\-]* [0-9] \"" .\" time-stamp-format: "%:B %:d, %:y" .\" time-stamp-end: "\"" .\" time-stamp-line-limit: 20 diff --git a/etc/Makefile.am b/etc/Makefile.am index 0a64e40..4cde97f 100644 --- a/etc/Makefile.am +++ b/etc/Makefile.am @@ -27,6 +27,7 @@ FLNFILES=\ describe-instance-attribute.fln\ describe-instance-status.fln\ describe-instances.fln\ + describe-regions.fln\ describe-security-groups.fln\ describe-snapshots.fln\ describe-tags.fln\ diff --git a/etc/describe-regions.fln b/etc/describe-regions.fln new file mode 100644 index 0000000..bbe7328 --- /dev/null +++ b/etc/describe-regions.fln @@ -0,0 +1,21 @@ +/* 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 . */ + +if (.DescribeRegionsResponse) { + for (var in .DescribeRegionsResponse.regionInfo.item) { + print(var.regionName,"\t",var.regionEndpoint,"\n"); + } +} diff --git a/src/Makefile.am b/src/Makefile.am index 7f20ba4..4d2b443 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -29,6 +29,7 @@ eclat_SOURCES=\ dscraddrs.c\ dscrazs.c\ dscrsnap.c\ + dscrregs.c\ dscrtags.c\ dscrinstattr.c\ dscrinsts.c\ diff --git a/src/dscrregs.c b/src/dscrregs.c new file mode 100644 index 0000000..658e71e --- /dev/null +++ b/src/dscrregs.c @@ -0,0 +1,50 @@ +/* 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 . */ + +#include "eclat.h" + +static void +parse_options(int argc, char *argv[], int *index) +{ + static struct filter_descr filters[] = { + { "endpoint", FILTER_STRING }, + { "region-name", FILTER_STRING }, + { NULL } + }; + + available_filters = filters; + generic_proginfo->print_help_hook = list_filters; + generic_proginfo->args_doc = "[REGION [REGION...]]"; + return generic_parse_options("eclat describe-regiones", + "List available regions", + argc, argv, index); +} + +int +eclat_describe_regions(CURL *curl, int argc, char **argv) +{ + int i; + struct ec2_query *q; + + parse_options(argc, argv, &i); + argv += i; + argc -= i; + translate_ids(argc, argv, "reg"); + + q = describe_query_create(curl, "DescribeRegions", + argc, argv, "RegionName"); + return eclat_send_query(curl, q); +} diff --git a/src/eclat.c b/src/eclat.c index c6a1fa4..2c0dcfe 100644 --- a/src/eclat.c +++ b/src/eclat.c @@ -244,6 +244,8 @@ struct command cmdtab[] = { eclat_delete_snapshot }, { "describe-avaialbility-zones", "DescribeAvaialbilityZones", eclat_describe_avaialbility_zones }, + { "describe-regions", "DescribeRegions", + eclat_describe_regions }, }; size_t cmdcnt = sizeof(cmdtab) / sizeof(cmdtab[0]); diff --git a/src/eclat.h b/src/eclat.h index 94140bb..e369b7c 100644 --- a/src/eclat.h +++ b/src/eclat.h @@ -85,6 +85,7 @@ int eclat_create_snapshot(CURL *curl, int argc, char **argv); int eclat_describe_snapshots(CURL *curl, int argc, char **argv); int eclat_delete_snapshot(CURL *curl, int argc, char **argv); int eclat_describe_avaialbility_zones(CURL *curl, int argc, char **argv); +int eclat_describe_regions(CURL *curl, int argc, char **argv); char *region_to_endpoint(const char *region); -- cgit v1.2.1