diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-11-19 13:26:52 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-11-19 13:30:24 +0200 |
commit | 858fef585e97f210378ca40b2287a78ced74c0de (patch) | |
tree | 2bd6eec8bf30899fb9b88b01a502a04ce3bee08a | |
parent | a32c2acdae16394613be0fe01fa5c439a0f247d0 (diff) | |
download | eclat-858fef585e97f210378ca40b2287a78ced74c0de.tar.gz eclat-858fef585e97f210378ca40b2287a78ced74c0de.tar.bz2 |
New commands: assocrtab, mkrtab, rmrtab, lsrtab, disasrtab, route
These implement the following EC2 actions: AssociateRouteTable,
CreateRoute, CreateRouteTable, DeleteRoute, DeleteRouteTable,
DescribeRouteTables, DisassociateRouteTable, ReplaceRoute.
* TODO: Update.
* etc/Makefile.am: Add new formats.
* etc/associate-route-table.fln: New file.
* etc/create-route-table.fln: New file.
* etc/create-route.fln: New file.
* etc/delete-route-table.fln: New file.
* etc/delete-route.fln: New file.
* etc/describe-route-tables.fln: New file.
* etc/disassociate-route-table.fln: New file.
* etc/replace-route.fln: New file.
* etc/route.fln: New file.
* src/Makefile.am: Add routetable.c
* src/routetable.c: New file.
* src/eclat.c (cmdtab): Register new subcommands.
* src/eclat.h (ECLAT_DEBCAT_DUMP): New category.
Add new protos.
* src/io.c (write_callback): Enable XML dump if dump debug
category is set.
-rw-r--r-- | TODO | 16 | ||||
-rw-r--r-- | etc/Makefile.am | 9 | ||||
-rw-r--r-- | etc/associate-route-table.fln | 19 | ||||
-rw-r--r-- | etc/create-route-table.fln | 28 | ||||
-rw-r--r-- | etc/create-route.fln | 22 | ||||
-rw-r--r-- | etc/delete-route-table.fln | 22 | ||||
-rw-r--r-- | etc/delete-route.fln | 22 | ||||
-rw-r--r-- | etc/describe-route-tables.fln | 41 | ||||
-rw-r--r-- | etc/disassociate-route-table.fln | 20 | ||||
-rw-r--r-- | etc/replace-route.fln | 22 | ||||
-rw-r--r-- | etc/route.fln | 33 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/eclat.c | 23 | ||||
-rw-r--r-- | src/eclat.h | 10 | ||||
-rw-r--r-- | src/io.c | 3 | ||||
-rw-r--r-- | src/routetable.c | 220 |
16 files changed, 497 insertions, 14 deletions
@@ -12,7 +12,7 @@ AllocateAddress allocaddr [X] [X] AssignPrivateIpAddresses - [ ] [ ] AssociateAddress assocaddr [X] [X] AssociateDhcpOptions - [ ] [ ] -AssociateRouteTable - [ ] [ ] +AssociateRouteTable assocrtab [X] [ ] AttachInternetGateway atigw [X] [ ] AttachNetworkInterface - [ ] [ ] AttachVolume atvol [X] [X] @@ -39,8 +39,8 @@ CreateNetworkAclEntry - [ ] [ ] CreateNetworkInterface - [ ] [ ] CreatePlacementGroup - [ ] [ ] CreateReservedInstancesListing - [ ] [ ] -CreateRoute - [ ] [ ] -CreateRouteTable - [ ] [ ] +CreateRoute route ID add [X] [ ] +CreateRouteTable mkrtab [X] [ ] CreateSecurityGroup mksg [X] [X] CreateSnapshot mksnap [X] [X] CreateSpotDatafeedSubscription - [ ] [ ] @@ -59,8 +59,8 @@ DeleteNetworkAcl - [ ] [ ] DeleteNetworkAclEntry - [ ] [ ] DeleteNetworkInterface - [ ] [ ] DeletePlacementGroup - [ ] [ ] -DeleteRoute - [ ] [ ] -DeleteRouteTable - [ ] [ ] +DeleteRoute route ID del [X] [ ] +DeleteRouteTable rmrtab [X] [ ] DeleteSecurityGroup rmsg [X] [X] DeleteSnapshot rmsnap [X] [X] DeleteSpotDatafeedSubscription - [ ] [ ] @@ -94,7 +94,7 @@ DescribeRegions lsreg [X] [X] DescribeReservedInstances - [ ] [ ] DescribeReservedInstancesListings - [ ] [ ] DescribeReservedInstancesOfferings - [ ] [ ] -DescribeRouteTables - [ ] [ ] +DescribeRouteTables lsrtab [X] [ ] DescribeSecurityGroups lssg [X] [X] DescribeSnapshotAttribute lssattr [X] [X] DescribeSnapshots lssnap [X] [X] @@ -116,7 +116,7 @@ DetachVolume devol [X] [X] DetachVpnGateway - [ ] [ ] DisableVgwRoutePropagation - [ ] [ ] DisassociateAddress disasaddr [X] [X] -DisassociateRouteTable - [ ] [ ] +DisassociateRouteTable disasrtab [X] [ ] EnableVgwRoutePropagation - [ ] [ ] EnableVolumeIO - [ ] [ ] GetConsoleOutput dmesg [X] [X] @@ -138,7 +138,7 @@ RegisterImage - [ ] [ ] ReleaseAddress rmaddr [X] [X] ReplaceNetworkAclAssociation - [ ] [ ] ReplaceNetworkAclEntry - [ ] [ ] -ReplaceRoute - [ ] [ ] +ReplaceRoute route ID chg|replace [X] [ ] ReplaceRouteTableAssociation - [ ] [ ] ReportInstanceStatus - [ ] [ ] RequestSpotInstances - [ ] [ ] diff --git a/etc/Makefile.am b/etc/Makefile.am index dfb87cc..07e1d5b 100644 --- a/etc/Makefile.am +++ b/etc/Makefile.am @@ -21,10 +21,13 @@ FLNFILES=\ attach-internet-gateway.fln\ attach-volume.fln\ associate-address.fln\ + associate-route-table.fln\ copy-image.fln\ copy-snapshot.fln\ create-image.fln\ create-internet-gateway.fln\ + create-route.fln\ + create-route-table.fln\ create-security-group.fln\ create-snapshot.fln\ create-subnet.fln\ @@ -32,6 +35,8 @@ FLNFILES=\ create-volume.fln\ create-vpc.fln\ delete-internet-gateway.fln\ + delete-route.fln\ + delete-route-table.fln\ delete-security-group.fln\ delete-subnet.fln\ delete-snapshot.fln\ @@ -48,6 +53,7 @@ FLNFILES=\ describe-instance-status.fln\ describe-instances.fln\ describe-regions.fln\ + describe-route-tables.fln\ describe-security-groups.fln\ describe-snapshot-attribute.fln\ describe-snapshots.fln\ @@ -59,6 +65,7 @@ FLNFILES=\ detach-internet-gateway.fln\ detach-volume.fln\ disassociate-address.fln\ + disassociate-route-table.fln\ get-console-output.fln\ lsattr.fln\ modify-image-attribute.fln\ @@ -68,6 +75,8 @@ FLNFILES=\ modify-vpc-attribute.fln\ reboot-instances.fln\ release-address.fln\ + replace-route.fln\ + route.fln\ reset-snapshot-attribute.fln\ run-instances.fln\ sg.fln\ diff --git a/etc/associate-route-table.fln b/etc/associate-route-table.fln new file mode 100644 index 0000000..2bb2557 --- /dev/null +++ b/etc/associate-route-table.fln @@ -0,0 +1,19 @@ +/* This file is part of Eclat. + Copyright (C) 2012-2015 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 (.AssociateRouteTableResponse.associationId) { + print(last, "\n"); +} diff --git a/etc/create-route-table.fln b/etc/create-route-table.fln new file mode 100644 index 0000000..a669c0d --- /dev/null +++ b/etc/create-route-table.fln @@ -0,0 +1,28 @@ +/* This file is part of Eclat. + Copyright (C) 2012-2015 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 (.CreateRouteTableResponse.routeTable) { + let tab = .CreateRouteTableResponse.routeTable; + if (empty(tab.routeSet)) { + print(tab.routeTableId, "\t", tab.vpcId, "\n"); + } else { + for (rs in tab.routeSet.item) { + print(tab.routeTableId, "\t", tab.vpcId, "\t", + rs.destinationCidrBlock, "\t", rs.gatewayId, "\t", + rs.state, "\n"); + } + } +} diff --git a/etc/create-route.fln b/etc/create-route.fln new file mode 100644 index 0000000..70e8bed --- /dev/null +++ b/etc/create-route.fln @@ -0,0 +1,22 @@ +/* This file is part of Eclat. + Copyright (C) 2012-2015 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 (.CreateRouteResponse.return) { + if (!.CreateRouteResponse.return[true]) { + error("Return: ",.CreateRouteResponse.return,"\n"); + exit(1); + } +} diff --git a/etc/delete-route-table.fln b/etc/delete-route-table.fln new file mode 100644 index 0000000..4b20b7d --- /dev/null +++ b/etc/delete-route-table.fln @@ -0,0 +1,22 @@ +/* This file is part of Eclat. + Copyright (C) 2012-2015 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 (.DeleteRouteTableResponse.return) { + if (!.DeleteRouteTableResponse.return[true]) { + error("Return: ",.DeleteRouteTableResponse.return,"\n"); + exit(1); + } +} diff --git a/etc/delete-route.fln b/etc/delete-route.fln new file mode 100644 index 0000000..666b425 --- /dev/null +++ b/etc/delete-route.fln @@ -0,0 +1,22 @@ +/* This file is part of Eclat. + Copyright (C) 2012-2015 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 (.DeleteRouteResponse.return) { + if (!.DeleteRouteResponse.return[true]) { + error("Return: ",.DeleteRouteResponse.return,"\n"); + exit(1); + } +} diff --git a/etc/describe-route-tables.fln b/etc/describe-route-tables.fln new file mode 100644 index 0000000..5004416 --- /dev/null +++ b/etc/describe-route-tables.fln @@ -0,0 +1,41 @@ +/* This file is part of Eclat. + Copyright (C) 2012-2015 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 (.DescribeRouteTablesResponse.routeTableSet) { + let rts = .DescribeRouteTablesResponse.routeTableSet; + for (routetab in rts.item) { + for (route in routetab.routeSet.item) { + print(routetab.routeTableId, "\t", routetab.vpcId, "\t", + "R", "\t", + route.destinationCidrBlock, "\t", + route.gatewayId, "\t", + route.state, "\t", + route.origin, "\n"); + } + } + for (routetab in rts.item) { + for (assoc in routetab.associationSet.item) { + if (assoc.subnetId) { + print(routetab.routeTableId, "\t", routetab.vpcId, "\t", + "A", "\t", + assoc.routeTableAssociationId, "\t", + assoc.routeTableId, "\t", + assoc.subnetId, "\t", + assoc.main, "\n"); + } + } + } +} diff --git a/etc/disassociate-route-table.fln b/etc/disassociate-route-table.fln new file mode 100644 index 0000000..bab6087 --- /dev/null +++ b/etc/disassociate-route-table.fln @@ -0,0 +1,20 @@ +/* This file is part of Eclat. + Copyright (C) 2012-2015 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 (.DisassociateRouteTableResponse.return) { + if (!.DisassociateRouteTableResponse.return[true]) + error("Return: ",.DisassociateRouteTableResponse.return,"\n"); +} diff --git a/etc/replace-route.fln b/etc/replace-route.fln new file mode 100644 index 0000000..95aea1e --- /dev/null +++ b/etc/replace-route.fln @@ -0,0 +1,22 @@ +/* This file is part of Eclat. + Copyright (C) 2012-2015 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 (.ReplaceRouteResponse.return) { + if (!.ReplaceRouteResponse.return[true]) { + error("Return: ",.ReplaceRouteResponse.return,"\n"); + exit(1); + } +} diff --git a/etc/route.fln b/etc/route.fln new file mode 100644 index 0000000..e5f0983 --- /dev/null +++ b/etc/route.fln @@ -0,0 +1,33 @@ +/* This file is part of Eclat. + Copyright (C) 2012-2015 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 (.CreateRouteResponse.return) { + if (!.CreateRouteResponse.return[true]) { + error("Return: ",.CreateRouteResponse.return,"\n"); + exit(1); + } +} else if (.DeleteRouteResponse.return) { + if (!.DeleteRouteResponse.return[true]) { + error("Return: ",.DeleteRouteResponse.return,"\n"); + exit(1); + } +} else if (.ReplaceRouteResponse.return) { + if (!.ReplaceRouteResponse.return[true]) { + error("Return: ",.ReplaceRouteResponse.return,"\n"); + exit(1); + } +} + diff --git a/src/Makefile.am b/src/Makefile.am index eb20de1..f772c79 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -63,6 +63,7 @@ eclat_SOURCES=\ rmsnap.c\ rmvol.c\ rmvpc.c\ + routetable.c\ setiattr.c\ sg.c\ sg.h\ diff --git a/src/eclat.c b/src/eclat.c index ae3b326..8d4838b 100644 --- a/src/eclat.c +++ b/src/eclat.c @@ -50,11 +50,13 @@ FILE *xml_dump_file; static char *categories[] = { - "main", - "cfgram", - "cflex", - "conf", - "curl", + [ECLAT_DEBCAT_MAIN] = "main", + [ECLAT_DEBCAT_CFGRAM] = "cfgram", + [ECLAT_DEBCAT_CFLEX] = "cflex", + [ECLAT_DEBCAT_CONF] = "conf", + [ECLAT_DEBCAT_CURL] = "curl", + [ECLAT_DEBCAT_FORLAN] = "forlan", + [ECLAT_DEBCAT_DUMP] = "dump" }; static void @@ -192,6 +194,17 @@ struct eclat_command cmdtab[] = { eclat_modify_subnet_attribute, CMD_MOD }, { "rmsubnet", "delete-subnet", "DeleteSubnet", eclat_delete_subnet, CMD_MOD|CMD_DESTR }, + { "mkrtab", "create-route-table", "CreateRouteTable", + eclat_create_route_table, CMD_MOD }, + { "rmrtab", "delete-route-table", "DeleteRouteTable", + eclat_delete_route_table, CMD_MOD|CMD_DESTR }, + { "lsrtab", "describe-route-tables", "DescribeRouteTables", + eclat_describe_route_tables }, + { "assocrtab", "associate-route-table", "AssociateRouteTable", + eclat_associate_route_table, CMD_MOD }, + { "disasrtab", "disassociate-route-table", "DisassociateRouteTable", + eclat_disassociate_route_table, CMD_MOD }, + { "route", NULL, NULL, eclat_route }, }; size_t cmdcnt = sizeof(cmdtab) / sizeof(cmdtab[0]); diff --git a/src/eclat.h b/src/eclat.h index c81558d..fcd9f13 100644 --- a/src/eclat.h +++ b/src/eclat.h @@ -38,6 +38,7 @@ #define ECLAT_DEBCAT_CONF 3 #define ECLAT_DEBCAT_CURL 4 #define ECLAT_DEBCAT_FORLAN 5 +#define ECLAT_DEBCAT_DUMP 6 enum authentication_provider { authp_undefined, @@ -186,6 +187,15 @@ int eclat_modify_subnet_attribute(eclat_command_env_t *env, int argc, char **argv); int eclat_delete_subnet(eclat_command_env_t *env, int argc, char **argv); +int eclat_create_route_table(eclat_command_env_t *env, int argc, char **argv); +int eclat_delete_route_table(eclat_command_env_t *env, int argc, char **argv); +int eclat_describe_route_tables(eclat_command_env_t *env, + int argc, char **argv); +int eclat_associate_route_table(eclat_command_env_t *env, + int argc, char **argv); +int eclat_disassociate_route_table(eclat_command_env_t *env, + int argc, char **argv); +int eclat_route(eclat_command_env_t *env, int argc, char **argv); int eclat_create_security_group(eclat_command_env_t *env, int argc, char **argv); @@ -47,7 +47,8 @@ write_callback(void *ptr, size_t size, size_t nmemb, void *data) int line = XML_GetCurrentLineNumber(parser); int column = XML_GetCurrentColumnNumber(parser); - if (debug_level(ECLAT_DEBCAT_MAIN) >= 10) + if (debug_level(ECLAT_DEBCAT_MAIN) >= 10 + || debug_level(ECLAT_DEBCAT_DUMP)) dumpxml(ptr, realsize); status = XML_Parse(parser, ptr, realsize, 0); diff --git a/src/routetable.c b/src/routetable.c new file mode 100644 index 0000000..05d4be3 --- /dev/null +++ b/src/routetable.c @@ -0,0 +1,220 @@ +/* This file is part of Eclat. + Copyright (C) 2012-2015 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_create_route_table(eclat_command_env_t *env, int argc, char **argv) +{ + int i; + struct ec2_request *q = env->request; + generic_proginfo->args_doc = "VPC-ID"; + generic_parse_options(env->cmd, + "create route table", + argc, argv, &i); + argc -= i; + argv += i; + if (argc != 1) + die(EX_USAGE, "wrong number of arguments"); + translate_ids(1, argv, MAP_VPC); + eclat_request_add_param(q, "VpcId", argv[0]); + return 0; +} + +int +eclat_delete_route_table(eclat_command_env_t *env, int argc, char **argv) +{ + int i; + struct ec2_request *q = env->request; + + generic_proginfo->args_doc = "RTAB-ID"; + generic_parse_options(env->cmd, + "delete route table", + argc, argv, &i); + argv += i; + argc -= i; + + if (argc != 1) + die(EX_USAGE, "wrong number of arguments"); + +// translate_ids(1, argv, MAP_ROUTE_TABLE); + eclat_request_add_param(q, "RouteTableId", argv[0]); + + return 0; +} + +static struct filter_descr rtab_filters[] = { + { "association.route-table-association-id", FILTER_STRING }, + { "association.route-table-id", FILTER_STRING }, + { "association.subnet-id", FILTER_STRING }, + { "association.main", FILTER_BOOL }, + { "route-table-id", FILTER_STRING }, + { "route.destination-cidr-block", FILTER_STRING }, + { "route.destination-prefix-list-id", FILTER_STRING }, + { "route.gateway-id", FILTER_STRING }, + { "route.instance-id", FILTER_STRING }, + { "route.origin", FILTER_STRING }, + { "route.state", FILTER_STRING }, + { "route.vpc-peering-connection-id", FILTER_STRING }, + { "tag-key", FILTER_STRING }, + { "tag-value", FILTER_STRING }, + { "tag:<KEY>", FILTER_STRING }, + { "vpc-id", FILTER_STRING }, + { NULL } +}; + +int +eclat_describe_route_tables(eclat_command_env_t *env, + int argc, char **argv) +{ + int i; + + available_filters = rtab_filters; + generic_proginfo->print_help_hook = list_filters; + generic_proginfo->args_doc = "[FILTER...] [ID...]"; + generic_parse_options(env->cmd, + "describe route tables", + argc, argv, &i); + argv += i; + argc -= i; + //FIXME: translate_ids(argc, argv, MAP_ROUTE_TABLE); + + describe_request_create(env, argc, argv, "RouteTableId"); + return 0; +} + +int +eclat_associate_route_table(eclat_command_env_t *env, + int argc, char **argv) +{ + int i; + struct ec2_request *q = env->request; + + generic_proginfo->args_doc = "RTAB-ID SUBNET-ID"; + generic_parse_options(env->cmd, + "associate a subnet with a route table", + argc, argv, &i); + argv += i; + argc -= i; + if (argc != 2) + die(EX_USAGE, "wrong number of arguments"); + +/*FIXME: + translate_ids(1, argv, MAP_ROUTE_TABLE); + translate_ids(1, argv+1, MAP_SUBNET); +*/ + + eclat_request_add_param(q, "RouteTableId", argv[0]); + eclat_request_add_param(q, "SubnetId", argv[1]); + + return 0; +} + +int +eclat_disassociate_route_table(eclat_command_env_t *env, + int argc, char **argv) +{ + int i; + struct ec2_request *q = env->request; + + generic_proginfo->args_doc = "RTBASSOC-ID"; + generic_parse_options(env->cmd, + "disassociate a subnet from a route table", + argc, argv, &i); + argv += i; + argc -= i; + if (argc != 1) + die(EX_USAGE, "wrong number of arguments"); + eclat_request_add_param(q, "AssociationId", argv[0]); + return 0; +} + +static void +route_create_request(struct ec2_request *req, int argc, char **argv) +{ + char const *id; + static struct idtab { + char *name; + char *id; + } idtab[] = { + { "gw", "GatewayId" }, + { "inst", "InstanceId" }, + { "if", "NetworkInterfaceId" }, + { "peer", "VpcPeeringConnectionId" }, + { NULL } + }; + struct idtab *p; + + if (argc != 2) + die(EX_USAGE, "wrong number of arguments"); + id = argv[0]; + + for (p = idtab; p->name; p++) + if (strcmp (id, p->name) == 0) { + id = p->id; + break; + } + + eclat_request_add_param(req, id, argv[1]); +} + +int +eclat_route(eclat_command_env_t *env, int argc, char **argv) +{ + int i; + struct ec2_request *q = env->request; + char *command; + char *rtb_id; + char *op; + char *cidr; + + generic_proginfo->args_doc = "RTB-ID OP CIDR [DEST ID]"; + generic_parse_options(env->cmd, + "manipulate the route table", + argc, argv, &i); + argv += i; + argc -= i; + + if (argc < 3) + die(EX_USAGE, "wrong number of arguments"); + //FIXME: translate_ids(1, argv, MAP_ROUTE_TABLE); + + rtb_id = argv[0]; + op = argv[1]; + cidr = argv[2]; + + argc -= 3; + argv += 3; + + if (strcmp(op, "add") == 0) { + command = "CreateRoute"; + route_create_request(q, argc, argv); + } else if (strcmp(op, "del") == 0) { + command = "DeleteRoute"; + if (argc != 0) + die(EX_USAGE, "wrong number of arguments"); + } else if (strcmp(op, "chg") == 0 || strcmp(op, "replace") == 0) { + command = "ReplaceRoute"; + route_create_request(q, argc, argv); + } else { + die(EX_USAGE, "unrecognized operation %s", op); + } + + eclat_request_add_param(q, "Action", command); + eclat_request_add_param(q, "RouteTableId", rtb_id); + eclat_request_add_param(q, "DestinationCidrBlock", cidr); + return 0; +} |