diff options
-rw-r--r-- | TODO | 8 | ||||
-rw-r--r-- | etc/Makefile.am | 3 | ||||
-rw-r--r-- | etc/describe-snapshot-attribute.fln | 28 | ||||
-rw-r--r-- | etc/modify-snapshot-attribute.fln | 22 | ||||
-rw-r--r-- | etc/reset-snapshot-attribute.fln | 22 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/dscrinstattr.c | 23 | ||||
-rw-r--r-- | src/dscrsnapattr.c | 175 | ||||
-rw-r--r-- | src/eclat.c | 6 | ||||
-rw-r--r-- | src/eclat.h | 13 | ||||
-rw-r--r-- | src/modinstattr.c | 4 | ||||
-rw-r--r-- | src/util.c | 25 |
12 files changed, 301 insertions, 29 deletions
@@ -93,7 +93,7 @@ DescribeReservedInstancesListings DSCRRSRVDINSTSLSTS [ ] [ ] DescribeReservedInstancesOfferings DSCRRSRVDINSTSOFRS [ ] [ ] DescribeRouteTables DSCRROUTTABS [ ] [ ] DescribeSecurityGroups DSCRSECGRPS [X] [X] -DescribeSnapshotAttribute DSCRSNAPATTR [ ] [ ] +DescribeSnapshotAttribute DSCRSNAPATTR [X] [ ] DescribeSnapshots DSCRSNAPS [X] [X] DescribeSpotDatafeedSubscription DSCRSPOTDFSSCR [ ] [ ] DescribeSpotInstanceRequests DSCRSPOTINSTREQS [ ] [ ] @@ -123,8 +123,8 @@ ImportVolume IMPVOL [ ] [ ] ModifyImageAttribute MODIMGATTR [ ] [ ] ModifyInstanceAttribute MODINSTATTR [X] [X] ModifyNetworkInterfaceAttribute MODNETIFATTR [ ] [ ] -ModifySnapshotAttribute MODSNAPATTR [ ] [ ] -ModifyVolumeAttribute MODVOLATTR [ ] [ ] +ModifySnapshotAttribute MODSNAPATTR [X] [ ] +ModifyVolumeAttribute MODVOLATTR [X] [ ] MonitorInstances MONINSTS [ ] [ ] PurchaseReservedInstancesOffering PURRSRVDINSTSOFR [ ] [ ] RebootInstances RBTINSTS [X] [X] @@ -139,7 +139,7 @@ RequestSpotInstances REQSPOTINSTS [ ] [ ] ResetImageAttribute RSTIMGATTR [ ] [ ] ResetInstanceAttribute RSTINSTATTR [ ] [ ] ResetNetworkInterfaceAttribute RSTNETIFATTR [ ] [ ] -ResetSnapshotAttribute RSTSNAPATTR [ ] [ ] +ResetSnapshotAttribute RSTSNAPATTR [X] [ ] RevokeSecurityGroupEgress RVKSECGRPEG [ ] [ ] RevokeSecurityGroupIngress RVKSECGRPIG [ ] [ ] RunInstances RUNINSTS [ ] [ ] diff --git a/etc/Makefile.am b/etc/Makefile.am index 6da6510..5ff4533 100644 --- a/etc/Makefile.am +++ b/etc/Makefile.am @@ -33,6 +33,7 @@ FLNFILES=\ describe-instances.fln\ describe-regions.fln\ describe-security-groups.fln\ + describe-snapshot-attribute.fln\ describe-snapshots.fln\ describe-tags.fln\ describe-volumes.fln\ @@ -40,8 +41,10 @@ FLNFILES=\ disassociate-address.fln\ get-console-output.fln\ modify-instance-attribute.fln\ + modify-snapshot-attribute.fln\ reboot-instances.fln\ release-address.fln\ + reset-snapshot-attribute.fln\ start-instances.fln\ stop-instances.fln diff --git a/etc/describe-snapshot-attribute.fln b/etc/describe-snapshot-attribute.fln new file mode 100644 index 0000000..0e71d38 --- /dev/null +++ b/etc/describe-snapshot-attribute.fln @@ -0,0 +1,28 @@ +/* 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/>. */ + +if (.DescribeSnapshotAttributeResponse) { + print(last.snapshotId); + if (.DescribeSnapshotAttributeResponse.createVolumePermission.item) { + for (var in .DescribeSnapshotAttributeResponse.createVolumePermission.item) { + if (var.userId) + print(" ", var.userId); + else if (var.group) + print(" g=", var.group); + } + } + print("\n"); +}
\ No newline at end of file diff --git a/etc/modify-snapshot-attribute.fln b/etc/modify-snapshot-attribute.fln new file mode 100644 index 0000000..6d00e7a --- /dev/null +++ b/etc/modify-snapshot-attribute.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 (.ModifySnapshotAttributeResponse.return) { + if (!.ModifySnapshotAttributeResponse.return[true]) { + error("Return: ",.ModifySnapshotAttributeResponse.return,"\n"); + exit(1); + } +} diff --git a/etc/reset-snapshot-attribute.fln b/etc/reset-snapshot-attribute.fln new file mode 100644 index 0000000..059ffed --- /dev/null +++ b/etc/reset-snapshot-attribute.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 (.ResetSnapshotAttributeResponse.return) { + if (!.ResetSnapshotAttributeResponse.return[true]) { + error("Return: ",.ResetSnapshotAttributeResponse.return,"\n"); + exit(1); + } +} diff --git a/src/Makefile.am b/src/Makefile.am index 0eba189..996f2d8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -33,6 +33,7 @@ eclat_SOURCES=\ dscraddrs.c\ dscrazs.c\ dscrsnap.c\ + dscrsnapattr.c\ dscrregs.c\ dscrtags.c\ dscrinstattr.c\ diff --git a/src/dscrinstattr.c b/src/dscrinstattr.c index 67b8bbf..d6d8b64 100644 --- a/src/dscrinstattr.c +++ b/src/dscrinstattr.c @@ -32,28 +32,6 @@ static char *attrs[] = { NULL }; -static void -list_attrs(FILE *fp) -{ - size_t ncols = get_scr_cols(); - int i, col, len; - char *delim = ""; - - fprintf(fp, "Available attributes are:\n"); - col = 0; - for (i = 0; attrs[i]; i++) { - len = strlen(delim) + strlen(attrs[i]); - if (col + len > ncols) { - fprintf(fp, ",\n%s", attrs[i]); - col = strlen(attrs[i]); - } else - col += fprintf(fp, "%s%s", delim, attrs[i]); - delim = ", "; - } - fputc('\n', fp); - fputc('\n', fp); -} - int eclat_describe_instance_attribute(eclat_command_env_t *env, int argc, char **argv) { @@ -61,6 +39,7 @@ eclat_describe_instance_attribute(eclat_command_env_t *env, int argc, char **arg struct ec2_query *q = env->query; generic_proginfo->args_doc = "INST-ID ATTR"; + available_attrs = attrs; generic_proginfo->print_help_hook = list_attrs; generic_parse_options("eclat describe-instance-attribute", "describe the specified attribute of the instance", diff --git a/src/dscrsnapattr.c b/src/dscrsnapattr.c new file mode 100644 index 0000000..83b3117 --- /dev/null +++ b/src/dscrsnapattr.c @@ -0,0 +1,175 @@ +/* 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" + +static char *attrs[] = { + "createVolumePermission", + "productCodes", + 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) +{ + int i; + struct ec2_query *q = env->query; + const char *attrname; + + generic_proginfo->args_doc = "SNAP-ID [ATTR]"; + available_attrs = attrs; + generic_proginfo->print_help_hook = list_attrs; + generic_parse_options("eclat describe-snapshot-attribute", + "describe the attribute of a snapshot", + argc, argv, &i); + argv += i; + argc -= i; + + switch (argc) { + default: + die(EX_USAGE, "wrong number of arguments"); + case 2: + attrname = canonattrname(argv[1]); + if (!attrname) + die(EX_USAGE, "unrecognized attribute name"); + break; + case 1: + attrname = attrs[0]; + } + + translate_ids(1, argv, "SnapshotId"); + eclat_query_add_param(q, "SnapshotId", argv[0]); + eclat_query_add_param(q, "Attribute", attrname); + return 0; +} + +static void +remdash(char *p) +{ + char *q; + + q = p + strspn(p, "0123456789-"); + if (*q) + die(EX_USAGE, "invalid account ID: %s; stopped near %s", + p, q); + for (q = p;; p++) { + if (*p == '-') + continue; + if (!(*q++ = *p)) + break; + } +} + +int +eclat_modify_snapshot_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; + + generic_proginfo->args_doc = "{g|u}{-|+}{all|ID} SNAP-ID"; + generic_parse_options("eclat modify-snapshot-attribute", + "modify the createVolumePermission attribute of a snapshot", + argc, argv, &i); + argv += i; + argc -= i; + + if (argc < 2) + die(EX_USAGE, "wrong number of arguments"); + for (i = 0; i < argc - 1; i++) { + const char *action, *what, *arg; + + switch (argv[i][0]) { + case 'u': + what = "UserId"; + break; + case 'g': + what = "Group"; + break; + default: + die(EX_USAGE, "malformed argument: %s", argv[i]); + } + + switch (argv[i][1]) { + case '+': + action = "Add"; + break; + case '-': + action = "Remove"; + break; + default: + die(EX_USAGE, "malformed argument: %s", argv[i]); + } + + grecs_asprintf(&bufptr, &bufsize, + "CreateVolumePermission.%s.%d.%s", action, + i + 1, what); + + if (argv[i][0] == 'u') + remdash(argv[i] + 2); + eclat_query_add_param(q, bufptr, argv[i] + 2); + } + free(bufptr); + + translate_ids(1, argv + i, "SnapshotId"); + eclat_query_add_param(q, "SnapshotId", argv[i]); + + return 0; +} + +int +eclat_reset_snapshot_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; + + generic_proginfo->args_doc = "SNAP-ID"; + generic_parse_options("eclat reset-snapshot-attribute", + "reset the createVolumePermission attribute of a snapshot", + argc, argv, &i); + argv += i; + argc -= i; + + if (argc != 1) + die(EX_USAGE, "wrong number of arguments"); + + translate_ids(1, argv, "SnapshotId"); + eclat_query_add_param(q, "SnapshotId", argv[0]); + eclat_query_add_param(q, "Attribute", "CreateVolumePermission"); + + return 0; +} + diff --git a/src/eclat.c b/src/eclat.c index 03f8fbb..49691e7 100644 --- a/src/eclat.c +++ b/src/eclat.c @@ -250,6 +250,12 @@ struct command cmdtab[] = { eclat_create_snapshot }, { "describe-snapshots", "DescribeSnapshots", eclat_describe_snapshots }, + { "describe-snapshot-attribute", "DescribeSnapshotAttribute", + eclat_describe_snapshot_attribute }, + { "modify-snapshot-attribute", "ModifySnapshotAttribute", + eclat_modify_snapshot_attribute, CMD_MOD }, + { "reset-snapshot-attribute", "ResetSnapshotAttribute", + eclat_reset_snapshot_attribute, CMD_MOD|CMD_DESTR }, { "delete-snapshot", "DeleteSnapshot", eclat_delete_snapshot, CMD_MOD|CMD_DESTR }, { "describe-avaialbility-zones", "DescribeAvaialbilityZones", diff --git a/src/eclat.h b/src/eclat.h index e9220fc..2fab8cf 100644 --- a/src/eclat.h +++ b/src/eclat.h @@ -92,6 +92,13 @@ int eclat_describe_security_groups(eclat_command_env_t *env, int argc, char **ar int eclat_create_snapshot(eclat_command_env_t *env, int argc, char **argv); int eclat_describe_snapshots(eclat_command_env_t *env, int argc, char **argv); int eclat_delete_snapshot(eclat_command_env_t *env, int argc, char **argv); +int eclat_describe_snapshot_attribute(eclat_command_env_t *env, + int argc, char **argv); +int eclat_modify_snapshot_attribute(eclat_command_env_t *env, + int argc, char **argv); +int eclat_reset_snapshot_attribute(eclat_command_env_t *env, + int argc, char **argv); + int eclat_describe_avaialbility_zones(eclat_command_env_t *env, int argc, char **argv); int eclat_describe_regions(eclat_command_env_t *env, int argc, char **argv); int eclat_create_volume(eclat_command_env_t *env, int argc, char **argv); @@ -127,9 +134,13 @@ struct filter_descr { char **avail; }; -struct filter_descr *available_filters; +extern struct filter_descr *available_filters; void list_filters(FILE *fp); + +extern char **available_attrs; +void list_attrs(FILE *fp); + int get_scr_cols(void); void translate_ids(int argc, char **argv, const char *mapname); void translate_resource_ids(int argc, char **argv); diff --git a/src/modinstattr.c b/src/modinstattr.c index 582f8a7..c84345f 100644 --- a/src/modinstattr.c +++ b/src/modinstattr.c @@ -47,7 +47,7 @@ canonattrname(const char *arg, size_t *plen) } static void -list_attrs(FILE *fp) +list_mod_attrs(FILE *fp) { size_t ncols = get_scr_cols(); int i, col, len, alen; @@ -82,7 +82,7 @@ eclat_modify_instance_attribute(eclat_command_env_t *env, int argc, char **argv) size_t bufsize = 0; generic_proginfo->args_doc = "INST-ID ATTR VALUE [VALUE...]"; - generic_proginfo->print_help_hook = list_attrs; + generic_proginfo->print_help_hook = list_mod_attrs; generic_parse_options("eclat modify-instance-attribute", "modify the attribute of an instance", argc, argv, &i); @@ -273,3 +273,28 @@ eclat_actcmp(const char *a, const char *b) } return rc; } + +char **available_attrs; + +void +list_attrs(FILE *fp) +{ + size_t ncols = get_scr_cols(); + int i, col, len; + char *delim = ""; + + fprintf(fp, "Available attributes are:\n"); + col = 0; + for (i = 0; available_attrs[i]; i++) { + len = strlen(delim) + strlen(available_attrs[i]); + if (col + len > ncols) { + fprintf(fp, ",\n%s", available_attrs[i]); + col = strlen(available_attrs[i]); + } else + col += fprintf(fp, "%s%s", delim, available_attrs[i]); + delim = ", "; + } + fputc('\n', fp); + fputc('\n', fp); +} + |