aboutsummaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-10-07 20:12:34 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2012-10-07 20:12:34 +0300
commit1fbcbdb432e945aa3f63be5b9170e94a0c9ef6c3 (patch)
tree209822ff7ef7766b94a714438473dcf8f12c4e1f /src/util.c
parentcabb35e68d34bcccaa39a223eaa037b335c81558 (diff)
downloadeclat-1fbcbdb432e945aa3f63be5b9170e94a0c9ef6c3.tar.gz
eclat-1fbcbdb432e945aa3f63be5b9170e94a0c9ef6c3.tar.bz2
Implement resource identifier mapping.
Resource identifier mapping permits to use more customized identifiers instead of the Amazon resource identifiers. For instance, you can use hostnames instead of the instance IDs, etc. * lib/Makefile.am: Add new files. * lib/filemap.c: New file. * lib/map.c: New file. * lib/libeclat.h (eclat_map_drv,eclat_map): New structs. (eclat_map_status): New enum. (eclat_map_init,eclat_map_lookup,eclat_map_config) (eclat_map_free,eclat_map_open,eclat_map_close) (eclat_map_get,eclat_map_strerror,eclat_map_drv_register) (eclat_map_foreach,eclat_map_free_all) (eclat_get_string_node): New protos. (eclat_map_drv_file): New extern. * src/accfile.c (access_file_lookup): Fix memory leak. * src/cmdline.opt: New option: --translate (-x) * src/config.c (eclat_kw) <map>: New block statement. (config_finish): Parse map configs. * src/asscaddr.c: Translate key. * src/dscrinstattr.c: Likewise. * src/dscrinsts.c: Likewise. * src/dscrinststat.c: Likewise. * src/dscrsecgrps.c: Likewise. * src/getconout.c: Likewise. * src/startinst.c: Likewise. * src/eclat.c (main): Initialize maps and free them when no more needed. * src/eclat.h (translate_option): New extern. (translate_ids): New proto. * src/util.c (translate_option): New variable. (translate_ids): New function.
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index 79b7576..a6357c4 100644
--- a/src/util.c
+++ b/src/util.c
@@ -18,6 +18,36 @@
#include <termios.h>
#include <sys/ioctl.h>
+int translate_option;
+
+void
+translate_ids(int argc, char **argv, const char *mapname)
+{
+ int i;
+ struct eclat_map *map;
+ char *val;
+
+ if (!translate_option)
+ return;
+ map = eclat_map_lookup(mapname);
+ if (!map)
+ die(EX_UNAVAILABLE, "no such map: %s", mapname);
+
+ if (eclat_map_open(map) != eclat_map_ok)
+ exit(EX_UNAVAILABLE);
+
+ for (i = 0; i < argc; i++) {
+ if (!strchr(argv[i], '=')) {
+ int rc = eclat_map_get(map, argv[i], &val);
+ if (rc != eclat_map_ok) {
+ die(EX_UNAVAILABLE, "cannot translate %s: %s",
+ argv[i], eclat_map_strerror(rc));
+ }
+ argv[i] = val;
+ }
+ }
+}
+
int
get_scr_cols()
{

Return to:

Send suggestions and report system problems to the System administrator.