aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2014-02-04 11:59:16 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2014-02-04 12:06:44 +0200
commit9ab2885b1ab9daef69b231c36f662daae30175b7 (patch)
tree8cac5f9ca98d95e5e5a30b5af8519e3531575c44
parentc3feab15f38588dbd677234c17a109c2378308f7 (diff)
downloadeclat-9ab2885b1ab9daef69b231c36f662daae30175b7.tar.gz
eclat-9ab2885b1ab9daef69b231c36f662daae30175b7.tar.bz2
New commands: lsaattr and setaattr.
* TODO: Update. * doc/Makefile.inc: Add new files. * doc/eclat-lsaattr.1: New file. * doc/eclat-setaattr.1: New file. * etc/Makefile.am (FLNFILES): Add new files. * etc/describe-image-attribute.fln: New file. * etc/modify-image-attribute.fln: New file. * src/Makefile.am (eclat_SOURCES,OPTFILES): Add new files. * src/eclat.c (cmdtab): New commands: lsaattr and setaattr. * src/eclat.h (eclat_describe_image_attribute) (eclat_modify_image_attribute,canonattrname): New protos. * src/lsaattr.c: New file. * src/lsiattr.c: Use canonattrname to simplify usage. * src/lssattr.c (canonattrname): Remove. Use external version. * src/setaattr-cl.opt: New file. * src/setaattr.c: New file. * src/setiattr.c: New file. * src/util.c (canonattrname): New function.
-rw-r--r--TODO4
-rw-r--r--doc/Makefile.inc2
-rw-r--r--doc/eclat-lsaattr.172
-rw-r--r--doc/eclat-setaattr.1109
-rw-r--r--etc/Makefile.am2
-rw-r--r--etc/describe-image-attribute.fln35
-rw-r--r--etc/modify-image-attribute.fln22
-rw-r--r--src/Makefile.am5
-rw-r--r--src/eclat.c6
-rw-r--r--src/eclat.h7
-rw-r--r--src/lsaattr.c63
-rw-r--r--src/lsiattr.c8
-rw-r--r--src/lssattr.c14
-rw-r--r--src/setaattr-cl.opt55
-rw-r--r--src/setaattr.c119
-rw-r--r--src/setiattr.c18
-rw-r--r--src/util.c18
17 files changed, 523 insertions, 36 deletions
diff --git a/TODO b/TODO
index 157e18b..8953a65 100644
--- a/TODO
+++ b/TODO
@@ -79,7 +79,7 @@ DescribeConversionTasks - [ ] [ ]
DescribeCustomerGateways - [ ] [ ]
DescribeDhcpOptions - [ ] [ ]
DescribeExportTasks - [ ] [ ]
-DescribeImageAttribute - [ ] [ ]
+DescribeImageAttribute lsaattr [X] [X]
DescribeImages lsimg [X] [X]
DescribeInstanceAttribute lsiattr [X] [X]
DescribeInstances lsinst [X] [X]
@@ -123,7 +123,7 @@ GetPasswordData - [ ] [ ]
ImportInstance - [ ] [ ]
ImportKeyPair - [ ] [ ]
ImportVolume - [ ] [ ]
-ModifyImageAttribute - [ ] [ ]
+ModifyImageAttribute setaattr [X] [X]
ModifyInstanceAttribute setiattr [X] [X]
ModifyNetworkInterfaceAttribute - [ ] [ ]
ModifySnapshotAttribute setsattr [X] [X]
diff --git a/doc/Makefile.inc b/doc/Makefile.inc
index 6925cc5..f777f59 100644
--- a/doc/Makefile.inc
+++ b/doc/Makefile.inc
@@ -30,6 +30,7 @@ MANPAGES1=\
eclat-devol.1\
eclat-disasaddr.1\
eclat-lsaddr.1\
+ eclat-lsaattr.1\
eclat-lsiattr.1\
eclat-lsimg.1\
eclat-lsinst.1\
@@ -53,6 +54,7 @@ MANPAGES1=\
eclat-rmsg.1\
eclat-rmsnap.1\
eclat-rmtag.1\
+ eclat-setaattr.1\
eclat-setiattr.1\
eclat-setsattr.1\
eclat-sg.1\
diff --git a/doc/eclat-lsaattr.1 b/doc/eclat-lsaattr.1
new file mode 100644
index 0000000..f108949
--- /dev/null
+++ b/doc/eclat-lsaattr.1
@@ -0,0 +1,72 @@
+.\" This file is part of Eclat -*- nroff -*-
+.\" 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/>.
+.TH ECLAT 1 "February 3, 2014" "ECLAT" "Eclat User Reference"
+.SH NAME
+eclat lsaattr, describe\-image\-attribute \- lists the attribute of an image.
+.SH SYNOPSI
+\fBeclat lsaattr\fB \fIAMI\-ID\fR [\fIATTR\fR]
+.br
+\fBeclat lsaattr\fB \fB\-\-help\fR
+.SH DESCRIPTION
+Thic command outputs the value of the attribute \fIATTR\fR of the AWS
+image \fIAMI-ID\fR. The latter is either the image
+identifier, or, if ID mapping is enabled (see the section \fBMAPS\fR
+in
+.BR eclat (1)),
+its symbolic name, which will be translated using
+the \fBImageId\fR map.
+.PP
+The \fBATTR\fR must be one of the following (case-insensitive):
+.BR description ,
+.BR blockDeviceMapping ,
+.BR launchPermission ,
+.BR productCodes ,
+.BR kernel ,
+.BR ramdisk
+.BR sriovNetSupport .
+.SH "SEE ALSO"
+.BR eclat (1),
+.BR eclat\-setaattr (1).
+.BR eclat\-mkimg (1),
+.BR eclat\-mkinst (1).
+.SH BUGS
+Reportedly, AWS is unable to return
+.BR blockDeviceMapping .
+Instead it returns an error code saying "Unauthorized attempt to
+access restricted resource", even if you supply the right
+credentials. This is an AWS bug, not
+.BR eclat 's.
+.SH AUTHORS
+Sergey Poznyakoff
+.SH "BUG REPORTS"
+Report bugs to <bug\-eclat@gnu.org.ua>.
+.SH COPYRIGHT
+Copyright \(co 2012, 2013 Sergey Poznyakoff
+.br
+.na
+License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
+.br
+.ad
+This is free software: you are free to change and redistribute it.
+There is NO WARRANTY, to the extent permitted by law.
+.\" Local variables:
+.\" eval: (add-hook 'write-file-hooks 'time-stamp)
+.\" time-stamp-start: ".TH [A-Z_][A-Z0-9_.\\-]* [0-9] \""
+.\" time-stamp-format: "%:B %:d, %:y"
+.\" time-stamp-end: "\""
+.\" time-stamp-line-limit: 20
+.\" end:
+
diff --git a/doc/eclat-setaattr.1 b/doc/eclat-setaattr.1
new file mode 100644
index 0000000..ba5c91a
--- /dev/null
+++ b/doc/eclat-setaattr.1
@@ -0,0 +1,109 @@
+.\" This file is part of Eclat -*- nroff -*-
+.\" 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/>.
+.TH ECLAT 1 "February 3, 2014" "ECLAT" "Eclat User Reference"
+.SH NAME
+eclat setaattr, modify-image-attribute \- modify attributes of an image
+.SH SYNOPSIS
+\fBeclat setaattr\fB \fIAMI\-ID\fR \fBdescription\fR \fIVALUE\fR
+.br
+\fBeclat setaattr\fB \fIAMI\-ID\fR \fBProductCode\fR \fICODE\fR [\fICODE\fR...]
+.br
+\fBeclat setaattr\fB \fIAMI\-ID\fR \fBLaunchPermission\fR\
+ [\fIOPTION\fR] \fIVALUE\fR [[\fIOPTION\fR] \fIVALUE\fR...]
+.br
+\fBeclat setaattr\fB \fIAMI\-ID\fR \fBLaunchPermission\fR {\fB\-a\fR|\fB\-d\fR}\
+ {\fB\-\-add\fR|\fB\-\-delete\fR} {\fB\-\-group\-name\fR|\fB\-\-user\-id\fR}\
+ \fIVALUE\fR
+.SH DESCRIPTION
+Set or remove attributes of an AWS image.
+.PP
+Only three attributes can be modified:
+.BR description ,
+.BR ProductCode ", and"
+.BR LaunchPermission .
+All three names are case-insensitive.
+.PP
+Setting the description requires a single value (see the first form in
+the synopsis).
+.PP
+The \fBProductCode\fR attribute can be assigned multiple values in the
+single invocation (second form in the synopsis). Note, that this
+operation is irreversible: after a product code is added to an AMI, it
+can't be removed.
+.PP
+The third form adds or removes AWS accounts to the
+\fBLaunchPermission\fR list. It allows for the following options:
+.TP
+.BR \-a ", " \-\-add
+Add the accounts that follow this option.
+.TP
+.BR \-d ", " \-\-delete
+Delete the accounts that follow this option.
+.PP
+This two options invert each other's effect. The default action is
+\fB\-\-add\fR, so the use of the \fB\-\-add\fR option is optional if
+it is the only option in the command line.
+.TP
+.BR \-g ", " \-\-group\-name
+Treat the arguments that follow as group names, instead of the account
+numbers. According to the AWS documentation, the only valid value
+that can be used with this option is \fBall\fR, which means all Amazon
+EC2 users.
+.TP
+.BR \-u ", " \-\-user\-id
+Treat the arguments that follow as user (account) IDs. This is the
+default. This option is intended to be used after
+\fB\-\-group\-name\fR to cancel its effect.
+.SH EXAMPLE
+.nr step 1 1
+.IP \n[step].
+Add a description :
+.PP
+.EX
+.B eclat setaattr ami-abcde012 description "Database server"
+.EE
+.IP \n+[step].
+Allow account \fB123456701234\fR to launch instances from
+\fBami-abcde012\fR, and revoke that permission from the rest of EC2 users.
+.PP
+.EX
+.B eclat setaattr ami-abcde012 LaunchPermission --add 123456701234 \\\\
+.B --del --group all
+.EE
+.SH "SEE ALSO"
+.BR eclat (1),
+.BR eclat\-lsaattr (1).
+.SH AUTHORS
+Sergey Poznyakoff
+.SH "BUG REPORTS"
+Report bugs to <bug\-eclat@gnu.org.ua>.
+.SH COPYRIGHT
+Copyright \(co 2012, 2013 Sergey Poznyakoff
+.br
+.na
+License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
+.br
+.ad
+This is free software: you are free to change and redistribute it.
+There is NO WARRANTY, to the extent permitted by law.
+.\" Local variables:
+.\" eval: (add-hook 'write-file-hooks 'time-stamp)
+.\" time-stamp-start: ".TH [A-Z_][A-Z0-9_.\\-]* [0-9] \""
+.\" time-stamp-format: "%:B %:d, %:y"
+.\" time-stamp-end: "\""
+.\" time-stamp-line-limit: 20
+.\" end:
+
diff --git a/etc/Makefile.am b/etc/Makefile.am
index f6a8186..3bcc242 100644
--- a/etc/Makefile.am
+++ b/etc/Makefile.am
@@ -34,6 +34,7 @@ FLNFILES=\
deregister-image.fln\
describe-addresses.fln\
describe-availability-zones.fln\
+ describe-image-attribute.fln\
describe-images.fln\
describe-instance-attribute.fln\
describe-instance-status.fln\
@@ -48,6 +49,7 @@ FLNFILES=\
disassociate-address.fln\
get-console-output.fln\
lsattr.fln\
+ modify-image-attribute.fln\
modify-instance-attribute.fln\
modify-snapshot-attribute.fln\
reboot-instances.fln\
diff --git a/etc/describe-image-attribute.fln b/etc/describe-image-attribute.fln
new file mode 100644
index 0000000..2231942
--- /dev/null
+++ b/etc/describe-image-attribute.fln
@@ -0,0 +1,35 @@
+/* This file is part of Eclat.
+ Copyright (C) 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/>. */
+
+if (.DescribeImageAttributeResponse.description.value ||
+ .DescribeImageAttributeResponse.kernel.value ||
+ .DescribeImageAttributeResponse.ramdisk.value ||
+ .DescribeImageAttributeResponse.sriovNetSupport.value ||
+ .DescribeImageAttributeResponse.productCodes.value)
+ print(last,"\n");
+else if (.DescribeImageAttributeResponse.blockDeviceMapping)
+ for (dev in .DescribeImageAttributeResponse.blockDeviceMapping.item) {
+ print(dev.deviceName,"\t", dev.ebs.volumeId, "\t", dev.ebs.status,
+ "\t", dev.ebs.deleteOnTermination);
+ if (dev.ebs.status[attached])
+ print("\t", dev.ebs.attachTime);
+ print("\n");
+ }
+else if (.DescribeImageAttributeResponse.launchPermission) {
+ for (itm in .DescribeImageAttributeResponse.launchPermission.item) {
+ print(itm.userId,"\n");
+ }
+}
diff --git a/etc/modify-image-attribute.fln b/etc/modify-image-attribute.fln
new file mode 100644
index 0000000..9ac381f
--- /dev/null
+++ b/etc/modify-image-attribute.fln
@@ -0,0 +1,22 @@
+/* This file is part of Eclat.
+ Copyright (C) 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/>. */
+
+if (.ModifyImageAttributeResponse.return) {
+ if (!.ModifyImageAttributeResponse.return[true]) {
+ error("Return: ",.ModifyImageAttributeResponse.return,"\n");
+ exit(1);
+ }
+}
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]);
diff --git a/src/util.c b/src/util.c
index cb4220c..1a0a6d0 100644
--- a/src/util.c
+++ b/src/util.c
@@ -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;
+}
+

Return to:

Send suggestions and report system problems to the System administrator.