aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-12-19 22:54:20 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2013-12-19 23:03:45 +0200
commit8d43103165e7e2f16c10d0592e5a51d86dac01ed (patch)
treec479c34f16e8a1d989fb95af462e47c318565cd8 /src
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 (limited to 'src')
-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
11 files changed, 178 insertions, 22 deletions
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
--- /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
--- /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
--- /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
--- /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
--- /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.