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 /src | |
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.
Diffstat (limited to 'src')
-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 |
9 files changed, 122 insertions, 44 deletions
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; |