/* 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 . */ #include #include static char *ami; static char *instance_count = "1"; static struct grecs_list *secgrp, *devmap, *iface, *privip; static char *keypair; static char *user_data; static char *type; static char *zone; static char *kernel; static char *ramdisk; static char *shutdown_behavior; static char *placement_group; static char *tenancy; static char *subnet; static char *private_ip; static char *secipcount; static char *profile_name; 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([], []) OPTION(,n,[], []) BEGIN /* FIXME: check if it's a valid number */ instance_count = optarg; END OPTION(security-group,g,[], []) BEGIN if (!secgrp) secgrp = grecs_list_create(); grecs_list_append(secgrp, optarg); END OPTION(keypair,k,[], []) BEGIN keypair = optarg; END OPTION(data,d,[], []) BEGIN user_data = optarg; END OPTION(data-file,f,[], []) BEGIN read_user_data(optarg); END OPTION(type,t,[], []) ALIAS(instance-type) BEGIN type = optarg; END OPTION(zone,z,[], []) ALIAS(availability-zone) BEGIN zone = optarg; END OPTION(kernel,,[], []) BEGIN ramdisk = optarg; END OPTION(devmap,m,[], []) ALIAS(block-device-mapping) BEGIN if (!devmap) devmap = grecs_list_create(); grecs_list_append(devmap, optarg); END OPTION(monitor,,, []) BEGIN monitor = 1; END OPTION(disable-api-termination,,, []) BEGIN disable_term = 1; END OPTION(shutdown,,[], []) ALIAS(instance-initiated-shutdown-behavior) BEGIN shutdown_behavior = optarg; END OPTION(placement-group,,[], []) BEGIN placement_group = optarg; END OPTION(tenancy,,[], []) BEGIN tenancy = optarg; END OPTION(subnet,s,[], []) BEGIN subnet = optarg; END OPTION(private-ip-address,,[], []) BEGIN private_ip = optarg; END dnl [--client-token token] OPTION(network-interface,a,[], []) ALIAS(iface) BEGIN if (!iface) iface = grecs_list_create(); grecs_list_append(iface, optarg); END OPTION(secondary-ip,,[], []) ALIAS(secondary-private-ip-address) BEGIN if (!privip) privip = grecs_list_create(); grecs_list_append(privip, privip); END OPTION(number-secondary-ip,,[], []) ALIAS(secondary-private-ip-address-count) BEGIN secipcount = optarg; END OPTION(iam-profile,p,[], []) BEGIN profile_name = optarg; END OPTION(ebs-optimized,,, []) BEGIN ebs_opt = 1; END ECLAT_CL_END ECLAT_CL_PARSER(parse_options, [],[< { int idx; GETOPT(argc, argv, idx, exit(EX_USAGE)) if (idx != argc-1) die(EX_USAGE, "bad number of arguments"); translate_ids(1, argv+idx, "ImageId"); ami = argv[idx]; } >])