1 /* This file is part of Eclat.
2 Copyright (C) 2012-2018 Sergey Poznyakoff.
3
4 Eclat is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8
9 Eclat is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
16
17 #include "eclat.h"
18
19 #include "mksubnet-cl.h"
20
21 int
eclat_create_subnet(eclat_command_env_t * env,int argc,char ** argv)22 eclat_create_subnet(eclat_command_env_t *env, int argc, char **argv)
23 {
24 int i;
25 struct ec2_request *q = env->request;
26
27 mksubnet_parse_options(env, argc, argv, &i);
28 argc -= i;
29 argv += i;
30 if (argc != 2)
31 die(EX_USAGE, "wrong number of arguments");
32
33 eclat_request_add_param(q, "CidrBlock", argv[0]);
34 eclat_request_add_param(q, "VpcId", argv[1]);
35 if (zone)
36 eclat_request_add_param(q, "AvailabilityZone", zone);
37 return 0;
38 }
39
40 static char *subnet_states[] = {
41 "pending",
42 "available",
43 NULL
44 };
45 static struct filter_descr filters[] = {
46 { "availabilityZone", FILTER_STRING },
47 { "availability-zone", FILTER_STRING },
48 { "available-ip-address-count", FILTER_INT },
49 { "cidrBlock", FILTER_STRING },
50 { "defaultForAz", FILTER_BOOL },
51 { "default-for-az", FILTER_STRING },
52 { "state", FILTER_ENUM, subnet_states },
53 { "subnet-id", FILTER_STRING },
54 { "vpc-id", FILTER_STRING },
55 { "tag-key", FILTER_STRING },
56 { "tag-value", FILTER_STRING },
57 { "tag:<KEY>", FILTER_STRING },
58 { NULL }
59 };
60
61 int
eclat_describe_subnets(eclat_command_env_t * env,int argc,char ** argv)62 eclat_describe_subnets(eclat_command_env_t *env,
63 int argc, char **argv)
64 {
65 int i;
66
67 available_filters = filters;
68 generic_proginfo->print_help_hook = list_filters;
69 generic_proginfo->args_doc = "[FILTER...] [ID...]";
70 generic_parse_options(env->cmd,
71 "describe subnets",
72 argc, argv, &i);
73 argv += i;
74 argc -= i;
75 translate_ids(argc, argv, MAP_SUBNET);
76
77 describe_request_create(env, argc, argv, "SubnetId");
78 return 0;
79 }
80
81 int
eclat_modify_subnet_attribute(eclat_command_env_t * env,int argc,char ** argv)82 eclat_modify_subnet_attribute(eclat_command_env_t *env, int argc, char **argv)
83 {
84 int i;
85 struct ec2_request *q = env->request;
86 const char *attrname;
87 char *bufptr = NULL;
88 size_t bufsize = 0;
89 static char *attrs[] = {
90 "MapPublicIpOnLaunch"
91 };
92
93 generic_proginfo->args_doc = "SUBNET-ID ATTR VALUE";
94 available_attrs = attrs;
95 generic_proginfo->print_help_hook = list_attrs;
96 generic_parse_options(env->cmd,
97 "modify VPC attribute",
98 argc, argv, &i);
99 argv += i;
100 argc -= i;
101
102 if (argc != 3)
103 die(EX_USAGE, "wrong number of arguments");
104
105 attrname = canonattrname(attrs, argv[1], NULL, NULL);
106 if (!attrname)
107 die(EX_USAGE, "unrecognized attribute name");
108
109 translate_ids(1, argv, MAP_SUBNET);
110 eclat_request_add_param(q, "SubnetId", argv[0]);
111 grecs_asprintf(&bufptr, &bufsize, "%s.Value", attrname);
112 eclat_request_add_param(q, bufptr, argv[2]);
113 free(bufptr);
114 return 0;
115 }
116
117 int
eclat_delete_subnet(eclat_command_env_t * env,int argc,char ** argv)118 eclat_delete_subnet(eclat_command_env_t *env, int argc, char **argv)
119 {
120 int i;
121 struct ec2_request *q = env->request;
122
123 generic_proginfo->args_doc = "SUBNET-ID";
124 generic_parse_options(env->cmd,
125 "delete internet gateway",
126 argc, argv, &i);
127 argv += i;
128 argc -= i;
129
130 if (argc != 1)
131 die(EX_USAGE, "wrong number of arguments");
132
133 translate_ids(1, argv, MAP_SUBNET);
134 eclat_request_add_param(q, "SubnetId", argv[0]);
135
136 return 0;
137 }
138