aboutsummaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-09-20 01:36:01 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2012-09-20 01:36:01 +0300
commit0d7ee650f6198c70f2ff06bc16ba160129de70cf (patch)
treea644d54acf3762e84529f68c2364972c9b112a4c /src/config.c
parent64993d198836c3d98643670b4b056701224c854e (diff)
downloadeclat-0d7ee650f6198c70f2ff06bc16ba160129de70cf.tar.gz
eclat-0d7ee650f6198c70f2ff06bc16ba160129de70cf.tar.bz2
Implement multiple regions and StopInstance command.
* src/config.c: Change configuration statements. * src/eclat.c: Translate endpoint if region is given. * src/eclat.h: Update. * src/startinst.c: Implement stop instance.
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c59
1 files changed, 55 insertions, 4 deletions
diff --git a/src/config.c b/src/config.c
index 5727167..c40d307 100644
--- a/src/config.c
+++ b/src/config.c
@@ -50,14 +50,63 @@ run_config_finish_hooks()
return rc;
}
+/* Translation table: region -> endpoint. Its elements are of
+ struct ec2_param type. */
+struct grecs_symtab *ec2_regtab;
+
+char *
+region_to_endpoint(const char *region)
+{
+ struct ec2_param *p, key;
+
+ key.name = (char*) region;
+ p = grecs_symtab_lookup_or_install(ec2_regtab, &key, NULL);
+ return p ? p->value : NULL;
+}
+
+static int
+cb_region(enum grecs_callback_command cmd,
+ grecs_locus_t *locus,
+ void *varptr,
+ grecs_value_t *value,
+ void *cb_data)
+{
+ struct ec2_param *p, key;
+ int install = 1;
+
+ if (cmd != grecs_callback_set_value) {
+ grecs_error(locus, 0, "Unexpected block statement");
+ return 1;
+ }
+ if (!value || value->type != GRECS_TYPE_ARRAY || value->v.arg.c != 2) {
+ grecs_error(locus, 0, "expected two strings");
+ return 1;
+ }
+ if (value->v.arg.v[0]->type != GRECS_TYPE_STRING ||
+ value->v.arg.v[1]->type != GRECS_TYPE_STRING) {
+ grecs_error(locus, 0, "expected two strings");
+ return 1;
+ }
+
+ key.name = value->v.arg.v[0]->v.string;
+ p = grecs_symtab_lookup_or_install(ec2_regtab, &key, &install);
+ if (!install)
+ free(p->value); /* FIXME: Redefinition warning */
+ p->value = grecs_strdup(value->v.arg.v[1]->v.string);
+ return 0;
+}
+
static struct grecs_keyword eclat_kw[] = {
- { "host", "hostname",
- "Send queries to <hostname> instead of the default host",
- grecs_type_string, GRECS_DFLT, &default_host },
+ { "default-endpoint", "hostname",
+ "Set default EC2 endpoint",
+ grecs_type_string, GRECS_DFLT, &endpoint },
+ { "region", "<name: string> <endpoint: string>",
+ "Define a region",
+ grecs_type_string, GRECS_MULT, NULL, 0, cb_region },
{ "access-file", "file",
"Specify a file containing `accessID:accessKey' pairs",
grecs_type_string, GRECS_DFLT, &access_file_name },
- { "region", "name",
+ { "default-region", "name",
"Define default AWS region",
grecs_type_string, GRECS_DFLT, &region_name },
@@ -90,6 +139,8 @@ config_init()
grecs_log_to_stderr = 1;
grecs_adjust_string_locations = 1;
grecs_print_diag_fun = grecs_print_diag;
+
+ ec2_regtab = grecs_symtab_create_default(sizeof(struct ec2_param));
}
void

Return to:

Send suggestions and report system problems to the System administrator.