diff options
Diffstat (limited to 'src/runinsts.c')
-rw-r--r-- | src/runinsts.c | 131 |
1 files changed, 1 insertions, 130 deletions
diff --git a/src/runinsts.c b/src/runinsts.c index 826377d..c13361a 100644 --- a/src/runinsts.c +++ b/src/runinsts.c @@ -17,135 +17,6 @@ #include "eclat.h" #include "runinsts-cl.h" -static int -isnumstr(const char *p) -{ - for (; *p; p++) - if (!isdigit(*p)) - return 0; - return 1; -} - -static void -encode_devmap(struct ec2_query *q) -{ - int i; - char *bufptr = NULL; - size_t bufsize = 0; - struct grecs_list_entry *ep; - - for (i = 1, ep = devmap->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); -} - /* format: dev-index:subnet:description:priv-ip:sgs:DOT:sip-count:sips @@ -302,7 +173,7 @@ eclat_run_instances(eclat_command_env_t *env, int argc, char **argv) eclat_query_add_param(q, "RamdiskId", ramdisk); if (devmap) - encode_devmap(q); + eclat_encode_devmap(q, devmap); if (monitor) eclat_query_add_param(q, "Monitoring.Enabled", "true"); |