diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 5 | ||||
-rw-r--r-- | src/eclat.c | 6 | ||||
-rw-r--r-- | src/eclat.h | 7 | ||||
-rw-r--r-- | src/lsaattr.c | 63 | ||||
-rw-r--r-- | src/lsiattr.c | 8 | ||||
-rw-r--r-- | src/lssattr.c | 14 | ||||
-rw-r--r-- | src/setaattr-cl.opt | 55 | ||||
-rw-r--r-- | src/setaattr.c | 119 | ||||
-rw-r--r-- | src/setiattr.c | 18 | ||||
-rw-r--r-- | src/util.c | 18 |
10 files changed, 279 insertions, 34 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index d38794b..1c83ec2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -37,6 +37,7 @@ eclat_SOURCES=\ io.c\ lsaddr.c\ lsattr.c\ + lsaattr.c\ lsiattr.c\ lsimg.c\ lsinst.c\ @@ -61,6 +62,7 @@ eclat_SOURCES=\ setiattr.c\ sg.c\ sg.h\ + setaattr.c\ startstop.c\ util.c @@ -94,7 +96,8 @@ OPTFILES=\ mkvol-cl.opt\ rmaddr-cl.opt\ rmsg-cl.opt\ - sg-cl.opt + sg-cl.opt\ + setaattr-cl.opt eclat_SOURCES += $(OPTFILES:.opt=.h) diff --git a/src/eclat.c b/src/eclat.c index d028a25..3791573 100644 --- a/src/eclat.c +++ b/src/eclat.c @@ -153,7 +153,11 @@ struct eclat_command cmdtab[] = { { "mksg", "create-security-group", "CreateSecurityGroup", eclat_create_security_group }, { "rmsg", "delete-security-group", "DeleteSecurityGroup", - eclat_delete_security_group, CMD_MOD|CMD_DESTR } + eclat_delete_security_group, CMD_MOD|CMD_DESTR }, + { "lsaattr", "describe-image-attribute", "DescribeImageAttribute", + eclat_describe_image_attribute }, + { "setaattr", "modify-image-attribute", "ModifyImageAttribute", + eclat_modify_image_attribute, CMD_MOD }, }; size_t cmdcnt = sizeof(cmdtab) / sizeof(cmdtab[0]); diff --git a/src/eclat.h b/src/eclat.h index b3ab350..528ae95 100644 --- a/src/eclat.h +++ b/src/eclat.h @@ -149,6 +149,11 @@ int eclat_create_security_group(eclat_command_env_t *env, int eclat_delete_security_group(eclat_command_env_t *env, int argc, char **argv); +int eclat_describe_image_attribute(eclat_command_env_t *env, + int argc, char **argv); +int eclat_modify_image_attribute(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); @@ -186,6 +191,8 @@ void list_filters(FILE *fp); extern char **available_attrs; void list_attrs(FILE *fp); +char *canonattrname(char **attrs, const char *arg, char *delim, + size_t *plen); int get_scr_cols(void); diff --git a/src/lsaattr.c b/src/lsaattr.c new file mode 100644 index 0000000..9a9dbe2 --- /dev/null +++ b/src/lsaattr.c @@ -0,0 +1,63 @@ +/* This file is part of Eclat. + Copyright (C) 2012-2014 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 char *attrs[] = { + "description", + "blockDeviceMapping", + "launchPermission", + "productCodes", + "kernel", + "ramdisk", + "sriovNetSupport", + NULL +}; + +int +eclat_describe_image_attribute(eclat_command_env_t *env, int argc, char **argv) +{ + int i; + struct ec2_query *q = env->query; + const char *attrname; + + generic_proginfo->args_doc = "AMI-ID [ATTR]"; + available_attrs = attrs; + generic_proginfo->print_help_hook = list_attrs; + generic_parse_options(env->cmd, + "describe the attribute of an image", + 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_IMAGE); + eclat_query_add_param(q, "ImageId", argv[0]); + eclat_query_add_param(q, "Attribute", attrname); + return 0; +} + diff --git a/src/lsiattr.c b/src/lsiattr.c index e364c8f..8aaad36 100644 --- a/src/lsiattr.c +++ b/src/lsiattr.c @@ -37,7 +37,8 @@ eclat_describe_instance_attribute(eclat_command_env_t *env, int argc, char **arg { int i; struct ec2_query *q = env->query; - + char *attrname; + generic_proginfo->args_doc = "INST-ID ATTR"; available_attrs = attrs; generic_proginfo->print_help_hook = list_attrs; @@ -51,9 +52,12 @@ eclat_describe_instance_attribute(eclat_command_env_t *env, int argc, char **arg die(EX_USAGE, "wrong number of arguments"); translate_ids(1, argv, MAP_INSTANCE); + attrname = canonattrname(attrs, argv[1], NULL, NULL); + if (!attrname) + die(EX_USAGE, "unrecognized attribute name"); eclat_query_add_param(q, "InstanceId", argv[0]); - eclat_query_add_param(q, "Attribute", argv[1]); + eclat_query_add_param(q, "Attribute", attrname); return 0; } diff --git a/src/lssattr.c b/src/lssattr.c index 3a7f87a..ec7532e 100644 --- a/src/lssattr.c +++ b/src/lssattr.c @@ -22,18 +22,6 @@ static char *attrs[] = { NULL }; -static char * -canonattrname(const char *arg) -{ - int i; - - for (i = 0; attrs[i]; i++) { - if (strcasecmp(arg, attrs[i]) == 0) - return attrs[i]; - } - return NULL; -} - int eclat_describe_snapshot_attribute(eclat_command_env_t *env, int argc, char **argv) @@ -55,7 +43,7 @@ eclat_describe_snapshot_attribute(eclat_command_env_t *env, default: die(EX_USAGE, "wrong number of arguments"); case 2: - attrname = canonattrname(argv[1]); + attrname = canonattrname(attrs, argv[1], NULL, NULL); if (!attrname) die(EX_USAGE, "unrecognized attribute name"); break; diff --git a/src/setaattr-cl.opt b/src/setaattr-cl.opt new file mode 100644 index 0000000..fb011c8 --- /dev/null +++ b/src/setaattr-cl.opt @@ -0,0 +1,55 @@ +/* This file is part of Eclat. + Copyright (C) 2012-2014 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/>. */ + +OPTIONS_COMMAND_BEGIN("eclat", + [<>], + [<modify attributes of an image>], + [<AMI-ID ATTR [<[<[OPTION]>]>] VALUE...>], + [<gnu>], + [<noversion>], + [<nopermute>]) + +OPTION([<group-name>],g,, + [<next argument is a group name>]) +BEGIN + acctype = ACCTYPE_GROUP; +END + +OPTION([<user-id>],u,, + [<next argument is a user ID>]) +BEGIN + acctype = ACCTYPE_USERID; +END + +OPTION(add,a,, + [<add attribute>]) +BEGIN + action = ACT_ADD; +END + +OPTION(delete,d,, + [<delete attribute value>]) +BEGIN + action = ACT_DEL; +END + +ECLAT_CL_END + +ECLAT_CL_PARSER(parse_options, [<int argc, char *argv[], int *index>],[< +{ + optind = 1; + GETOPT(argc, argv, *index, exit(EX_USAGE)) +}>]) diff --git a/src/setaattr.c b/src/setaattr.c new file mode 100644 index 0000000..5365678 --- /dev/null +++ b/src/setaattr.c @@ -0,0 +1,119 @@ +/* This file is part of Eclat. + Copyright (C) 2012-2014 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" + +#define ACCTYPE_USERID 0 +#define ACCTYPE_GROUP 1 + +char *acct_string[] = { "UserId", "Group" }; + +#define ACT_ADD 0 +#define ACT_DEL 1 +char *action_string[] = { "Add", "Remove" }; + +int action = ACT_ADD; +int acctype = ACCTYPE_USERID; + +#include "setaattr-cl.h" + +static char *attrs[] = { + "description", + "LaunchPermission", + "ProductCode", + NULL +}; + +static char * +canonuserid(char *input) +{ + char *p, *q; + + for (p = q = input; *q; q++) { + if (strchr(" \t-", *q)) + continue; + *p++ = *q; + } + *p = 0; + return input; +} + +int +eclat_modify_image_attribute(eclat_command_env_t *env, + int argc, char **argv) +{ + int i; + struct ec2_query *q = env->query; + const char *attrname; + char *bufptr = NULL; + size_t bufsize = 0; + + available_attrs = attrs; + proginfo.print_help_hook = list_attrs; + + parse_options(env, argc, argv, &i); + argv += i; + argc -= i; + + if (argc < 3) + die(EX_USAGE, "wrong number of arguments"); + translate_ids(1, argv, MAP_IMAGE); + attrname = canonattrname(attrs, argv[1], NULL, NULL); + if (!attrname) + die(EX_USAGE, "unrecognized attribute name"); + + eclat_query_add_param(q, "ImageId", argv[0]); + + argv++; + argc--; + argv[0] = (char*) env->cmd->name; + + if (strcmp(attrname, "description") == 0) { + if (argc != 2) + die(EX_USAGE, "only one description is allowed"); + eclat_query_add_param(q, "Description.Value", argv[1]); + } else if (strcmp(attrname, "ProductCode") == 0) { + for (i = 1; i < argc; i++) { + grecs_asprintf(&bufptr, &bufsize, + "ProductCode.%d", + i); + eclat_query_add_param(q, bufptr, argv[i]); + } + } else { + int j = 1; + + while (argc) { + argv[0] = (char*) env->cmd->name; + parse_options(env, argc, argv, &i); + argv += i; + argc -= i; + + if (argc) { + grecs_asprintf(&bufptr, &bufsize, + "LaunchPermission.%s.%d.%s", + action_string[action], j++, + acct_string[acctype]); + eclat_query_add_param(q, bufptr, + canonuserid(argv[0])); + } + } + } + free(bufptr); + return 0; +} + + + diff --git a/src/setiattr.c b/src/setiattr.c index d7ecf9a..60687b7 100644 --- a/src/setiattr.c +++ b/src/setiattr.c @@ -30,22 +30,6 @@ static char *attrs[] = { NULL }; -static char * -canonattrname(const char *arg, size_t *plen) -{ - size_t len = strlen(arg); - int i; - - for (i = 0; attrs[i]; i++) { - size_t alen = strcspn(attrs[i], "."); - if (alen == len && strncasecmp(arg, attrs[i], len) == 0) { - *plen = len; - return attrs[i]; - } - } - return NULL; -} - static void list_mod_attrs(FILE *fp) { @@ -95,7 +79,7 @@ eclat_modify_instance_attribute(eclat_command_env_t *env, int argc, char **argv) translate_ids(1, argv, MAP_INSTANCE); eclat_query_add_param(q, "InstanceId", argv[0]); - canonattr = canonattrname(argv[1], &canonlen); + canonattr = canonattrname(attrs, argv[1], ".", &canonlen); if (!canonattr) die(EX_USAGE, "unrecognized attribute: %s", argv[1]); @@ -320,3 +320,21 @@ list_attrs(FILE *fp) fputc('\n', fp); } +char * +canonattrname(char **attrs, const char *arg, char *delim, size_t *plen) +{ + size_t len = strlen(arg); + int i; + + for (i = 0; attrs[i]; i++) { + size_t alen = delim ? strcspn(attrs[i], delim) + : strlen(attrs[i]); + if (alen == len && strncasecmp(arg, attrs[i], len) == 0) { + if (plen) + *plen = len; + return attrs[i]; + } + } + return NULL; +} + |