diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2012-09-29 10:34:41 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2012-09-29 10:34:41 +0300 |
commit | fa9cb6dc9bac292eb92347bb44faa2d3677c4dac (patch) | |
tree | 2d2f30bf2592e48a809acdf703846a4743c2c6ee /src | |
parent | 61696066e3c9384580b90d246864b7c69403cb10 (diff) | |
download | eclat-fa9cb6dc9bac292eb92347bb44faa2d3677c4dac.tar.gz eclat-fa9cb6dc9bac292eb92347bb44faa2d3677c4dac.tar.bz2 |
Implement describe-addresses; improve assign-address (vpc functionality)
* etc/Makefile.am: Add new files.
* etc/describe-addresses.fln
* src/Makefile.am: Add new files.
* src/asscaddr-cl.opt: New file.
* src/asscaddr.c: Handle VPC addresses.
* src/dscraddrs-cl.opt: New file.
* src/dscraddrs.c: New file.
* src/eclat.c: Add new commands.
* src/eclat.h: Update.
* tests/Makefile.am: Add new test suites.
* tests/testsuite.at: Likewise.
* tests/describe-addresses.at: New file.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/asscaddr-cl.opt | 55 | ||||
-rw-r--r-- | src/asscaddr.c | 23 | ||||
-rw-r--r-- | src/dscraddrs-cl.opt | 37 | ||||
-rw-r--r-- | src/dscraddrs.c | 34 | ||||
-rw-r--r-- | src/eclat.c | 6 | ||||
-rw-r--r-- | src/eclat.h | 1 |
7 files changed, 153 insertions, 6 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 423dbd8..dff9319 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,6 +21,7 @@ eclat_SOURCES=\ asscaddr.c\ cmdline.h\ config.c\ + dscraddrs.c\ dscrtags.c\ dscrinsts.c\ dscrinststat.c\ @@ -40,6 +41,8 @@ AM_CPPFLAGS= \ -DDEFAULT_PREPROCESSOR="$(DEFAULT_PREPROCESSOR)" OPTFILES=\ + asscaddr-cl.opt\ + dscraddrs-cl.opt\ dscrinststat-cl.opt\ generic-cl.opt diff --git a/src/asscaddr-cl.opt b/src/asscaddr-cl.opt new file mode 100644 index 0000000..298fb1a --- /dev/null +++ b/src/asscaddr-cl.opt @@ -0,0 +1,55 @@ +/* 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/>. */ + +OPTIONS_BEGIN("eclat associate-address", + [<associate IP address with an instance>], + [<INSTANCE IP-OR-ALLOC-ID>], + [<gnu>], + [<nousage>], + [<noversion>]) + +OPTION(vpc,v,, + [<assign VPC addresses>]) +BEGIN + vpc = 1; +END + +OPTION(interface,i,IFACE, + [<network interface ID to associate with an instance (vpc only)>]) +BEGIN + iface = optarg; +END + +OPTION(private-address,p,ADDR, + [<private IP address to associate with the Elastic IP address (vpc only)>]) +BEGIN + privaddr = optarg; +END + +OPTION(allow-reassociation,A,, + [<allow to reassociate an already associated address (vpc only)>]) +BEGIN + reassoc = 1; +END + +OPTIONS_END + +static void +parse_options(int argc, char *argv[], int *index) +{ + GETOPT(argc, argv, *index, exit(EX_USAGE)) +} + diff --git a/src/asscaddr.c b/src/asscaddr.c index b18abc9..7767664 100644 --- a/src/asscaddr.c +++ b/src/asscaddr.c @@ -15,6 +15,11 @@ along with Eclat. If not, see <http://www.gnu.org/licenses/>. */ #include "eclat.h" +static int vpc; +static char *iface; +static char *privaddr; +static int reassoc; +#include "asscaddr-cl.h" int eclat_associate_address(CURL *curl, int argc, char **argv) @@ -22,9 +27,7 @@ eclat_associate_address(CURL *curl, int argc, char **argv) int i; struct ec2_query *q; - generic_parse_options("eclat associate-address", - "INSTANCE IP", - argc, argv, &i); + parse_options(argc, argv, &i); argc -= i; argv += i; @@ -34,8 +37,18 @@ eclat_associate_address(CURL *curl, int argc, char **argv) q = eclat_query_create(use_ssl ? EC2_QF_HTTPS : 0, endpoint, "/"); eclat_query_add_param(q, "Action", "AssociateAddress"); eclat_query_add_param(q, "InstanceId", argv[0]); - eclat_query_add_param(q, "PublicIp", argv[1]); - + if (vpc) { + eclat_query_add_param(q, "AllocationId", argv[1]); + if (iface) + eclat_query_add_param(q, "NetworkInterfaceId", iface); + if (privaddr) + eclat_query_add_param(q, "PrivateIpAddress", privaddr); + if (reassoc) + eclat_query_add_param(q, "AllowReassociation", "true"); + + } else { + eclat_query_add_param(q, "PublicIp", argv[1]); + } return eclat_send_query(curl, q); } diff --git a/src/dscraddrs-cl.opt b/src/dscraddrs-cl.opt new file mode 100644 index 0000000..05439e5 --- /dev/null +++ b/src/dscraddrs-cl.opt @@ -0,0 +1,37 @@ +/* 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/>. */ + +OPTIONS_BEGIN("eclat describe-addresses", + [<describe elastic IP addresses>], + [<[FILTER...]>], + [<gnu>], + [<nousage>], + [<noversion>]) + +OPTION(vpc,v,, + [<describe VPC addresses>]) +BEGIN + vpc = 1; +END + +OPTIONS_END + +static void +parse_options(int argc, char *argv[], int *index) +{ + GETOPT(argc, argv, *index, exit(EX_USAGE)) +} + diff --git a/src/dscraddrs.c b/src/dscraddrs.c new file mode 100644 index 0000000..fe26664 --- /dev/null +++ b/src/dscraddrs.c @@ -0,0 +1,34 @@ +/* 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 int vpc = 0; +#include "dscraddrs-cl.h" + +int +eclat_describe_addresses(CURL *curl, int argc, char **argv) +{ + int i; + struct ec2_query *q; + + parse_options(argc, argv, &i); + argv += i; + argc -= i; + + q = describe_query_create(curl, "DescribeAddresses", argc, argv, + vpc ? "AllocationId" : "PublicIp"); + return eclat_send_query(curl, q); +} diff --git a/src/eclat.c b/src/eclat.c index 746de0d..c245214 100644 --- a/src/eclat.c +++ b/src/eclat.c @@ -221,6 +221,8 @@ struct command { struct command cmdtab[] = { { "start-instances", "StartInstances", eclat_start_instance }, { "stop-instances", "StopInstances", eclat_stop_instance }, + { "describe-addresses", "DescribeAddresses", + eclat_describe_addresses }, { "describe-tags", "DescribeTags", eclat_describe_tags }, { "describe-instance-status", "DescribeInstanceStatus", eclat_describe_instance_status }, @@ -454,7 +456,9 @@ read_format(struct command *cmd) env = find_format(format_name_option); else if (format_file_option) env = compile_format_file(format_file_option); - else if (cmd && cmd->fmt) + else if (!cmd) + return NULL; + else if (cmd->fmt) env = forlan_parse_buffer(cmd->fmt, strlen(cmd->fmt), &cmd->locus.beg); else if (format_file) { diff --git a/src/eclat.h b/src/eclat.h index fd3dd60..587e2e4 100644 --- a/src/eclat.h +++ b/src/eclat.h @@ -64,6 +64,7 @@ int eclat_describe_instance_status(CURL *curl, int argc, char **argv); 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); char *region_to_endpoint(const char *region); |