aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-04-05 18:06:37 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2013-04-05 18:06:37 +0300
commitd19bab14d9f3e8093ea8288c08f4df5249f2801c (patch)
tree64124e0bfb195664ba5ef3562c80437091d6b0d5 /lib
parent9205135a977cacebb79df1309ef5eaab57127f06 (diff)
downloadeclat-d19bab14d9f3e8093ea8288c08f4df5249f2801c.tar.gz
eclat-d19bab14d9f3e8093ea8288c08f4df5249f2801c.tar.bz2
Implement create-image and deregister-image.
* TODO: Update. * etc/create-image.fln: New file. * etc/deregister-image.fln: New file. * etc/Makefile.am (FLNFILES): Add new files. * lib/envmap.c: New file. * lib/Makefile.am (libeclat_a_SOURCES): Add new files. * lib/libeclat.h (eclat_encode_devmap): New proto. * src/creimg-cl.opt: New file. * src/creimg.c: New file. * src/drgimg.c: New file. * src/Makefile.am: Add new files. * src/dscrimgs-cl.opt: Change short option to -u for consistency with other commands. * src/eclat.c: New commands create-image and deregister-image. * src/eclat.h (eclat_create_image) (eclat_deregister_image): New prototypes. * src/runinsts.c (encode_devmap): Move to the library.
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am1
-rw-r--r--lib/envmap.c154
-rw-r--r--lib/libeclat.h3
3 files changed, 158 insertions, 0 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 62f58b9..d6eaa56 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -36,6 +36,7 @@ libeclat_a_SOURCES=\
base64.c\
confirm.c\
diag.c\
+ envmap.c\
expand.c\
forlan.c\
forlan.h\
diff --git a/lib/envmap.c b/lib/envmap.c
new file mode 100644
index 0000000..2e3f8aa
--- /dev/null
+++ b/lib/envmap.c
@@ -0,0 +1,154 @@
+/* This file is part of Eclat.
+ Copyright (C) 2013 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 <config.h>
+#include <string.h>
+#include <ctype.h>
+#include <sysexits.h>
+#include "libeclat.h"
+#include "wordsplit.h"
+#include "grecs.h"
+
+static int
+isnumstr(const char *p)
+{
+ for (; *p; p++)
+ if (!isdigit(*p))
+ return 0;
+ return 1;
+}
+
+void
+eclat_encode_devmap(struct ec2_query *q, struct grecs_list *list)
+{
+ int i;
+ char *bufptr = NULL;
+ size_t bufsize = 0;
+ struct grecs_list_entry *ep;
+
+ if (!list)
+ return;
+ for (i = 1, ep = list->head; ep; ep = ep->next, i++) {
+ char *dev = ep->data;
+ char *p = strchr(dev, '=');
+
+ if (!p)
+ die(EX_USAGE, "malformed device mapping: %s", dev);
+ *p++ = 0;
+
+ grecs_asprintf(&bufptr, &bufsize,
+ "BlockDeviceMapping.%d.DeviceName",
+ i);
+ eclat_query_add_param(q, bufptr, dev);
+
+ if (strcmp(p, "none") == 0) {
+ grecs_asprintf(&bufptr, &bufsize,
+ "BlockDeviceMapping.%d.NoDevice",
+ i);
+ eclat_query_add_param(q, bufptr, NULL);
+ } else if (strncmp(p, "ephemeral", 9) == 0) {
+ grecs_asprintf(&bufptr, &bufsize,
+ "BlockDeviceMapping.%d.VirtualName",
+ i);
+ eclat_query_add_param(q, bufptr, p);
+ } else {
+ struct wordsplit ws;
+
+ /* [snapshot-id]:[volume-size]:[true|false]:[standard|io1[:iops]] */
+ ws.ws_delim = ":";
+ if (wordsplit(p, &ws,
+ WRDSF_NOVAR | WRDSF_NOCMD | WRDSF_DELIM))
+ die(EX_SOFTWARE,
+ "failed to split string %s: %s",
+ p,
+ wordsplit_strerror(&ws));
+ if (ws.ws_wordc == 1) {
+ if (strncmp(ws.ws_wordv[0], "snap-", 5) == 0) {
+ grecs_asprintf(&bufptr, &bufsize,
+ "BlockDeviceMapping.%d."
+ "Ebs.SnapshotId",
+ i);
+ } else if (isnumstr(ws.ws_wordv[0])) {
+ grecs_asprintf(&bufptr, &bufsize,
+ "BlockDeviceMapping.%d."
+ "Ebs.VolumeSize",
+ i);
+ } else
+ die(EX_USAGE,
+ "unrecognized word \"%s\", "
+ "expected either a snapshot ID, "
+ "or disk size",
+ ws.ws_wordv[0]);
+ eclat_query_add_param(q, bufptr,
+ ws.ws_wordv[0]);
+ } else {
+ if (ws.ws_wordv[0]) {
+ grecs_asprintf(&bufptr, &bufsize,
+ "BlockDeviceMapping.%d."
+ "Ebs.SnapshotId",
+ i);
+ eclat_query_add_param(q, bufptr,
+ ws.ws_wordv[0]);
+ }
+
+ if (ws.ws_wordv[1]) {
+ grecs_asprintf(&bufptr, &bufsize,
+ "BlockDeviceMapping.%d."
+ "Ebs.VolumeSize",
+ i);
+ eclat_query_add_param(q, bufptr,
+ ws.ws_wordv[1]);
+ }
+ }
+
+ switch (ws.ws_wordc) {
+ default:
+ die(EX_USAGE,
+ "too many parts in device mapping \"%s\"",
+ p);
+ case 5:
+ grecs_asprintf(&bufptr, &bufsize,
+ "BlockDeviceMapping.%d.Ebs.Iops",
+ i);
+ eclat_query_add_param(q, bufptr,
+ ws.ws_wordv[4]);
+ /* fall through */
+ case 4:
+ grecs_asprintf(&bufptr, &bufsize,
+ "BlockDeviceMapping.%d.Ebs.VolumeType",
+ i);
+ eclat_query_add_param(q, bufptr,
+ ws.ws_wordv[3]);
+ /* fall through */
+ case 3:
+ if (strcmp(ws.ws_wordv[2], "false") &&
+ strcmp(ws.ws_wordv[2], "true"))
+ die(EX_USAGE,
+ "expected \"true\" or \"false\", "
+ "but found \"%s\"",
+ ws.ws_wordv[2]);
+ grecs_asprintf(&bufptr, &bufsize,
+ "BlockDeviceMapping.%d."
+ "Ebs.DeleteOnTermination",
+ i);
+ eclat_query_add_param(q, bufptr,
+ ws.ws_wordv[2]);
+ }
+ wordsplit_free(&ws);
+ }
+ }
+ free(bufptr);
+}
diff --git a/lib/libeclat.h b/lib/libeclat.h
index 107d15d..7c0d2fb 100644
--- a/lib/libeclat.h
+++ b/lib/libeclat.h
@@ -93,6 +93,9 @@ void eclat_query_signature(struct ec2_query *req, char *secret);
char *eclat_query_to_url(struct ec2_query *req, char **post_params);
void eclat_query_encode(struct ec2_query *q);
+
+void eclat_encode_devmap(struct ec2_query *q, struct grecs_list *list);
+
typedef struct eclat_partial_tree *eclat_partial_tree_t;

Return to:

Send suggestions and report system problems to the System administrator.