1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
#include <stdio.h>
#include <time.h>
#include <misc.h>
#include <cc-client-marshal.h>
#ifndef MODE
#define MODE 0
#endif
int main(int argc, char **argv) {
axutil_env_t * env = NULL;
axis2_char_t * client_home = NULL;
axis2_char_t endpoint_uri[256], *tmpstr;
axis2_stub_t * stub = NULL;
int rc, i, port, use_wssec;
char *euca_home, configFile[1024], policyFile[1024];
if (MODE == 0) {
if (argc != 2 || strcmp(argv[1], "-9")) {
printf("only runnable from inside euca\n");
exit(1);
}
} else {
if (argc < 3) {
printf("USAGE: CCclient <host:port> <command> <opts>\n");
exit(1);
}
}
euca_home = getenv("EUCALYPTUS");
if (!euca_home) {
snprintf(configFile, 1024, "/etc/eucalyptus/eucalyptus.conf");
snprintf(policyFile, 1024, "/var/eucalyptus/keys/cc-client-policy.xml");
} else {
snprintf(configFile, 1024, "%s/etc/eucalyptus/eucalyptus.conf", euca_home);
snprintf(policyFile, 1024, "%s/var/eucalyptus/keys/cc-client-policy.xml", euca_home);
}
rc = get_conf_var(configFile, "CC_PORT", &tmpstr);
if (rc != 1) {
// error
logprintf("ERROR: parsing config file (%s) for CC_PORT\n",configFile);
exit(1);
} else {
port = atoi(tmpstr);
}
rc = get_conf_var(configFile, "ENABLE_WS_SECURITY", &tmpstr);
if (rc != 1) {
// error
logprintf("ERROR: parsing config file (%s) for ENABLE_WS_SECURITY\n",configFile);
exit(1);
} else {
if (!strcmp(tmpstr, "Y")) {
use_wssec = 1;
} else {
use_wssec = 0;
}
}
if (MODE == 0) {
snprintf(endpoint_uri, 256," http://localhost:%d/axis2/services/EucalyptusCC", port);
} else {
snprintf(endpoint_uri, 256," http://%s/axis2/services/EucalyptusCC", argv[1]);
}
env = axutil_env_create_all(NULL, 0);
//env = axutil_env_create_all("/tmp/fofo", AXIS2_LOG_LEVEL_TRACE);
client_home = AXIS2_GETENV("AXIS2C_HOME");
if (!client_home) {
printf("must have AXIS2C_HOME set\n");
exit(1);
}
stub = axis2_stub_create_EucalyptusCC(env, client_home, endpoint_uri);
if (use_wssec) {
rc = InitWSSEC(env, stub, policyFile);
if (rc) {
printf("cannot initialize WS-SEC policy (%s)\n",policyFile);
exit(1);
}
}
if (MODE == 0) {
rc = cc_killallInstances(env, stub);
if (rc != 0) {
printf("cc_killallInstances() failed\n");
exit(1);
}
} else {
/*
if (!strcmp(argv[2], "registerImage")) {
rc = cc_registerImage(argv[3], env, stub);
if (rc != 0) {
printf("cc_registerImage() failed: in:%s out:%d\n", argv[3], rc);
exit(1);
}
*/
if (!strcmp(argv[2], "runInstances")) {
char *amiId=NULL, *amiURL=NULL, *kernelId=NULL, *kernelURL=NULL, *ramdiskId=NULL, *ramdiskURL=NULL;
if (argv[3]) amiId = argv[3];
if (argv[4]) amiURL = argv[4];
if (argv[5]) kernelId = argv[5];
if (argv[6]) kernelURL = argv[6];
if (argv[10]) ramdiskId = argv[10];
if (argv[11]) ramdiskURL = argv[11];
rc = cc_runInstances(amiId, amiURL, kernelId, kernelURL, ramdiskId, ramdiskURL, atoi(argv[7]), atoi(argv[8]), argv[9], env, stub);
if (rc != 0) {
printf("cc_runInstances() failed: in:%s out:%d\n", argv[4], rc);
exit(1);
}
} else if (!strcmp(argv[2], "describeInstances")) {
rc = cc_describeInstances(NULL, 0, env, stub);
if (rc != 0) {
printf("cc_describeInstances() failed\n");
exit(1);
}
} else if (!strcmp(argv[2], "getConsoleOutput")) {
rc = cc_getConsoleOutput(argv[3], env, stub);
if (rc != 0) {
printf("cc_getConsoleOutput() failed\n");
exit(1);
}
} else if (!strcmp(argv[2], "rebootInstances")) {
char *instIds[256];
if (argv[3] != NULL) {
instIds[0] = strdup(argv[3]);
}
rc = cc_rebootInstances(instIds, 1, env, stub);
if (rc != 0) {
printf("cc_rebootInstances() failed\n");
exit(1);
}
} else if (!strcmp(argv[2], "terminateInstances")) {
char *instIds[256];
i=3;
while (argv[i] != NULL) {
instIds[i-3] = strdup(argv[i]);
i++;
}
if ( (i-3) > 0) {
rc = cc_terminateInstances(instIds, i-3, env, stub);
if (rc != 0) {
printf("cc_terminateInstances() failed\n");
exit(1);
}
}
} else if (!strcmp(argv[2], "describeResources")) {
rc = cc_describeResources(env, stub);
if (rc != 0) {
printf("cc_describeResources() failed\n");
exit(1);
}
} else if (!strcmp(argv[2], "startNetwork")) {
rc = cc_startNetwork(atoi(argv[3]), argv[4], env, stub);
if (rc != 0) {
printf("cc_startNetwork() failed\n");
exit(1);
}
} else if (!strcmp(argv[2], "configureNetwork")) {
rc = cc_configureNetwork(argv[3], argv[4], argv[5], atoi(argv[6]), atoi(argv[7]), argv[8], env, stub);
if (rc != 0) {
printf("cc_configureNetwork() failed\n");
exit(1);
}
} else if (!strcmp(argv[2], "stopNetwork")) {
rc = cc_stopNetwork(atoi(argv[3]), argv[4], env, stub);
if (rc != 0) {
printf("cc_stopNetwork() failed\n");
exit(1);
}
} else if (!strcmp(argv[2], "assignAddress")) {
rc = cc_assignAddress(argv[3], argv[4], env, stub);
if (rc != 0) {
printf("cc_assignNetwork() failed\n");
exit(1);
}
} else if (!strcmp(argv[2], "unassignAddress")) {
rc = cc_unassignAddress(argv[3], argv[4], env, stub);
if (rc != 0) {
printf("cc_unassignNetwork() failed\n");
exit(1);
}
} else if (!strcmp(argv[2], "describePublicAddresses")) {
rc = cc_describePublicAddresses(env, stub);
if (rc != 0) {
printf("cc_describePublicAddresses() failed\n");
exit(1);
}
} else if (!strcmp(argv[2], "killallInstances")) {
rc = cc_killallInstances(env, stub);
if (rc != 0) {
printf("cc_killallInstances() failed\n");
exit(1);
}
}
}
exit(0);
}
|