summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2013-12-19 20:54:20 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2013-12-19 21:03:45 (GMT)
commit8d43103165e7e2f16c10d0592e5a51d86dac01ed (patch) (side-by-side diff)
treec479c34f16e8a1d989fb95af462e47c318565cd8
parent2a69cacdfe3f43c61c65ea4359c821236b7f141c (diff)
downloadeclat-8d43103165e7e2f16c10d0592e5a51d86dac01ed.tar.gz
eclat-8d43103165e7e2f16c10d0592e5a51d86dac01ed.tar.bz2
Implement security group creation and deletion.
* doc/eclat-lssg.1: New file. * doc/eclat-sg.1: New file. * doc/Makefile.inc: Add new files. * etc/create-security-group.fln: New file. * etc/delete-security-group.fln: New file. * etc/Makefile.am: Add new files. * src/mksg-cl.opt: New file. * src/mksg.c: New file. * src/rmsg-cl.opt: New file. * src/rmsg.c: New file. * src/sg.h: New file. * src/Makefile.am: Add new files. * src/eclat.c (cmdtab): New commands "mksg" and "rmsg". * src/eclat.h (eclat_create_security_group) (eclat_delete_security_group): New protos. * src/lssg.c: Include sg.h. Use groupkw instead of the static rt[], which is removed. * src/sg-cl.opt: Use groupkw * src/sg.c (groupkw): New global. * TODO: Update.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--TODO4
-rw-r--r--doc/Makefile.inc38
-rw-r--r--doc/eclat-lssg.18
-rw-r--r--doc/eclat-sg.16
-rw-r--r--etc/Makefile.am2
-rw-r--r--etc/create-security-group.fln23
-rw-r--r--etc/delete-security-group.fln22
-rw-r--r--src/Makefile.am5
-rw-r--r--src/eclat.c4
-rw-r--r--src/eclat.h6
-rw-r--r--src/lssg.c12
-rw-r--r--src/mksg-cl.opt34
-rw-r--r--src/mksg.c38
-rw-r--r--src/rmsg-cl.opt35
-rw-r--r--src/rmsg.c36
-rw-r--r--src/sg-cl.opt10
-rw-r--r--src/sg.c11
-rw-r--r--src/sg.h9
18 files changed, 256 insertions, 47 deletions
diff --git a/TODO b/TODO
index c8182b6..bd7ec6a 100644
--- a/TODO
+++ b/TODO
@@ -41,7 +41,7 @@ CreatePlacementGroup - [ ] [ ]
CreateReservedInstancesListing - [ ] [ ]
CreateRoute - [ ] [ ]
CreateRouteTable - [ ] [ ]
-CreateSecurityGroup - [ ] [ ]
+CreateSecurityGroup mksg [X] [X]
CreateSnapshot mksnap [X] [X]
CreateSpotDatafeedSubscription - [ ] [ ]
CreateSubnet - [ ] [ ]
@@ -61,7 +61,7 @@ DeleteNetworkInterface - [ ] [ ]
DeletePlacementGroup - [ ] [ ]
DeleteRoute - [ ] [ ]
DeleteRouteTable - [ ] [ ]
-DeleteSecurityGroup - [ ] [ ]
+DeleteSecurityGroup rmsg [X] [X]
DeleteSnapshot rmsnap [X] [X]
DeleteSpotDatafeedSubscription - [ ] [ ]
DeleteSubnet - [ ] [ ]
diff --git a/doc/Makefile.inc b/doc/Makefile.inc
index 4c10f82..0fa843f 100644
--- a/doc/Makefile.inc
+++ b/doc/Makefile.inc
@@ -20,42 +20,44 @@
MANPAGES1=\
eclat.1\
- eclat-mkaddr.1\
eclat-assocaddr.1\
eclat-atvol.1\
eclat-clrsattr.1\
+ eclat-conmesg.1\
eclat-cpimg.1\
eclat-cpsnap.1\
- eclat-mkinst.1\
- eclat-mkimg.1\
- eclat-mksnap.1\
- eclat-mktag.1\
- eclat-mkvol.1\
- eclat-rmsnap.1\
- eclat-rmtag.1\
eclat-deimg.1\
+ eclat-devol.1\
+ eclat-disasaddr.1\
eclat-lsaddr.1\
- eclat-lszon.1\
- eclat-lsimg.1\
eclat-lsiattr.1\
- eclat-lsistat.1\
+ eclat-lsimg.1\
eclat-lsinst.1\
+ eclat-lsistat.1\
eclat-lsreg.1\
- eclat-lssg.1\
eclat-lssattr.1\
+ eclat-lssg.1\
eclat-lssnap.1\
eclat-lstag.1\
eclat-lsvol.1\
- eclat-devol.1\
- eclat-disasaddr.1\
+ eclat-lszon.1\
+ eclat-mkaddr.1\
+ eclat-mkimg.1\
+ eclat-mkinst.1\
+ eclat-mksg.1\
+ eclat-mksnap.1\
+ eclat-mktag.1\
+ eclat-mkvol.1\
+ eclat-reboot.1\
+ eclat-rmaddr.1\
+ eclat-rmsg.1\
+ eclat-rmsnap.1\
+ eclat-rmtag.1\
eclat-setiattr.1\
eclat-setsattr.1\
eclat-sg.1\
- eclat-conmesg.1\
eclat-start.1\
- eclat-stop.1\
- eclat-reboot.1\
- eclat-rmaddr.1
+ eclat-stop.1
MANPAGES5=\
eclat.conf.5
diff --git a/doc/eclat-lssg.1 b/doc/eclat-lssg.1
index 69c31c9..50ce425 100644
--- a/doc/eclat-lssg.1
+++ b/doc/eclat-lssg.1
@@ -13,13 +13,13 @@
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with Eclat. If not, see <http://www.gnu.org/licenses/>.
-.TH LSSEC 1 "December 16, 2013" "ECLAT" "Eclat User Reference"
+.TH LSSEC 1 "December 19, 2013" "ECLAT" "Eclat User Reference"
.SH NAME
eclat lssg, describe\-security\-groups \- return information about security groups
.SH SYNOPSIS
\fBeclat lssg\fR [\fB\-n\fR] [\fB\-\-name\fR]\
[\fIFILTER\fR...] [\fIID\fR]
-
+.br
\fBeclat lssg\fR \fB\-\-help\fR
.SH DESCRIPTION
This command returns information about security groups. By default,
@@ -109,7 +109,9 @@ Outgoing:
.EE
.SH "SEE ALSO"
.BR eclat (1),
-.BR eclat\-sg (1).
+.BR eclat\-sg (1),
+.BR eclat\-mksg (1),
+.BR eclat\-rmsg (1).
.SH AUTHORS
Sergey Poznyakoff
.SH "BUG REPORTS"
diff --git a/doc/eclat-sg.1 b/doc/eclat-sg.1
index 6e9e708..7dcac0f 100644
--- a/doc/eclat-sg.1
+++ b/doc/eclat-sg.1
@@ -13,7 +13,7 @@
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with Eclat. If not, see <http://www.gnu.org/licenses/>.
-.TH SG 1 "December 17, 2013" "ECLAT" "Eclat User Reference"
+.TH SG 1 "December 19, 2013" "ECLAT" "Eclat User Reference"
.SH NAME
eclat sg \- manipulate security groups
.SH SYNOPSIS
@@ -130,7 +130,9 @@ Give a terse help summary.
List command line syntax and available options.
.SH "SEE ALSO"
.BR eclat (1),
-.BR eclat\-lssg (1).
+.BR eclat\-lssg (1),
+.BR eclat\-mksg (1),
+.BR eclat\-rmsg (1).
.SH AUTHORS
Sergey Poznyakoff
.SH "BUG REPORTS"
diff --git a/etc/Makefile.am b/etc/Makefile.am
index caa780c..c62369b 100644
--- a/etc/Makefile.am
+++ b/etc/Makefile.am
@@ -23,9 +23,11 @@ FLNFILES=\
copy-image.fln\
copy-snapshot.fln\
create-image.fln\
+ create-security-group.fln\
create-snapshot.fln\
create-tags.fln\
create-volume.fln\
+ delete-security-group.fln\
delete-snapshot.fln\
delete-tags.fln\
delete-volume.fln\
diff --git a/etc/create-security-group.fln b/etc/create-security-group.fln
new file mode 100644
index 0000000..06d021d
--- a/dev/null
+++ b/etc/create-security-group.fln
@@ -0,0 +1,23 @@
+/* This file is part of Eclat.
+ Copyright (C) 2012, 2013 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 (.CreateSecurityGroupResponse.return) {
+ if (!.CreateSecurityGroupResponse.return[true]) {
+ print("Return: ",.CreateSecurityGroupResponse.return,"\n");
+ exit(1);
+ } else
+ print(.CreateSecurityGroupResponse.groupId,"\n");
+}
diff --git a/etc/delete-security-group.fln b/etc/delete-security-group.fln
new file mode 100644
index 0000000..ca1c611
--- a/dev/null
+++ b/etc/delete-security-group.fln
@@ -0,0 +1,22 @@
+/* This file is part of Eclat.
+ Copyright (C) 2012, 2013 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 (.DeleteSecurityGroupResponse.return) {
+ if (!.DeleteSecurityGroupResponse.return[true]) {
+ print("Return: ",.DeleteSecurityGroupResponse.return,"\n");
+ exit(1);
+ }
+}
diff --git a/src/Makefile.am b/src/Makefile.am
index 6654f5c..9bc68d0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -50,14 +50,17 @@ eclat_SOURCES=\
lszon.c\
mkimg.c\
mkinst.c\
+ mksg.c\
mksnap.c\
mktags.c\
mkvol.c\
rmaddr.c\
+ rmsg.c\
rmsnap.c\
rmvol.c\
setiattr.c\
sg.c\
+ sg.h\
startstop.c\
util.c
@@ -86,9 +89,11 @@ OPTFILES=\
lstag-cl.opt\
mkimg-cl.opt\
mkinst-cl.opt\
+ mksg-cl.opt\
mktags-cl.opt\
mkvol-cl.opt\
rmaddr-cl.opt\
+ rmsg-cl.opt\
sg-cl.opt
eclat_SOURCES += $(OPTFILES:.opt=.h)
diff --git a/src/eclat.c b/src/eclat.c
index 0558fcd..a046eb9 100644
--- a/src/eclat.c
+++ b/src/eclat.c
@@ -150,6 +150,10 @@ struct eclat_command cmdtab[] = {
{ "lsattr", NULL, NULL,
eclat_lsattr, CMD_NOQRY },
{ "sg", NULL, NULL, eclat_sg },
+ { "mksg", "create-security-group", "CreateSecurityGroup",
+ eclat_create_security_group },
+ { "rmsg", "delete-security-group", "DeleteSecurityGroup",
+ eclat_delete_security_group }
};
size_t cmdcnt = sizeof(cmdtab) / sizeof(cmdtab[0]);
diff --git a/src/eclat.h b/src/eclat.h
index 03a0bdf..903e49e 100644
--- a/src/eclat.h
+++ b/src/eclat.h
@@ -144,6 +144,11 @@ int eclat_copy_image(eclat_command_env_t *env, int argc, char **argv);
int eclat_copy_snapshot(eclat_command_env_t *env, int argc, char **argv);
int eclat_sg(eclat_command_env_t *env, int argc, char **argv);
+int eclat_create_security_group(eclat_command_env_t *env,
+ int argc, char **argv);
+int eclat_delete_security_group(eclat_command_env_t *env,
+ int argc, char **argv);
+
int eclat_lsattr(eclat_command_env_t *env, int argc, char **argv);
char *region_to_endpoint(const char *region);
@@ -212,3 +217,4 @@ void set_command_confirmation(const char *name, enum eclat_confirm_mode cfmode,
grecs_locus_t *locus);
extern struct eclat_map_drv eclat_map_drv_ec2;
+
diff --git a/src/lssg.c b/src/lssg.c
index 039feb1..a4eef38 100644
--- a/src/lssg.c
+++ b/src/lssg.c
@@ -17,25 +17,19 @@
#include "eclat.h"
static int name_option;
#include "lssg-cl.h"
+#include "sg.h"
int
eclat_describe_security_groups(eclat_command_env_t *env, int argc, char **argv)
{
int i;
- static struct {
- char *resid;
- char *map;
- } rt[] = {
- { "GroupId", MAP_GROUPID },
- { "GroupName", MAP_GROUPNAME }
- };
parse_options(env, argc, argv, &i);
argv += i;
argc -= i;
- translate_ids(argc, argv, rt[name_option].map);
+ translate_ids(argc, argv, groupkw[name_option].map);
- describe_query_create(env, argc, argv, rt[name_option].resid);
+ describe_query_create(env, argc, argv, groupkw[name_option].resid);
return 0;
}
diff --git a/src/mksg-cl.opt b/src/mksg-cl.opt
new file mode 100644
index 0000000..1dd10b1
--- a/dev/null
+++ b/src/mksg-cl.opt
@@ -0,0 +1,34 @@
+/* This file is part of Eclat.
+ Copyright (C) 2013 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 char *vpcid;
+
+ECLAT_CL_BEGIN([<create EC2 security group>],
+ [<GROUPNAME DESCR>])
+
+OPTION(vpc-id,i,[<ID>],
+ [<VPC ID>])
+BEGINb
+ vpcid = 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/mksg.c b/src/mksg.c
new file mode 100644
index 0000000..dcffdd9
--- a/dev/null
+++ b/src/mksg.c
@@ -0,0 +1,38 @@
+/* This file is part of Eclat.
+ Copyright (C) 2013 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 "mksg-cl.h"
+
+int
+eclat_create_security_group(eclat_command_env_t *env, int argc, char **argv)
+{
+ int i;
+ struct ec2_query *q = env->query;
+
+ parse_options(env, argc, argv, &i);
+ argc -= i;
+ argv += i;
+ if (argc != 2)
+ die(EX_USAGE, "wrong number of arguments");
+
+ eclat_query_add_param(q, "GroupName", argv[0]);
+ eclat_query_add_param(q, "GroupDescription", argv[1]);
+ if (vpcid)
+ eclat_query_add_param(q, "VpcId", vpcid);
+ return 0;
+}
+
diff --git a/src/rmsg-cl.opt b/src/rmsg-cl.opt
new file mode 100644
index 0000000..2801b56
--- a/dev/null
+++ b/src/rmsg-cl.opt
@@ -0,0 +1,35 @@
+/* This file is part of Eclat.
+ Copyright (C) 2013 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 "sg.h"
+static int group_n = GROUP_ID;
+
+ECLAT_CL_BEGIN([<delete group>],
+ [<GROUPARG>])
+OPTION(name,n,,
+ [<the GROUPARG argument is a group name>])
+BEGIN
+ group_n = GROUP_NAME;
+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/rmsg.c b/src/rmsg.c
new file mode 100644
index 0000000..fff5902
--- a/dev/null
+++ b/src/rmsg.c
@@ -0,0 +1,36 @@
+/* This file is part of Eclat.
+ Copyright (C) 2012, 2013 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 "rmsg-cl.h"
+
+int
+eclat_delete_security_group(eclat_command_env_t *env, int argc, char **argv)
+{
+ int i;
+ struct ec2_query *q = env->query;
+
+ parse_options(env, argc, argv, &i);
+ argc -= i;
+ argv += i;
+ if (argc != 1)
+ die(EX_USAGE, "bad number of arguments");
+ translate_ids(1, &argv[0], groupkw[group_n].map);
+ eclat_query_add_param(q, groupkw[group_n].resid, argv[0]);
+ return 0;
+}
+
+
diff --git a/src/sg-cl.opt b/src/sg-cl.opt
index aa44095..433d705 100644
--- a/src/sg-cl.opt
+++ b/src/sg-cl.opt
@@ -49,7 +49,7 @@ OPTION(group-id,g,[<ID>],
[<source group ID>])
BEGIN
struct group_arg *g = grecs_malloc(sizeof(*g));
- translate_ids(1, &optarg, rt[GROUP_ID].map);
+ translate_ids(1, &optarg, groupkw[GROUP_ID].map);
g->type = GROUP_ID;
g->str = optarg;
g->usr = user;
@@ -62,7 +62,7 @@ OPTION(group-name,G,[<NAME>],
[<source group name>])
BEGIN
struct group_arg *g = grecs_malloc(sizeof(*g));
- translate_ids(1, &optarg, rt[GROUP_NAME].map);
+ translate_ids(1, &optarg, groupkw[GROUP_NAME].map);
g->type = GROUP_NAME;
g->str = optarg;
g->usr = user;
@@ -131,17 +131,17 @@ ECLAT_CL_PARSER(parse_options, [<int argc, char *argv[]>],[<
die(EX_USAGE, "bad number of arguments");
} else if (argc != 1)
die(EX_USAGE, "bad number of arguments");
- translate_ids(argc, argv, rt[dest_n].map);
+ translate_ids(argc, argv, groupkw[dest_n].map);
eclat_query_add_param(env->query, "Action", command);
if (list_option)
- describe_query_create(env, argc, argv, rt[dest_n].resid);
+ describe_query_create(env, argc, argv, groupkw[dest_n].resid);
else {
if (group_list || source_list || from_port || to_port || proto)
flush_rule();
if (rule_n == 1)
die(EX_USAGE, "no rules");
- eclat_query_add_param(query, rt[dest_n].resid, argv[0]);
+ eclat_query_add_param(query, groupkw[dest_n].resid, argv[0]);
}
}>])
diff --git a/src/sg.c b/src/sg.c
index 2fc0a9b..160851c 100644
--- a/src/sg.c
+++ b/src/sg.c
@@ -17,14 +17,9 @@
#include "eclat.h"
#include <arpa/inet.h>
#include <netdb.h>
+#include "sg.h"
-#define GROUP_ID 0
-#define GROUP_NAME 1
-
-static struct {
- char *resid;
- char *map;
-} rt[] = {
+struct groupkw groupkw[] = {
{ "GroupId", MAP_GROUPID },
{ "GroupName", MAP_GROUPNAME }
};
@@ -174,7 +169,7 @@ flush_rule()
grecs_asprintf(&bufptr, &bufsize,
"IpPermissions.%d.Groups.%d.%s",
rule_n, i,
- rt[a->type].resid);
+ groupkw[a->type].resid);
eclat_query_add_param(query, bufptr, a->str);
if (a->usr) {
grecs_asprintf(&bufptr, &bufsize,
diff --git a/src/sg.h b/src/sg.h
new file mode 100644
index 0000000..a406c51
--- a/dev/null
+++ b/src/sg.h
@@ -0,0 +1,9 @@
+struct groupkw {
+ char *resid;
+ char *map;
+};
+
+#define GROUP_ID 0
+#define GROUP_NAME 1
+
+extern struct groupkw groupkw[];

Return to:

Send suggestions and report system problems to the System administrator.