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 | |
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.
-rw-r--r-- | etc/Makefile.am | 1 | ||||
-rw-r--r-- | etc/describe-addresses.fln | 28 | ||||
-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 | ||||
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/describe-addresses.at | 127 | ||||
-rw-r--r-- | tests/testsuite.at | 1 |
12 files changed, 311 insertions, 6 deletions
diff --git a/etc/Makefile.am b/etc/Makefile.am index e182936..2f6f81a 100644 --- a/etc/Makefile.am +++ b/etc/Makefile.am @@ -19,6 +19,7 @@ noinst_PROGRAMS = flncat FLNFILES=\ associate-address.fln\ disassociate-address.fln\ + describe-addresses.fln describe-instance-status.fln\ describe-instances.fln\ describe-tags.fln\ diff --git a/etc/describe-addresses.fln b/etc/describe-addresses.fln new file mode 100644 index 0000000..bd83df7 --- /dev/null +++ b/etc/describe-addresses.fln @@ -0,0 +1,28 @@ +/* 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 (.DescribeAddressesResponse.addressesSet) { + for (var in .DescribeAddressesResponse.addressesSet.item) { + print(var.domain,"\t",var.publicIp,"\t",var.instanceId); + if (var.domain[vpc]) + print("\t",var.networkInterfaceId,"\t", + var.networkInterfaceOwnerId,"\t", + var.privateIpAddress,"\t", + var.allocationId,"\t", + var.associationId); + print("\n"); + } +} 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); diff --git a/tests/Makefile.am b/tests/Makefile.am index 1494290..16a7dba 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -41,6 +41,7 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac TESTSUITE_AT = \ associate-address.at\ + describe-addresses.at\ describe-instance-status.at\ describe-instances.at\ describe-tags.at\ diff --git a/tests/describe-addresses.at b/tests/describe-addresses.at new file mode 100644 index 0000000..8a1d5c8 --- /dev/null +++ b/tests/describe-addresses.at @@ -0,0 +1,127 @@ +# 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([DescribeAddresses (standard)], +[DescribeAddresses, DescribeAddresses-standard], +[describe-addresses.fln], +[<DescribeAddressesResponse xmlns="http://ec2.amazonaws.com/doc/2012-08-15/"> + <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId> + <addressesSet> + <item> + <publicIp>192.0.2.1</publicIp> + <domain>standard</domain> + <instanceId>i-f15ebb98</instanceId> + </item> + <item> + <publicIp>198.51.100.2</publicIp> + <domain>standard</domain> + <instanceId/> + </item> + </addressesSet> +</DescribeAddressesResponse> +], +[standard 192.0.2.1 i-f15ebb98 +standard 198.51.100.2 +]) + +ECLAT_TEST_FORMAT([DescribeAddresses (vpc)], +[DescribeAddresses, DescribeAddresses-vpc], +[describe-addresses.fln], +[<DescribeAddressesResponse xmlns="http://ec2.amazonaws.com/doc/2012-08-15/"> + <requestId>0782c68a-5f24-4dce-93c0-b5a066d6e0d0</requestId> + <addressesSet> + <item> + <publicIp>203.0.113.12</publicIp> + <allocationId>eipalloc-08229861</allocationId> + <domain>vpc</domain> + <instanceId>i-64600030</instanceId> + <associationId>eipassoc-f0229899</associationId> + <networkInterfaceId>eni-ef229886</networkInterfaceId> + <networkInterfaceOwnerId>053230519467</networkInterfaceOwnerId> + <privateIpAddress>10.0.0.228</privateIpAddress> + </item> + <item> + <publicIp>46.51.221.164</publicIp> + <allocationId>eipalloc-1b5fe072</allocationId> + <domain>vpc</domain> + </item> + <item> + <publicIp>203.0.113.14</publicIp> + <allocationId>eipalloc-f38a359a</allocationId> + <domain>vpc</domain> + <instanceId>i-7a00642e</instanceId> + <associationId>eipassoc-1f239876</associationId> + <networkInterfaceId>eni-d83388b1</networkInterfaceId> + <networkInterfaceOwnerId>053230519467</networkInterfaceOwnerId> + <privateIpAddress>10.0.0.12</privateIpAddress> + </item> + <item> + <publicIp>203.0.113.33</publicIp> + <allocationId>eipalloc-282d9641</allocationId> + <domain>vpc</domain> + <instanceId>i-7a00642e</instanceId> + <associationId>eipassoc-252d964c</associationId> + <networkInterfaceId>eni-d83388b1</networkInterfaceId> + <networkInterfaceOwnerId>053230519467</networkInterfaceOwnerId> + <privateIpAddress>10.0.0.14</privateIpAddress> + </item> + <item> + <publicIp>203.0.113.22</publicIp> + <allocationId>eipalloc-1266dd7b</allocationId> + <domain>vpc</domain> + <instanceId>i-880f6fdc</instanceId> + <associationId>eipassoc-832e94ea</associationId> + <networkInterfaceId>eni-af2e94c6</networkInterfaceId> + <networkInterfaceOwnerId>053230519467</networkInterfaceOwnerId> + <privateIpAddress>10.0.0.47</privateIpAddress> + </item> + <item> + <publicIp>203.0.113.42</publicIp> + <allocationId>eipalloc-ff229896</allocationId> + <domain>vpc</domain> + </item> + <item> + <publicIp>203.0.113.53</publicIp> + <allocationId>eipalloc-b463dcdd</allocationId> + <domain>vpc</domain> + <instanceId>i-c844219c</instanceId> + <associationId>eipassoc-d667ddbf</associationId> + <networkInterfaceId>eni-ea67dc83</networkInterfaceId> + <networkInterfaceOwnerId>053230519467</networkInterfaceOwnerId> + <privateIpAddress>10.0.0.174</privateIpAddress> + </item> + <item> + <publicIp>203.0.113.61</publicIp> + <allocationId>eipalloc-bf66dcd6</allocationId> + <domain>vpc</domain> + <instanceId>i-ba6a0dee</instanceId> + <associationId>eipassoc-9c66dcf5</associationId> + <networkInterfaceId>eni-73e05a1a</networkInterfaceId> + <networkInterfaceOwnerId>053230519467</networkInterfaceOwnerId> + <privateIpAddress>10.0.0.85</privateIpAddress> + </item> + </addressesSet> +</DescribeAddressesResponse> +], +[vpc 203.0.113.12 i-64600030 eni-ef229886 053230519467 10.0.0.228 eipalloc-08229861 eipassoc-f0229899 +vpc 46.51.221.164 eipalloc-1b5fe072 +vpc 203.0.113.14 i-7a00642e eni-d83388b1 053230519467 10.0.0.12 eipalloc-f38a359a eipassoc-1f239876 +vpc 203.0.113.33 i-7a00642e eni-d83388b1 053230519467 10.0.0.14 eipalloc-282d9641 eipassoc-252d964c +vpc 203.0.113.22 i-880f6fdc eni-af2e94c6 053230519467 10.0.0.47 eipalloc-1266dd7b eipassoc-832e94ea +vpc 203.0.113.42 eipalloc-ff229896 +vpc 203.0.113.53 i-c844219c eni-ea67dc83 053230519467 10.0.0.174 eipalloc-b463dcdd eipassoc-d667ddbf +vpc 203.0.113.61 i-ba6a0dee eni-73e05a1a 053230519467 10.0.0.85 eipalloc-bf66dcd6 eipassoc-9c66dcf5 +]) diff --git a/tests/testsuite.at b/tests/testsuite.at index 5cc0721..89f275d 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -54,6 +54,7 @@ m4_include([tagshairy.at]) AT_BANNER([Default formats]) m4_include([associate-address.at]) +m4_include([describe-addresses.at]) m4_include([describe-instance-status.at]) m4_include([describe-instances.at]) m4_include([describe-tags.at]) |