diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-11-18 23:25:04 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-11-18 23:25:04 +0200 |
commit | ed8a63afa3482a2036fd134e056a446a408b6357 (patch) | |
tree | 8209ee4131550a9ac0cd38dfcd25c22f8939266b /src | |
parent | 48e8aede6696c9b26a1bb1fd92d50f838e8b3178 (diff) | |
download | eclat-ed8a63afa3482a2036fd134e056a446a408b6357.tar.gz eclat-ed8a63afa3482a2036fd134e056a446a408b6357.tar.bz2 |
Implement VPC and Internet Gateway commands.
New commands: lsvpc, lsvpcattr, mkvpc,
setvpcattr, rmvpc, lsigw, mkigw, rmigw,
atigw, deigw.
* TODO: Update.
* doc/Makefile.inc: Add mkvpc manpage.
* etc/Makefile.am: Add create-vpc.fl and describe-vpcs.fln
* etc/describe-vpc-attribute.fln: New file.
* etc/describe-vpcs.fln: New file.
* src/Makefile.am: Add new files.
* src/igw.c: New file.
* src/lsvpc.c: New file.
* src/mkvpc-cl.opt: New file.
* src/mkvpc.c: New file.
* src/rmvpc.c: New file.
* src/vpcattr.c: New file.
* src/eclat.c (cmdtab): Register new subcommands.
* src/eclat.h: Add new prototypes.
* src/mksg-cl.opt: New option: --internet-gateway, -g
* src/lsinst.c (parse_options): Define args_doc.
* src/lsreg.c (parse_options): Remove useless return.
* src/lstag-cl.opt: Likewise.
* src/mktags-cl.opt: Remove stray character.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 8 | ||||
-rw-r--r-- | src/eclat.c | 20 | ||||
-rw-r--r-- | src/eclat.h | 19 | ||||
-rw-r--r-- | src/igw.c | 133 | ||||
-rw-r--r-- | src/lsinst.c | 1 | ||||
-rw-r--r-- | src/lsreg.c | 6 | ||||
-rw-r--r-- | src/lstag-cl.opt | 9 | ||||
-rw-r--r-- | src/lsvpc.c | 59 | ||||
-rw-r--r-- | src/mksg-cl.opt | 2 | ||||
-rw-r--r-- | src/mktags-cl.opt | 10 | ||||
-rw-r--r-- | src/mkvpc-cl.opt | 36 | ||||
-rw-r--r-- | src/mkvpc.c | 38 | ||||
-rw-r--r-- | src/rmvpc.c | 40 | ||||
-rw-r--r-- | src/util.c | 2 | ||||
-rw-r--r-- | src/vpcattr.c | 96 |
15 files changed, 473 insertions, 6 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 7ec7c66..d46ad42 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -36,2 +36,3 @@ eclat_SOURCES=\ getconout.c\ + igw.c\ io.c\ @@ -50,2 +51,3 @@ eclat_SOURCES=\ lsvol.c\ + lsvpc.c\ lszon.c\ @@ -57,2 +59,3 @@ eclat_SOURCES=\ mkvol.c\ + mkvpc.c\ rmaddr.c\ @@ -61,2 +64,3 @@ eclat_SOURCES=\ rmvol.c\ + rmvpc.c\ setiattr.c\ @@ -66,3 +70,4 @@ eclat_SOURCES=\ startstop.c\ - util.c + util.c\ + vpcattr.c @@ -100,2 +105,3 @@ OPTFILES=\ mkvol-cl.opt\ + mkvpc-cl.opt\ rmaddr-cl.opt\ diff --git a/src/eclat.c b/src/eclat.c index 69efa8e..faba64a 100644 --- a/src/eclat.c +++ b/src/eclat.c @@ -166,2 +166,22 @@ struct eclat_command cmdtab[] = { eclat_modify_image_attribute, CMD_MOD }, + { "lsvpc", "describe-vpcs", "DescribeVpcs", + eclat_describe_vpcs }, + { "lsvpcattr", "describe-vpc-attribute", "DescribeVpcAttribute", + eclat_describe_vpc_attribute }, + { "mkvpc", "create-vpc", "CreateVpc", + eclat_create_vpc, CMD_MOD }, + { "setvpcattr", "modify-vpc-attribute", "ModifyVpcAttribute", + eclat_modify_vpc_attribute, CMD_MOD }, + { "rmvpc", "delete-vpc", "DeleteVpc", + eclat_delete_vpc, CMD_MOD|CMD_DESTR }, + { "lsigw", "describe-internet-gateways", "DescribeInternetGateways", + eclat_describe_internet_gateways }, + { "mkigw", "create-internet-gateway", "CreateInternetGateway", + eclat_create_internet_gateway, CMD_MOD }, + { "rmigw", "delete-internet-gateway", "DeleteInternetGateway", + eclat_delete_internet_gateway, CMD_MOD|CMD_DESTR }, + { "atigw", "attach-internet-gateway", "AttachInternetGateway", + eclat_attach_internet_gateway, CMD_MOD }, + { "deigw", "detach-internet-gateway", "DetachInternetGateway", + eclat_detach_internet_gateway, CMD_MOD|CMD_DESTR }, }; diff --git a/src/eclat.h b/src/eclat.h index 604ffdc..6897c15 100644 --- a/src/eclat.h +++ b/src/eclat.h @@ -165,2 +165,18 @@ int eclat_sg(eclat_command_env_t *env, int argc, char **argv); +int eclat_describe_vpcs(eclat_command_env_t *env, int argc, char **argv); +int eclat_describe_vpc_attribute(eclat_command_env_t *env, int argc, char **argv); +int eclat_modify_vpc_attribute(eclat_command_env_t *env, int argc, char **argv); +int eclat_delete_vpc(eclat_command_env_t *env, int argc, char **argv); + +int eclat_create_internet_gateway(eclat_command_env_t *env, + int argc, char **argv); +int eclat_delete_internet_gateway(eclat_command_env_t *env, + int argc, char **argv); +int eclat_describe_internet_gateways(eclat_command_env_t *env, + int argc, char **argv); +int eclat_attach_internet_gateway(eclat_command_env_t *env, + int argc, char **argv); +int eclat_detach_internet_gateway(eclat_command_env_t *env, + int argc, char **argv); + int eclat_create_security_group(eclat_command_env_t *env, @@ -176,2 +192,3 @@ int eclat_modify_image_attribute(eclat_command_env_t *env, int eclat_lsattr(eclat_command_env_t *env, int argc, char **argv); +int eclat_create_vpc(eclat_command_env_t *env, int argc, char **argv); @@ -230,2 +247,4 @@ int get_scr_cols(void); #define MAP_REG "reg" +#define MAP_VPC "VpcId" +#define MAP_IGW "InternetGatewayId" diff --git a/src/igw.c b/src/igw.c new file mode 100644 index 0000000..a0f6f48 --- /dev/null +++ b/src/igw.c @@ -0,0 +1,133 @@ +/* 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_internet_gateway(eclat_command_env_t *env, int argc, char **argv) +{ + int i; + struct ec2_request *q = env->request; + generic_proginfo->args_doc = NULL; + generic_parse_options(env->cmd, + "create internet gateway", + argc, argv, &i); + if (argc > i) + die(EX_USAGE, "wrong number of arguments"); + return 0; +} + +int +eclat_delete_internet_gateway(eclat_command_env_t *env, int argc, char **argv) +{ + int i; + struct ec2_request *q = env->request; + + generic_proginfo->args_doc = "IGW-ID"; + generic_parse_options(env->cmd, + "delete internet gateway", + argc, argv, &i); + argv += i; + argc -= i; + + if (argc != 1) + die(EX_USAGE, "wrong number of arguments"); + + translate_ids(1, argv, MAP_IGW); + eclat_request_add_param(q, "InternetGatewayId", argv[0]); + + return 0; +} + +static struct filter_descr filters[] = { + { "attachment.state", FILTER_STRING }, + { "attachment.vpc-id", FILTER_STRING }, + { "internet-gateway-id", FILTER_STRING }, + { "tag-key", FILTER_STRING }, + { "tag-value", FILTER_STRING }, + { "tag:<KEY>", FILTER_STRING }, + { NULL } +}; + +int +eclat_describe_internet_gateways(eclat_command_env_t *env, + int argc, char **argv) +{ + int i; + + available_filters = filters; + generic_proginfo->print_help_hook = list_filters; + generic_proginfo->args_doc = "[FILTER...] [ID...]"; + generic_parse_options(env->cmd, + "describe internet gateways", + argc, argv, &i); + argv += i; + argc -= i; + translate_ids(argc, argv, MAP_IGW); + + describe_request_create(env, argc, argv, "InternetGatewayId"); + return 0; +} + +int +eclat_attach_internet_gateway(eclat_command_env_t *env, + int argc, char **argv) +{ + int i; + struct ec2_request *q = env->request; + + generic_proginfo->args_doc = "IGW-ID VPC-ID"; + generic_parse_options(env->cmd, + "attach internet gateway to a VPC", + argc, argv, &i); + argv += i; + argc -= i; + if (argc != 2) + die(EX_USAGE, "wrong number of arguments"); + + translate_ids(1, argv, MAP_IGW); + translate_ids(1, argv+1, MAP_VPC); + + eclat_request_add_param(q, "InternetGatewayId", argv[0]); + eclat_request_add_param(q, "VpcId", argv[1]); + + return 0; +} + +int +eclat_detach_internet_gateway(eclat_command_env_t *env, + int argc, char **argv) +{ + int i; + struct ec2_request *q = env->request; + + generic_proginfo->args_doc = "IGW-ID VPC-ID"; + generic_parse_options(env->cmd, + "detach internet gateway from VPC", + argc, argv, &i); + argv += i; + argc -= i; + if (argc != 2) + die(EX_USAGE, "wrong number of arguments"); + + translate_ids(1, argv, MAP_IGW); + translate_ids(1, argv+1, MAP_VPC); + + eclat_request_add_param(q, "InternetGatewayId", argv[0]); + eclat_request_add_param(q, "VpcId", argv[1]); + + return 0; +} diff --git a/src/lsinst.c b/src/lsinst.c index 7c65495..79cc4ec 100644 --- a/src/lsinst.c +++ b/src/lsinst.c @@ -134,2 +134,3 @@ parse_options(struct eclat_command const *cmd, int argc, char *argv[], generic_proginfo->print_help_hook = list_filters; + generic_proginfo->args_doc = _("[FILTER...] [INST-ID...]"); return generic_parse_options(cmd, diff --git a/src/lsreg.c b/src/lsreg.c index 11c8203..78d3862 100644 --- a/src/lsreg.c +++ b/src/lsreg.c @@ -31,5 +31,5 @@ parse_options(struct eclat_command const *cmd, generic_proginfo->args_doc = "[REGION [REGION...]]"; - return generic_parse_options(cmd, - "List available regions", - argc, argv, index); + generic_parse_options(cmd, + "List available regions", + argc, argv, index); } diff --git a/src/lstag-cl.opt b/src/lstag-cl.opt index 1c0c1af..15cd6f3 100644 --- a/src/lstag-cl.opt +++ b/src/lstag-cl.opt @@ -78,2 +78,11 @@ END +OPTION(internet-gateway,g,[<ID>], + [<internet gateway ID>]) +BEGIN + struct resource *res = grecs_malloc(sizeof(*res)); + res->map = MAP_IGW; + res->resid = optarg; + grecs_list_append(reslist, res); +END + ECLAT_CL_END diff --git a/src/lsvpc.c b/src/lsvpc.c new file mode 100644 index 0000000..edd8a13 --- /dev/null +++ b/src/lsvpc.c @@ -0,0 +1,59 @@ +/* This file is part of Eclat. + Copyright (C) 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" + +static void +parse_options(struct eclat_command const *cmd, int argc, char *argv[], + int *index) +{ + static char *state_enum[] = { "pending", "available", NULL }; + static struct filter_descr filters[] = { + { "cidr", FILTER_STRING }, //FIXME: FILTER_CIDR + { "dhcp-options-id", FILTER_STRING }, + { "isDefault", FILTER_BOOL }, + { "state", FILTER_ENUM, state_enum }, + { "tag-key", FILTER_STRING }, + { "tag-value", FILTER_STRING }, + { "tag:<KEY>", FILTER_STRING }, + { "vpc-id", FILTER_STRING }, + { NULL } + }; + + available_filters = filters; + generic_proginfo->print_help_hook = list_filters; + generic_proginfo->args_doc = _("[FILTER...] [VPC-ID...]"); + return generic_parse_options(cmd, + "List VPCs", + argc, argv, index); +} + +int +eclat_describe_vpcs(eclat_command_env_t *env, int argc, char **argv) +{ + int i; + + parse_options(env->cmd, argc, argv, &i); + argv += i; + argc -= i; + translate_ids(argc, argv, MAP_VPC); + + describe_request_create(env, argc, argv, "VpcId"); + return 0; +} + + + diff --git a/src/mksg-cl.opt b/src/mksg-cl.opt index 474b2ae..6b09ca6 100644 --- a/src/mksg-cl.opt +++ b/src/mksg-cl.opt @@ -23,3 +23,3 @@ OPTION(vpc-id,i,[<ID>], [<VPC ID>]) -BEGINb +BEGIN vpcid = optarg; diff --git a/src/mktags-cl.opt b/src/mktags-cl.opt index 8cb0033..510835b 100644 --- a/src/mktags-cl.opt +++ b/src/mktags-cl.opt @@ -79,2 +79,12 @@ END +OPTION(internet-gateway,g,[<ID>], + [<internet gateway ID>]) +BEGIN + struct resource *res = grecs_malloc(sizeof(*res)); + res->map = MAP_IGW; + res->resid = optarg; + grecs_list_append(reslist, res); +END + + OPTION(from-file,T,[<FILE>], diff --git a/src/mkvpc-cl.opt b/src/mkvpc-cl.opt new file mode 100644 index 0000000..03611f0 --- /dev/null +++ b/src/mkvpc-cl.opt @@ -0,0 +1,36 @@ +/* This file is part of Eclat. + Copyright (C) 2013-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/>. */ + +static int vpc_dry_run; +static char *vpc_tenancy; + +ECLAT_CL_BEGIN([<create VPC>], + [<CIDR>]) + +OPTION(tenancy,t, + [<default|dedicated>], + [<instance tenancy>]) +BEGIN + vpc_tenancy = optarg; +END + +ECLAT_CL_END + +ECLAT_CL_PARSER(parse_options, [<int argc, char *argv[], int *index>],[< +{ + GETOPT(argc, argv, *index, exit(EX_USAGE)) +} +>]) diff --git a/src/mkvpc.c b/src/mkvpc.c new file mode 100644 index 0000000..1c837ba --- /dev/null +++ b/src/mkvpc.c @@ -0,0 +1,38 @@ +/* This file is part of Eclat. + Copyright (C) 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" +#include "mkvpc-cl.h" + +int +eclat_create_vpc(eclat_command_env_t *env, int argc, char **argv) +{ + int i; + struct ec2_request *q = env->request; + + parse_options(env, argc, argv, &i); + argc -= i; + argv += i; + if (argc != 1) + die(EX_USAGE, "wrong number of arguments"); + + if (vpc_tenancy) + eclat_request_add_param(q, "InstanceTenancy", "true"); + eclat_request_add_param(q, "CidrBlock", argv[0]); + return 0; +} + + diff --git a/src/rmvpc.c b/src/rmvpc.c new file mode 100644 index 0000000..d1c0026 --- /dev/null +++ b/src/rmvpc.c @@ -0,0 +1,40 @@ +/* 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_delete_vpc(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, + "delete the VPC", + argc, argv, &i); + argv += i; + argc -= 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; +} + @@ -167,3 +167,3 @@ void describe_request_update(eclat_command_env_t *env, int argc, char **argv, - const char *uparm, int n_in, int *n_out) + const char *uparm, int n_in, int *n_out) { diff --git a/src/vpcattr.c b/src/vpcattr.c new file mode 100644 index 0000000..1896ee1 --- /dev/null +++ b/src/vpcattr.c @@ -0,0 +1,96 @@ +/* This file is part of Eclat. + Copyright (C) 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_describe_vpc_attribute(eclat_command_env_t *env, int argc, char **argv) +{ + int i; + struct ec2_request *q = env->request; + const char *attrname; + static char *attrs[] = { + "enableDnsSupport", + "enableDnsHostnames", + NULL + }; + + generic_proginfo->args_doc = "VPC-ID [ATTR]"; + available_attrs = attrs; + generic_proginfo->print_help_hook = list_attrs; + generic_parse_options(env->cmd, + "describe VPC attributes", + argc, argv, &i); + argv += i; + argc -= i; + + switch (argc) { + default: + die(EX_USAGE, "wrong number of arguments"); + case 2: + attrname = canonattrname(attrs, argv[1], NULL, NULL); + if (!attrname) + die(EX_USAGE, "unrecognized attribute name"); + break; + case 1: + attrname = attrs[0]; + } + + translate_ids(1, argv, MAP_VPC); + eclat_request_add_param(q, "VpcId", argv[0]); + if (attrname) + eclat_request_add_param(q, "Attribute", attrname); + return 0; +} + +int +eclat_modify_vpc_attribute(eclat_command_env_t *env, int argc, char **argv) +{ + int i; + struct ec2_request *q = env->request; + const char *attrname; + char *bufptr = NULL; + size_t bufsize = 0; + static char *attrs[] = { + "EnableDnsSupport", + "EnableDnsHostnames", + NULL + }; + + + generic_proginfo->args_doc = "VPC-ID ATTR VALUE"; + available_attrs = attrs; + generic_proginfo->print_help_hook = list_attrs; + generic_parse_options(env->cmd, + "modify VPC attribute", + argc, argv, &i); + argv += i; + argc -= i; + + if (argc != 3) + die(EX_USAGE, "wrong number of arguments"); + attrname = canonattrname(attrs, argv[1], NULL, NULL); + if (!attrname) + die(EX_USAGE, "unrecognized attribute name"); + + translate_ids(1, argv, MAP_VPC); + eclat_request_add_param(q, "VpcId", argv[0]); + grecs_asprintf(&bufptr, &bufsize, "%s.Value", attrname); + eclat_request_add_param(q, bufptr, argv[2]); + free(bufptr); + return 0; +} + |