diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-01-22 17:32:33 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-01-22 17:49:08 +0200 |
commit | f158212743c51bf1ebd44d27ee07a6c2b4867426 (patch) | |
tree | d50ec63da5173113bae52b9dfa39bf2ab370cfc6 | |
parent | 90262e24c2a3ec8b1e3fa189f80b41166a347555 (diff) | |
download | eclat-f158212743c51bf1ebd44d27ee07a6c2b4867426.tar.gz eclat-f158212743c51bf1ebd44d27ee07a6c2b4867426.tar.bz2 |
Improve setting UserData attribute. Change lsistat defaults.
* NEWS: Update.
* doc/eclat-setiattr.1: Document new options.
* doc/eclat-lsistat.1: Update.
* etc/describe-instance-attribute.fln: Decode userData.
* grecs: Upgrade.
* src/setiattr-cl.opt: New file.
* src/Makefile.am (OPTFILES): Add setiattr-cl.opt
* src/setiattr.c: Encode UserData.
* src/eclat.h (read_file): New proto.
* src/lsistat-cl.opt: New option -r (--running).
* src/lsistat.c: Change default to show all instances, no matter
their state.
* src/mkinst-cl.opt (read_user_data): Remove. Use read_file instead.
* src/sg.c: Add missing include.
* src/util.c (read_file): New function.
-rw-r--r-- | NEWS | 13 | ||||
-rw-r--r-- | doc/eclat-lsistat.1 | 19 | ||||
-rw-r--r-- | doc/eclat-setiattr.1 | 26 | ||||
-rw-r--r-- | etc/describe-instance-attribute.fln | 3 | ||||
m--------- | grecs | 0 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/eclat.h | 3 | ||||
-rw-r--r-- | src/lsistat-cl.opt | 8 | ||||
-rw-r--r-- | src/lsistat.c | 4 | ||||
-rw-r--r-- | src/mkinst-cl.opt | 28 | ||||
-rw-r--r-- | src/setiattr-cl.opt | 39 | ||||
-rw-r--r-- | src/setiattr.c | 35 | ||||
-rw-r--r-- | src/sg.c | 3 | ||||
-rw-r--r-- | src/util.c | 45 |
14 files changed, 170 insertions, 57 deletions
@@ -60,6 +60,19 @@ taken from the instance store. Lists content of the instance store. +* Setting UserData instance attribute. + +The setiattr (modify-instance-attribute) command automatically encodes +the value of UserData attribute in base64. A command line option is +provided to read the value from a file. + +* lsistat + +The default for lsistat (describe-instance-status) command has been +changed to display all instances, no matter their status. Use the +-r (--running) option to get prior behavior. The -a (--all) option +has been retained for backward compatibility. + Version 1.0, 2013-12-20 diff --git a/doc/eclat-lsistat.1 b/doc/eclat-lsistat.1 index 6d1b9a3..a222701 100644 --- a/doc/eclat-lsistat.1 +++ b/doc/eclat-lsistat.1 @@ -1,5 +1,5 @@ .\" This file is part of Eclat -*- nroff -*- -.\" Copyright (C) 2012-2014 Sergey Poznyakoff +.\" Copyright (C) 2012-2015 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 @@ -13,11 +13,16 @@ .\" .\" You should have received a copy of the GNU General Public License .\" along with Eclat. If not, see <http://www.gnu.org/licenses/>. -.TH LSISTAT 1 "February 13, 2014" "ECLAT" "Eclat User Reference" +.TH LSISTAT 1 "January 22, 2015" "ECLAT" "Eclat User Reference" .SH NAME eclat lsistat, describe\-instance\-status \- describe status of EC2 instances .SH SYNOPSIS -\fBeclat lsistat\fR [\fB\-a\fR] [\fB\-\-all\fR] [\fIFILTER\fR...] +\fBeclat\fR\ + \fBlsistat\fR + [\fB\-ar\fR]\ + [\fB\-\-all\fR]\ + [\fB\-\-running\fR]\ + [\fIFILTER\fR...] .PP \fBeclat lsistat\fR \fB\-\-help\fR .SH DESCRIPTION @@ -44,8 +49,10 @@ services it runs, etc.) .SH OPTIONS .TP \fB\-a\fR, \fB\-\-all\fR -Return the status for all instances. By default, only running -instances are described. +Return the status for all instances. This is the default. +.TP +\fB\-r\fR, \fB\-\-running\fR +Show only running instances. .SH FILTERS The following filters are defined: .TP @@ -162,7 +169,7 @@ Sergey Poznyakoff .SH "BUG REPORTS" Report bugs to <bug\-eclat@gnu.org.ua>. .SH COPYRIGHT -Copyright \(co 2012-2014 Sergey Poznyakoff +Copyright \(co 2012-2015 Sergey Poznyakoff .br .na License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> diff --git a/doc/eclat-setiattr.1 b/doc/eclat-setiattr.1 index c121f8a..363c9b9 100644 --- a/doc/eclat-setiattr.1 +++ b/doc/eclat-setiattr.1 @@ -1,5 +1,5 @@ .\" This file is part of Eclat -*- nroff -*- -.\" Copyright (C) 2012-2014 Sergey Poznyakoff +.\" Copyright (C) 2012-2015 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 @@ -13,13 +13,15 @@ .\" .\" You should have received a copy of the GNU General Public License .\" along with Eclat. If not, see <http://www.gnu.org/licenses/>. -.TH SETIATTR 1 "February 13, 2014" "ECLAT" "Eclat User Reference" +.TH SETIATTR 1 "January 22, 2015" "ECLAT" "Eclat User Reference" .SH NAME eclat setiattr, modify\-instance\-attribute \- modifies attribute of an instance .SH SYNOPSIS -.nh -.na -\fBeclat setiattr\fR \fIINSTANCE-ID\fR \fIATTR\fR\ +\fBeclat setiattr\fR\ + [\fB\-bf\fR]\ + [\fB\-\-base64\fR]\ + [\fB\-\-file\fR]\ + \fIINSTANCE-ID\fR \fIATTR\fR\ \fIVALUE\fR [\fIVALUE\fR...] .PP \fBeclat setiattr\fR \fB\-\-help\fR @@ -34,6 +36,18 @@ in .BR eclat (1)), this command uses the \fBInstanceId\fR map to translate \fIINSTANCE-ID\fR to the corresponding identifier. +.SH OPTIONS +Both options are valid only when setting the value of +.BR UserData : +.TP +\fB\-b\fR, \fB\-\-base64\fR +Value is already base64-encoded. If that option is not given, +.B eclat +assumes the value is plaintext and will encode it. +.TP +\fB\-f\fR, \fB\-\-file\fR +Treat the \fIVALUE\fR argument as the name of file to read the value +from. To read from the standard input, use \fB\-\fR (a dash). .SH ATTRIBUTES The \fIATTR\fR argument can be one of the following: .TP @@ -92,7 +106,7 @@ Sergey Poznyakoff .SH "BUG REPORTS" Report bugs to <bug\-eclat@gnu.org.ua>. .SH COPYRIGHT -Copyright \(co 2012-2014 Sergey Poznyakoff +Copyright \(co 2012-2015 Sergey Poznyakoff .br .na License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> diff --git a/etc/describe-instance-attribute.fln b/etc/describe-instance-attribute.fln index 49f6ff7..49b6b35 100644 --- a/etc/describe-instance-attribute.fln +++ b/etc/describe-instance-attribute.fln @@ -17,12 +17,13 @@ if (.DescribeInstanceAttributeResponse.instanceType.value || .DescribeInstanceAttributeResponse.kernel.value || .DescribeInstanceAttributeResponse.ramdisk.value || - .DescribeInstanceAttributeResponse.userData.value || .DescribeInstanceAttributeResponse.disableApiTermination.value || .DescribeInstanceAttributeResponse.instanceInitiatedShutdownBehavior.value || .DescribeInstanceAttributeResponse.rootDeviceName.value || .DescribeInstanceAttributeResponse.ebsOptimized.value) print(last,"\n"); +else if (.DescribeInstanceAttributeResponse.userData.value) + print(decode(last), "\n"); else if (.DescribeInstanceAttributeResponse.blockDeviceMapping) for (dev in .DescribeInstanceAttributeResponse.blockDeviceMapping.item) { print(dev.deviceName,"\t", dev.ebs.volumeId, "\t", dev.ebs.status, diff --git a/grecs b/grecs -Subproject 7534b68099db68eb3f47c2dbcff51127d7c3e31 +Subproject 6331e7708f13efed852e6b85aa17ac21dc158ad diff --git a/src/Makefile.am b/src/Makefile.am index 0cd910e..ecc05d3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -101,6 +101,7 @@ OPTFILES=\ rmaddr-cl.opt\ rmsg-cl.opt\ sg-cl.opt\ + setiattr-cl.opt\ setaattr-cl.opt eclat_SOURCES += $(OPTFILES:.opt=.h) diff --git a/src/eclat.h b/src/eclat.h index d83b8fa..28fcaf0 100644 --- a/src/eclat.h +++ b/src/eclat.h @@ -1,5 +1,5 @@ /* This file is part of Eclat. - Copyright (C) 2012-2014 Sergey Poznyakoff. + Copyright (C) 2012-2015 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 @@ -215,6 +215,7 @@ extern char **available_attrs; void list_attrs(FILE *fp); char *canonattrname(char **attrs, const char *arg, char *delim, size_t *plen); +char *read_file(const char *file); int get_scr_cols(void); diff --git a/src/lsistat-cl.opt b/src/lsistat-cl.opt index a55aeef..4c2de27 100644 --- a/src/lsistat-cl.opt +++ b/src/lsistat-cl.opt @@ -18,11 +18,17 @@ ECLAT_CL_BEGIN([<describe the status of Amazon EC2 instances including any sched [<[FILTER...]>]) OPTION(all,a,, - [<return the health status for all instances>]) + [<return the health status for all instances (default)>]) BEGIN all_option = 1; END +OPTION(running,r,, + [<show only running instances>]) +BEGIN + all_option = 0; +END + ECLAT_CL_END ECLAT_CL_PARSER(parse_options, [<int argc, char *argv[], int *index>], [< diff --git a/src/lsistat.c b/src/lsistat.c index 50b86e2..3638db7 100644 --- a/src/lsistat.c +++ b/src/lsistat.c @@ -1,5 +1,5 @@ /* This file is part of Eclat. - Copyright (C) 2012-2014 Sergey Poznyakoff. + Copyright (C) 2012-2015 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 @@ -15,7 +15,7 @@ along with Eclat. If not, see <http://www.gnu.org/licenses/>. */ #include "eclat.h" -static int all_option; +static int all_option = 1; #include "lsistat-cl.h" int diff --git a/src/mkinst-cl.opt b/src/mkinst-cl.opt index 16521d3..8fd9c27 100644 --- a/src/mkinst-cl.opt +++ b/src/mkinst-cl.opt @@ -1,5 +1,5 @@ /* This file is part of Eclat. - Copyright (C) 2013-2014 Sergey Poznyakoff. + Copyright (C) 2013-2015 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 @@ -14,7 +14,6 @@ You should have received a copy of the GNU General Public License along with Eclat. If not, see <http://www.gnu.org/licenses/>. */ -#include <sys/stat.h> #include <stdio.h> static char *ami; @@ -38,29 +37,6 @@ static int monitor; static int disable_term; static int ebs_opt; -static void -read_user_data(const char *file) -{ - struct stat st; - FILE *fp; - - if (stat(file, &st)) - die(EX_USAGE, "cannot stat file %s: %s", file, - strerror(errno)); - - /* FIXME: Use limits.h to check st.st_size */ - user_data = grecs_malloc(st.st_size+1); - fp = fopen(file, "r"); - if (!fp) - die(EX_UNAVAILABLE, "cannot open file %s: %s", file, - strerror(errno)); - if (fread(user_data, st.st_size, 1, fp) != 1) - die(EX_UNAVAILABLE, "error reading from %s: %s", file, - strerror(errno)); - fclose(fp); - user_data[st.st_size] = 0; -} - ECLAT_CL_BEGIN([<launch new instances>], [<AMI-ID>]) @@ -94,7 +70,7 @@ END OPTION(data-file,f,[<FILE>], [<read user data from FILE>]) BEGIN - read_user_data(optarg); + user_data = read_file(optarg); END OPTION(type,t,[<TYPE>], diff --git a/src/setiattr-cl.opt b/src/setiattr-cl.opt new file mode 100644 index 0000000..d3376c4 --- /dev/null +++ b/src/setiattr-cl.opt @@ -0,0 +1,39 @@ +/* This file is part of Eclat. + Copyright (C) 2013-2015 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/>. */ + +ECLAT_CL_BEGIN([<modify the attribute of an instance>], + [<INST-ID ATTR VALUE [VALUE...]>]) + +OPTION(data-file,f,, + [<read user data from file>]) +BEGIN + from_file = 1; +END + +OPTION(base64,b,, + [<user data are already base64-encoded>]) +BEGIN + is_base64 = 1; +END + +ECLAT_CL_END + +ECLAT_CL_PARSER(parse_options, [<int argc, char *argv[], int *index>],[< +{ + optind = 1; + proginfo.print_help_hook = list_mod_attrs; + GETOPT(argc, argv, *index) +}>]) diff --git a/src/setiattr.c b/src/setiattr.c index 60687b7..e799bc7 100644 --- a/src/setiattr.c +++ b/src/setiattr.c @@ -1,5 +1,5 @@ /* This file is part of Eclat. - Copyright (C) 2012-2014 Sergey Poznyakoff. + Copyright (C) 2012-2015 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 @@ -54,6 +54,9 @@ list_mod_attrs(FILE *fp) fputc('\n', fp); } +int from_file; +int is_base64; +#include "setiattr-cl.h" int eclat_modify_instance_attribute(eclat_command_env_t *env, int argc, char **argv) @@ -64,14 +67,10 @@ eclat_modify_instance_attribute(eclat_command_env_t *env, int argc, char **argv) size_t canonlen; char *bufptr = NULL; size_t bufsize = 0; - - generic_proginfo->args_doc = "INST-ID ATTR VALUE [VALUE...]"; - generic_proginfo->print_help_hook = list_mod_attrs; - generic_parse_options(env->cmd, - "modify the attribute of an instance", - argc, argv, &i); - argv += i; - argc -= i; + + parse_options(env, argc, argv, &i); + argv += i; + argc -= i; if (argc < 3) die(EX_USAGE, "wrong number of arguments"); @@ -112,9 +111,21 @@ eclat_modify_instance_attribute(eclat_command_env_t *env, int argc, char **argv) argv[i]); eclat_query_add_param(q, bufptr, p); } - } else if (argc != 3) - die(EX_USAGE, "wrong number of arguments"); - else + } else if (strcmp(canonattr, "UserData.Value") == 0) { + char *input = from_file ? read_file(argv[2]) : argv[2]; + size_t enclen = 0; + char *data; + + if (is_base64) + data = input; + else + eclat_base64_encode((unsigned char *)input, + strlen(input), + (unsigned char**) &data, &enclen); + eclat_query_add_param(q, canonattr, data); + if (enclen) + free(data); + } else eclat_query_add_param(q, canonattr, argv[2]); free(bufptr); return 0; @@ -1,5 +1,5 @@ /* This file is part of Eclat. - Copyright (C) 2013-2014 Sergey Poznyakoff. + Copyright (C) 2013-2015 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 @@ -17,6 +17,7 @@ #include "eclat.h" #include <arpa/inet.h> #include <netdb.h> +#include <netinet/in.h> #include "sg.h" struct groupkw groupkw[] = { @@ -1,5 +1,5 @@ /* This file is part of Eclat. - Copyright (C) 2012-2014 Sergey Poznyakoff. + Copyright (C) 2012-2015 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 @@ -18,6 +18,7 @@ #include "json.h" #include <termios.h> #include <sys/ioctl.h> +#include <sys/stat.h> int translation_enabled; char *custom_map; @@ -367,6 +368,48 @@ canonattrname(char **attrs, const char *arg, char *delim, size_t *plen) } return NULL; } + +char * +read_file(const char *file) +{ + char *buf = NULL; + + if (strcmp(file, "-") == 0) { + struct grecs_txtacc *acc = grecs_txtacc_create(); + char inbuf[4096]; + size_t n; + + while (n = fread(inbuf, 1, sizeof(inbuf), stdin)) + grecs_txtacc_grow(acc, inbuf, n); + grecs_txtacc_grow_char(acc, 0); + if (ferror(stdin)) + die(EX_NOINPUT, "read error"); + grecs_txtacc_grow_char(acc, 0); + buf = grecs_txtacc_finish(acc, 1); + grecs_txtacc_free(acc); + } else { + struct stat st; + FILE *fp; + + if (stat(file, &st)) + die(EX_USAGE, "cannot stat file %s: %s", file, + strerror(errno)); + + /* FIXME: Use limits.h to check st.st_size */ + buf = grecs_malloc(st.st_size+1); + fp = fopen(file, "r"); + if (!fp) + die(EX_NOINPUT, "cannot open file %s: %s", file, + strerror(errno)); + if (fread(buf, st.st_size, 1, fp) != 1) + die(EX_NOINPUT, "error reading from %s: %s", file, + strerror(errno)); + fclose(fp); + buf[st.st_size] = 0; + } + + return buf; +} char *instance_store_base_url = "http://169.254.169.254/latest"; unsigned short instance_store_port; |