diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-04-20 10:42:08 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-04-20 10:42:08 +0300 |
commit | dd644264f786cb024e5221567f8b26efa270e753 (patch) | |
tree | 0bc1d82d541d51b5115f2defe1832502ee680b95 /src/startstop.c | |
parent | 67dce06bb26798e2b11ee0883bdc7e08d7edb663 (diff) | |
download | eclat-dd644264f786cb024e5221567f8b26efa270e753.tar.gz eclat-dd644264f786cb024e5221567f8b26efa270e753.tar.bz2 |
Add back an accidentally removed file.
Diffstat (limited to 'src/startstop.c')
-rw-r--r-- | src/startstop.c | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/startstop.c b/src/startstop.c new file mode 100644 index 0000000..216ee1c --- /dev/null +++ b/src/startstop.c | |||
@@ -0,0 +1,87 @@ | |||
1 | /* This file is part of Eclat. | ||
2 | Copyright (C) 2012, 2013 Sergey Poznyakoff. | ||
3 | |||
4 | Eclat is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 3, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | Eclat is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with Eclat. If not, see <http://www.gnu.org/licenses/>. */ | ||
16 | |||
17 | #include "eclat.h" | ||
18 | |||
19 | static void | ||
20 | parse_options(const char *progname, const char *docstring, | ||
21 | int argc, char *argv[], int *index) | ||
22 | { | ||
23 | generic_proginfo->args_doc = "ID [ID...]"; | ||
24 | return generic_parse_options(progname, docstring, argc, argv, index); | ||
25 | } | ||
26 | |||
27 | static int | ||
28 | start_stop_instance(eclat_command_env_t *env, int argc, char **argv) | ||
29 | { | ||
30 | int i; | ||
31 | struct ec2_query *q = env->query; | ||
32 | char buf[128], *bend; | ||
33 | size_t bs; | ||
34 | |||
35 | if (argc == 0) | ||
36 | die(EX_USAGE, "no instance ids"); | ||
37 | translate_ids(argc, argv, "InstanceId"); | ||
38 | |||
39 | strcpy(buf, "InstanceId."); | ||
40 | bend = buf + strlen(buf); | ||
41 | bs = sizeof(buf) - strlen(buf); | ||
42 | for (i = 0; i < argc; i++) { | ||
43 | snprintf(bend, bs, "%lu", (unsigned long)(i + 1)); | ||
44 | eclat_query_add_param(q, buf, argv[i]); | ||
45 | } | ||
46 | |||
47 | return 0; | ||
48 | } | ||
49 | |||
50 | int | ||
51 | eclat_start_instance(eclat_command_env_t *env, int argc, char **argv) | ||
52 | { | ||
53 | int i; | ||
54 | |||
55 | parse_options("eclat start-instances", | ||
56 | "Start named instances", | ||
57 | argc, argv, &i); | ||
58 | |||
59 | debug(ECLAT_DEBCAT_MAIN, 1, ("starting instances")); | ||
60 | return start_stop_instance(env, argc - i, argv + i); | ||
61 | } | ||
62 | |||
63 | int | ||
64 | eclat_stop_instance(eclat_command_env_t *env, int argc, char **argv) | ||
65 | { | ||
66 | int i; | ||
67 | |||
68 | parse_options("eclat stop-instances", | ||
69 | "Stop named instances", | ||
70 | argc, argv, &i); | ||
71 | |||
72 | debug(ECLAT_DEBCAT_MAIN, 1, ("stopping instances")); | ||
73 | return start_stop_instance(env, argc - i, argv + i); | ||
74 | } | ||
75 | |||
76 | int | ||
77 | eclat_reboot_instance(eclat_command_env_t *env, int argc, char **argv) | ||
78 | { | ||
79 | int i; | ||
80 | |||
81 | parse_options("eclat reboot-instances", | ||
82 | "Reboot named instances", | ||
83 | argc, argv, &i); | ||
84 | |||
85 | debug(ECLAT_DEBCAT_MAIN, 1, ("rebooting instances")); | ||
86 | return start_stop_instance(env, argc - i, argv + i); | ||
87 | } | ||