Skip to content
Newer
Older
100644 551 lines (475 sloc) 19.5 KB
df1fb37 @gholms Update GPL file headers
gholms authored Jul 17, 2012
1 /*************************************************************************
2 * Copyright 2009-2012 Eucalyptus Systems, Inc.
3 *
4 * This program 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; version 3 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see http://www.gnu.org/licenses/.
15 *
16 * Please contact Eucalyptus Systems, Inc., 6755 Hollister Ave., Goleta
17 * CA 93117, USA or visit http://www.eucalyptus.com/licenses/ if you need
18 * additional information or have any questions.
47b5fb5 @gholms Tweak GPL headers
gholms authored Jul 25, 2012
19 *
20 * This file may incorporate work covered under the following copyright
21 * and permission notice:
22 *
23 * Software License Agreement (BSD License)
24 *
25 * Copyright (c) 2008, Regents of the University of California
26 * All rights reserved.
27 *
28 * Redistribution and use of this software in source and binary forms,
29 * with or without modification, are permitted provided that the
30 * following conditions are met:
31 *
32 * Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following disclaimer.
34 *
35 * Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer
37 * in the documentation and/or other materials provided with the
38 * distribution.
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
43 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
44 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
45 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
46 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
48 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
50 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
51 * POSSIBILITY OF SUCH DAMAGE. USERS OF THIS SOFTWARE ACKNOWLEDGE
52 * THE POSSIBLE PRESENCE OF OTHER OPEN SOURCE LICENSED MATERIAL,
53 * COPYRIGHTED MATERIAL OR PATENTED MATERIAL IN THIS SOFTWARE,
54 * AND IF ANY SUCH MATERIAL IS DISCOVERED THE PARTY DISCOVERING
55 * IT MAY INFORM DR. RICH WOLSKI AT THE UNIVERSITY OF CALIFORNIA,
56 * SANTA BARBARA WHO WILL THEN ASCERTAIN THE MOST APPROPRIATE REMEDY,
57 * WHICH IN THE REGENTS' DISCRETION MAY INCLUDE, WITHOUT LIMITATION,
58 * REPLACEMENT OF THE CODE SO IDENTIFIED, LICENSING OF THE CODE SO
59 * IDENTIFIED, OR WITHDRAWAL OF THE CODE CAPABILITY TO THE EXTENT
60 * NEEDED TO COMPLY WITH ANY SUCH LICENSES OR RIGHTS.
df1fb37 @gholms Update GPL file headers
gholms authored Jul 18, 2012
61 ************************************************************************/
005ae59 fake cc
Daniel Nurmi authored Aug 20, 2011
62
63 #include <stdio.h>
64 #include <stdlib.h>
65 #include <string.h>
66
67 #define HANDLERS_FANOUT
68 #include "handlers.h"
69 #include "client-marshal.h"
70
71 #include <fcntl.h> /* For O_* constants */
72 #include <sys/stat.h> /* For mode constants */
73 #include <semaphore.h>
74 #include <sys/mman.h>
75 #include <sys/stat.h> /* For mode constants */
76 #include <fcntl.h> /* For O_* constants */
77
78
79 enum {SHARED_MEM, SHARED_FILE};
80 #define MAX_FAKE_INSTANCES 4096
81
82 typedef struct fakeconfig_t {
83 ncInstance global_instances[MAX_FAKE_INSTANCES];
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
84 ncResource res;
85 time_t current, last;
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
86 } fakeconfig;
87 fakeconfig *myconfig;
88 sem_t *fakelock;
89
90 void saveNcStuff() {
91 int fd, i, done=0;
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
92
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
93 sem_post(fakelock);
94 }
95
96 int setup_shared_buffer_fake(void **buf, char *bufname, size_t bytes, sem_t **lock, char *lockname, int mode) {
97 int shd, rc, ret;
98
99 // create a lock and grab it
100 *lock = sem_open(lockname, O_CREAT, 0644, 1);
101 sem_wait(*lock);
102 ret=0;
103
104 if (mode == SHARED_MEM) {
105 // set up shared memory segment for config
106 shd = shm_open(bufname, O_CREAT | O_RDWR | O_EXCL, 0644);
107 if (shd >= 0) {
108 // if this is the first process to create the config, init to 0
109 rc = ftruncate(shd, bytes);
110 } else {
111 shd = shm_open(bufname, O_CREAT | O_RDWR, 0644);
112 }
113 if (shd < 0) {
114 fprintf(stderr, "cannot initialize shared memory segment\n");
115 sem_post(*lock);
116 sem_close(*lock);
117 return(1);
118 }
119 *buf = mmap(0, bytes, PROT_READ | PROT_WRITE, MAP_SHARED, shd, 0);
120 } else if (mode == SHARED_FILE) {
121 char *tmpstr, path[MAX_PATH];
122 struct stat mystat;
123 int fd;
124
125 tmpstr = getenv(EUCALYPTUS_ENV_VAR_NAME);
126 if (!tmpstr) {
59bc3e0 @a13m Remove hard-coded paths from C and Java code
a13m authored Sep 11, 2012
127 snprintf(path, MAX_PATH, EUCALYPTUS_KEYS_DIR "/CC/%s", bufname);
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
128 } else {
59bc3e0 @a13m Remove hard-coded paths from C and Java code
a13m authored Sep 12, 2012
129 snprintf(path, MAX_PATH, EUCALYPTUS_KEYS_DIR "/CC/%s", tmpstr, bufname);
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
130 }
131 fd = open(path, O_RDWR | O_CREAT, 0600);
132 if (fd<0) {
133 fprintf(stderr, "ERROR: cannot open/create '%s' to set up mmapped buffer\n", path);
134 ret = 1;
135 } else {
136 mystat.st_size = 0;
137 rc = fstat(fd, &mystat);
138 // this is the check to make sure we're dealing with a valid prior config
139 if (mystat.st_size != bytes) {
140 rc = ftruncate(fd, bytes);
141 }
142 *buf = mmap(NULL, bytes, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
143 if (*buf == NULL) {
144 fprintf(stderr, "ERROR: cannot mmap fd\n");
145 ret = 1;
146 }
147 close(fd);
148 }
149 }
150 sem_post(*lock);
151 return(ret);
152 }
153
154 void loadNcStuff() {
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
155 int fd, i, count=0, done=0, rc, j;
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
156 struct stat mystat;
157
158 rc = setup_shared_buffer_fake((void **)&myconfig, "/eucalyptusCCfakeconfig", sizeof(fakeconfig), &fakelock, "/eucalyptusCCfakelock", SHARED_FILE);
159 if (rc) {
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
160 logprintfl(EUCADEBUG, "fakeNC: error setting up shared mem\n");
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
161 }
162 sem_wait(fakelock);
163
164 done=0;
165 for (i=0; i<MAX_FAKE_INSTANCES && !done; i++) {
166 if (!strlen(myconfig->global_instances[i].instanceId)) {
167 count = i;
168 done++;
169 }
170 }
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
171
172 if (myconfig->last == 0) {
173 myconfig->last = time(NULL);
174 myconfig->current = time(NULL);
175 } else {
176 myconfig->current = time(NULL);
177 }
178 logprintfl(EUCADEBUG, "fakeNC: setup(): last=%d current=%d\n", myconfig->last, myconfig->current);
179 if ( (myconfig->current - myconfig->last) > 30 ) {
180 // do a refresh
181 myconfig->last = time(NULL);
182 myconfig->current = time(NULL);
183 for (i=0; i<MAX_FAKE_INSTANCES; i++) {
184 if (strlen(myconfig->global_instances[i].instanceId)) {
185
0db116c fix to RT: #6467 CC: metadata redirect is not re-applied in non HA mo…
Daniel Nurmi authored Mar 27, 2012
186 if (!strcmp(myconfig->global_instances[i].stateName, "Teardown") && ((time(NULL) - myconfig->global_instances[i].launchTime) > 300) ) {
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
187 logprintfl(EUCADEBUG, "fakeNC: setup(): invalidating instance %s\n", myconfig->global_instances[i].instanceId);
188 bzero(&(myconfig->global_instances[i]), sizeof(ncInstance));
189 } else {
190 for (j=0; j<EUCA_MAX_VOLUMES; j++) {
191 if (strlen(myconfig->global_instances[i].volumes[j].volumeId) && strcmp(myconfig->global_instances[i].volumes[j].stateName, "attached")) {
192 logprintfl(EUCADEBUG, "fakeNC: setup(): invalidating volume %s\n", myconfig->global_instances[i].volumes[j].volumeId);
193 bzero(&(myconfig->global_instances[i].volumes[j]), sizeof(ncVolume));
194 }
195 }
196 }
197 }
198 }
199 }
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
200 }
201
202 ncStub * ncStubCreate (char *endpoint_uri, char *logfile, char *homedir)
203 {
204 axutil_env_t * env = NULL;
205 axis2_char_t * client_home;
206 axis2_stub_t * stub;
207 ncStub * st = NULL;
208
209 if ( logfile ) {
210 env = axutil_env_create_all (logfile, AXIS2_LOG_LEVEL_TRACE);
211 } else {
212 env = axutil_env_create_all (NULL, 0);
213 }
214 if ( homedir ) {
215 client_home = (axis2_char_t *)homedir;
216 } else {
217 client_home = AXIS2_GETENV("AXIS2C_HOME");
218 }
219
220 if (client_home == NULL) {
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
221 logprintfl (EUCAERROR, "fakeNC: ERROR: cannot get AXIS2C_HOME");
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
222 return NULL;
223 }
224 if (endpoint_uri == NULL) {
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
225 logprintfl (EUCAERROR, "fakeNC: ERROR: empty endpoint_url");
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
226 return NULL;
227 }
228
229 char * uri = endpoint_uri;
230
231 // extract node name from the endpoint
232 char * p = strstr (uri, "://"); // find "http[s]://..."
233 if (p==NULL) {
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
234 logprintfl (EUCAERROR, "fakeNC: ncStubCreate received invalid URI %s\n", uri);
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
235 return NULL;
236 }
237 char * node_name = strdup (p+3); // copy without the protocol prefix
238 if (node_name==NULL) {
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
239 logprintfl (EUCAERROR, "fakeNC: ncStubCreate is out of memory\n");
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
240 return NULL;
241 }
242 if ((p = strchr (node_name, ':')) != NULL) *p = '\0'; // cut off the port
243 if ((p = strchr (node_name, '/')) != NULL) *p = '\0'; // if there is no port
244
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
245 logprintfl (EUCADEBUG, "fakeNC: DEBUG: requested URI %s\n", uri);
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
246
c03a701 @dmitrii renaming VMwareBroker to Broker in a few places
dmitrii authored Apr 1, 2012
247 // see if we should redirect to a local broker
248 if (strstr (uri, "EucalyptusBroker")) {
249 uri = "http://localhost:8773/services/EucalyptusBroker";
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
250 logprintfl (EUCADEBUG, "fakeNC: DEBUG: redirecting request to %s\n", uri);
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
251 }
252
253 // TODO: what if endpoint_uri, home, or env are NULL?
254 stub = axis2_stub_create_EucalyptusNC(env, client_home, (axis2_char_t *)uri);
255
256 if (stub && (st = malloc (sizeof(ncStub)))) {
257 st->env=env;
258 st->client_home=strdup((char *)client_home);
259 st->endpoint_uri=(axis2_char_t *)strdup(endpoint_uri);
260 st->node_name=(axis2_char_t *)strdup(node_name);
261 st->stub=stub;
262 if (st->client_home == NULL || st->endpoint_uri == NULL) {
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
263 logprintfl (EUCAWARN, "fakeNC: WARNING: out of memory");
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
264 }
265 } else {
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
266 logprintfl (EUCAWARN, "fakeNC: WARNING: out of memory");
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
267 }
268
269 free (node_name);
270 return st;
271 }
272
273 int ncStubDestroy (ncStub * st)
274 {
275 free (st);
276 return (0);
277 }
278
279 /************************** stubs **************************/
280
ef16e57 latest merge from eee
Daniel Nurmi authored Aug 29, 2011
281 int ncRunInstanceStub (ncStub *st, ncMetadata *meta, char *uuid, char *instanceId, char *reservationId, virtualMachine *params, char *imageId, char *imageURL, char *kernelId, char *kernelURL, char *ramdiskId, char *ramdiskURL, char *ownerId, char *accountId, char *keyName, netConfig *netparams, char *userData, char *launchIndex, char *platform, int expiryTime, char **groupNames, int groupNamesSize, ncInstance **outInstPtr)
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
282 {
283 ncInstance *instance;
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
284 int i, j, foundidx=-1;
285
286 logprintfl(EUCADEBUG, "fakeNC: runInstance(): params: uuid=%s instanceId=%s reservationId=%s ownerId=%s accountId=%s platform=%s\n", SP(uuid), SP(instanceId), SP(reservationId), SP(ownerId), SP(accountId), SP(platform));
287
288 if (!uuid || !instanceId || !reservationId || !ownerId || !accountId || !platform || !meta || !netparams) {
289 logprintfl(EUCAERROR, "fakeNC: runInstance(): bad input params\n");
290 return(0);
291 }
292
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
293 loadNcStuff();
294
295 instance = allocate_instance (uuid,
296 instanceId,
297 reservationId,
298 params,
299 instance_state_names[PENDING],
300 PENDING,
301 meta->userId,
ef16e57 latest merge from eee
Daniel Nurmi authored Aug 29, 2011
302 ownerId, accountId,
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
303 netparams, keyName,
304 userData, launchIndex, platform, expiryTime, groupNames, groupNamesSize);
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
305 if (instance) {
0db116c fix to RT: #6467 CC: metadata redirect is not re-applied in non HA mo…
Daniel Nurmi authored Mar 27, 2012
306 instance->launchTime = time (NULL);
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
307 foundidx=-1;
308 for (i=0; i<MAX_FAKE_INSTANCES && (foundidx < 0); i++) {
309 if (!strlen(myconfig->global_instances[i].instanceId)) {
310 foundidx = i;
311 }
312 }
313 memcpy( &(myconfig->global_instances[foundidx]),instance, sizeof(ncInstance));
314 logprintfl(EUCADEBUG, "fakeNC: runInstance(): decrementing resource by %d/%d/%d\n", params->cores, params->mem, params->disk);
315 myconfig->res.memorySizeAvailable -= params->mem;
316 myconfig->res.numberOfCoresAvailable -= params->cores;
317 myconfig->res.diskSizeAvailable -= params->disk;
318
319 *outInstPtr = instance;
320 logprintfl(EUCADEBUG, "fakeNC: runInstance(): allocated and stored instance\n");
321 } else {
322 logprintfl(EUCAERROR, "fakeNC: runInstance(): failed to allocate instance\n");
323 }
324
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
325 saveNcStuff();
326 return(0);
327 }
328
329 int ncTerminateInstanceStub (ncStub *st, ncMetadata *meta, char *instanceId, int force, int *shutdownState, int *previousState)
330 {
331 int i, done=0;
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
332
333 logprintfl(EUCADEBUG, "fakeNC: terminateInstance(): params: instanceId=%s force=%d\n", SP(instanceId), force);
334
335 if (!instanceId) {
336 logprintfl(EUCAERROR, "fakeNC: termianteInstance(): bad input params\n");
337 return(0);
338 }
339
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
340 loadNcStuff();
341
342 for (i=0; i<MAX_FAKE_INSTANCES && !done; i++) {
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
343 if (!strcmp(myconfig->global_instances[i].instanceId, instanceId)) {
0db116c fix to RT: #6467 CC: metadata redirect is not re-applied in non HA mo…
Daniel Nurmi authored Mar 27, 2012
344 logprintfl(EUCADEBUG, "fakeNC: terminateInstance():\tsetting stateName for instance %s at idx %d\n", instanceId, i);
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
345 snprintf(myconfig->global_instances[i].stateName, 10, "Teardown");
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
346 myconfig->res.memorySizeAvailable += myconfig->global_instances[i].params.mem;
347 myconfig->res.numberOfCoresAvailable += myconfig->global_instances[i].params.cores;
348 myconfig->res.diskSizeAvailable += myconfig->global_instances[i].params.disk;
349 done++;
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
350 }
351 }
352
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
353 if (shutdownState && previousState) {
354 *shutdownState = *previousState = 0;
355 }
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
356
357 saveNcStuff();
358 return(0);
359 }
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
360
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
361 int ncAssignAddressStub (ncStub *st, ncMetadata *meta, char *instanceId, char *publicIp){
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
362 int i, done=0;
363
364 logprintfl(EUCADEBUG, "fakeNC: assignAddress(): params: instanceId=%s publicIp=%s\n", SP(instanceId), SP(publicIp));
365 if (!instanceId || !publicIp) {
366 logprintfl(EUCADEBUG, "fakeNC: assignAddress(): bad input params\n");
367 return(0);
368 }
369
370 loadNcStuff();
371
372 for (i=0; i<MAX_FAKE_INSTANCES && !done; i++) {
373 if (!strcmp(myconfig->global_instances[i].instanceId, instanceId)) {
374 logprintfl(EUCADEBUG, "fakeNC: assignAddress()\tsetting publicIp at idx %d\n", i);
375 snprintf(myconfig->global_instances[i].ncnet.publicIp, 24, "%s", publicIp);
376 done++;
377 }
378 }
379
380 saveNcStuff();
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
381 return(0);
382 }
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
383
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
384 int ncPowerDownStub (ncStub *st, ncMetadata *meta){
385 return(0);
386 }
387
388 int ncDescribeInstancesStub (ncStub *st, ncMetadata *meta, char **instIds, int instIdsLen, ncInstance ***outInsts, int *outInstsLen)
389 {
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
390 int i, numinsts=0;
391 logprintfl(EUCADEBUG, "fakeNC: describeInstances(): params: instIdsLen=%d\n", instIdsLen);
392
393 if (instIdsLen < 0) {
394 logprintfl(EUCAERROR, "fakeNC: describeInstances(): bad input params\n");
395 return(0);
396 }
397
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
398 loadNcStuff();
399
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
400 // *outInstsLen = myconfig->instanceidx+1;
401 *outInsts = malloc (sizeof(ncInstance *) * MAX_FAKE_INSTANCES);
402 for (i=0; i<MAX_FAKE_INSTANCES; i++) {
403 if (strlen(myconfig->global_instances[i].instanceId)) {
404 ncInstance *newinst;
405 newinst = malloc(sizeof(ncInstance));
406 if (!strcmp(myconfig->global_instances[i].stateName, "Pending")) {
407 snprintf(myconfig->global_instances[i].stateName, 8, "Extant");
408 }
409 memcpy(newinst, &(myconfig->global_instances[i]), sizeof(ncInstance));
410 (* outInsts)[numinsts] = newinst;
411 logprintfl(EUCADEBUG, "fakeNC: describeInstances(): idx=%d numinsts=%d instanceId=%s stateName=%s\n", i, numinsts, newinst->instanceId, newinst->stateName);
412 numinsts++;
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
413 }
414 }
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
415 *outInstsLen = numinsts;
416
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
417 saveNcStuff();
418 return(0);
419 }
420
421 int ncBundleInstanceStub (ncStub *stub, ncMetadata *meta, char *instanceId, char *bucketName, char *filePrefix, char *walrusURL, char *userPublicKey, char *S3Policy, char *S3PolicySig) {
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
422 return(ncTerminateInstanceStub(stub, meta, instanceId, 0, NULL, NULL));
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
423 }
424
2aa5bdd @gelinasc Fixes EUCA-2208
gelinasc authored Oct 4, 2012
425 int ncBundleRestartInstanceStub (ncStub *stub, ncMetadata *meta, char *instanceId) {
426 return(ncTerminateInstanceStub(stub, meta, instanceId, 0, NULL, NULL));
427 }
428
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
429 int ncCancelBundleTaskStub (ncStub *stub, ncMetadata *meta, char *instanceId) {
430 return(0);
431 }
432
433 int ncDescribeBundleTasksStub (ncStub *stub, ncMetadata *meta, char **instIds, int instIdsLen, bundleTask ***outBundleTasks, int *outBundleTasksLen) {
434 return(0);
435 }
436
437 int ncDescribeResourceStub (ncStub *st, ncMetadata *meta, char *resourceType, ncResource **outRes)
438 {
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
439 int ret=0;
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
440 ncResource *res;
441
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
442 loadNcStuff();
443
444 if (myconfig->res.memorySizeMax <= 0) {
445 // not initialized?
446 res = allocate_resource ("OK", "iqn.1993-08.org.debian:01:736a4e92c588", 1024000, 1024000, 30000000, 30000000, 4096, 4096, "none");
447 if (!res) {
448 logprintfl(EUCAERROR, "fakeNC: describeResource(): failed to allocate fake resource\n");
449 ret=1;
450 } else {
451 memcpy(&(myconfig->res), res, sizeof(ncResource));
452 free(res);
453 }
454 }
455
456 if (!ret) {
457 res = malloc(sizeof(ncResource));
458 memcpy(res, &(myconfig->res), sizeof(ncResource));
459 *outRes = res;
460 } else {
461 *outRes = NULL;
462 }
463
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
464 saveNcStuff();
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
465 return(ret);
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
466 }
467
468 int ncAttachVolumeStub (ncStub *stub, ncMetadata *meta, char *instanceId, char *volumeId, char *remoteDev, char *localDev)
469 {
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
470 int i, j, done=0, vdone=0, foundidx=-1;
471
472 logprintfl(EUCADEBUG, "fakeNC: attachVolume(): params: instanceId=%s volumeId=%s remoteDev=%s localDev=%s\n", SP(instanceId), SP(volumeId), SP(remoteDev), SP(localDev));
473 if (!instanceId || !volumeId || !remoteDev || !localDev) {
474 logprintfl(EUCADEBUG, "fakeNC: attachVolume(): bad input params\n");
475 return(0);
476 }
477
478 loadNcStuff();
479
480 for (i=0; i<MAX_FAKE_INSTANCES && !done; i++) {
481 if (!strcmp(myconfig->global_instances[i].instanceId, instanceId)) {
482 logprintfl(EUCADEBUG, "fakeNC: \tsetting volume info at idx %d\n", i);
483 vdone=0;
484 for (j=0; j<EUCA_MAX_VOLUMES; j++) {
485 if (!strlen(myconfig->global_instances[i].volumes[j].volumeId)) {
486 if (foundidx < 0) {
487 foundidx=j;
488 }
489 } else if (!strcmp(myconfig->global_instances[i].volumes[j].volumeId, volumeId)) {
490 vdone++;
491 }
492 }
493 if (!vdone && foundidx >= 0) {
494 logprintfl(EUCADEBUG, "fakeNC: \tfake attaching volume at idx %d\n", foundidx);
495 snprintf(myconfig->global_instances[i].volumes[foundidx].volumeId, CHAR_BUFFER_SIZE, "%s", volumeId);
496 snprintf(myconfig->global_instances[i].volumes[foundidx].remoteDev, CHAR_BUFFER_SIZE, "%s", remoteDev);
497 snprintf(myconfig->global_instances[i].volumes[foundidx].localDev, CHAR_BUFFER_SIZE, "%s", localDev);
498 snprintf(myconfig->global_instances[i].volumes[foundidx].localDevReal, CHAR_BUFFER_SIZE, "%s", localDev);
499 snprintf(myconfig->global_instances[i].volumes[foundidx].stateName, CHAR_BUFFER_SIZE, "%s", "attached");
500 }
501 done++;
502 }
503 }
504
505 saveNcStuff();
506 return (0);
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
507 }
508
509 int ncDetachVolumeStub (ncStub *stub, ncMetadata *meta, char *instanceId, char *volumeId, char *remoteDev, char *localDev, int force)
510 {
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
511 int i, j, done=0, vdone=0, foundidx=-1;
512
513 logprintfl(EUCADEBUG, "fakeNC: detachVolume(): params: instanceId=%s volumeId=%s remoteDev=%s localDev=%s\n", SP(instanceId), SP(volumeId), SP(remoteDev), SP(localDev));
514 if (!instanceId || !volumeId || !remoteDev || !localDev) {
515 logprintfl(EUCADEBUG, "fakeNC: detachVolume(): bad input params\n");
516 return(0);
517 }
518
519 loadNcStuff();
520
521 for (i=0; i<MAX_FAKE_INSTANCES && !done; i++) {
522 if (!strcmp(myconfig->global_instances[i].instanceId, instanceId)) {
523 logprintfl(EUCADEBUG, "fakeNC: \tsetting volume info at idx %d\n", i);
524 vdone=0;
525 for (j=0; j<EUCA_MAX_VOLUMES; j++) {
526 if (!strcmp(myconfig->global_instances[i].volumes[j].volumeId, volumeId)) {
527 foundidx=j;
528 }
529 }
530 if (foundidx >= 0) {
531 logprintfl(EUCADEBUG, "fakeNC: \tfake detaching volume at idx %d\n", foundidx);
532 snprintf(myconfig->global_instances[i].volumes[foundidx].stateName, CHAR_BUFFER_SIZE, "%s", "detached");
533 }
534 done++;
535 }
536 }
537
538 saveNcStuff();
539 return (0);
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
540 }
541
542 int ncCreateImageStub (ncStub *stub, ncMetadata *meta, char *instanceId, char *volumeId, char *remoteDev)
543 {
263f9ea little build reorg to make room for...the fake backend
Daniel Nurmi authored Aug 31, 2011
544 return(ncTerminateInstanceStub(stub, meta, instanceId, 0, NULL, NULL));
005ae59 fake cc
Daniel Nurmi authored Aug 21, 2011
545 }
e418678 @dmitrii sensor stub on the NC coded, but not tested
dmitrii authored Aug 3, 2012
546
ee23f20 @dmitrii added sensor_init and sensor_config, doing config via params to Descr…
dmitrii authored Aug 24, 2012
547 int ncDescribeSensorsStub (ncStub *st, ncMetadata *meta, int historySize, long long collectionIntervalTimeMs, char **instIds, int instIdsLen, char **sensorIds, int sensorIdsLen, sensorResource ***outResources, int *outResourcesLen)
e418678 @dmitrii sensor stub on the NC coded, but not tested
dmitrii authored Aug 4, 2012
548 {
549 return -1; // not supported
550 }
Something went wrong with that request. Please try again.