98
100
snprintf (nc->virsh_cmd_path, MAX_PATH, EUCALYPTUS_VIRSH, nc->home);
99
101
snprintf (nc->xm_cmd_path, MAX_PATH, EUCALYPTUS_XM);
100
102
snprintf (nc->detach_cmd_path, MAX_PATH, EUCALYPTUS_DETACH, nc->home, nc->home);
101
snprintf (nc->connect_storage_cmd_path, MAX_PATH, EUCALYPTUS_CONNECT_ISCSI, nc->home, nc->home);
102
snprintf (nc->disconnect_storage_cmd_path, MAX_PATH, EUCALYPTUS_DISCONNECT_ISCSI, nc->home, nc->home);
103
snprintf (nc->get_storage_cmd_path, MAX_PATH, EUCALYPTUS_GET_ISCSI, nc->home, nc->home);
103
snprintf (nc->connect_storage_cmd_path, MAX_PATH, EUCALYPTUS_CONNECT_ISCSI, nc->home);
104
snprintf (nc->disconnect_storage_cmd_path, MAX_PATH, EUCALYPTUS_DISCONNECT_ISCSI, nc->home);
105
snprintf (nc->get_storage_cmd_path, MAX_PATH, EUCALYPTUS_GET_ISCSI, nc->home);
104
106
strcpy(nc->uri, HYPERVISOR_URI);
105
107
nc->convert_to_disk = 0;
280
282
ncMetadata *meta,
281
283
char *instanceId,
282
284
char **consoleOutput) {
284
int pid, status, rc, bufsize, fd;
285
char filename[MAX_PATH];
286
char *console_output=NULL, *console_append=NULL, *console_main=NULL;
287
char console_file[MAX_PATH];
291
int bufsize, pid, status;
293
*consoleOutput = NULL;
295
snprintf(console_file, 1024, "%s/%s/%s/console.append.log", scGetInstancePath(), meta->userId, instanceId);
296
rc = stat(console_file, &statbuf);
298
fd = open(console_file, O_RDONLY);
300
console_append = malloc(4096);
301
if (console_append) {
302
bzero(console_append, 4096);
303
rc = read(fd, console_append, (4096)-1);
287
310
if (getuid() != 0) {
288
output = strdup("NOT SUPPORTED");
311
console_main = strdup("NOT SUPPORTED");
290
313
fprintf(stderr, "strdup failed (out of memory?)\n");
314
if (console_append) free(console_append);
293
*consoleOutput = base64_enc((unsigned char *)output, strlen(output));
294
if (output) free(output);
298
319
bufsize = sizeof(char) * 1024 * 64;
299
output = malloc(bufsize);
300
bzero(output, bufsize);
320
console_main = malloc(bufsize);
322
logprintfl(EUCAERROR, "doGetConsoleOutput(): out of memory!\n");
323
if (console_append) free(console_append);
326
bzero(console_main, bufsize);
302
snprintf(filename, MAX_PATH, "/tmp/consoleOutput.%s", instanceId);
328
snprintf(console_file, MAX_PATH, "/tmp/consoleOutput.%s", instanceId);
307
fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, 0644);
333
fd = open(console_file, O_WRONLY | O_TRUNC | O_CREAT, 0644);
325
351
struct stat statbuf;
328
while(count < 10000 && stat(filename, &statbuf) < 0) {count++;}
329
fd = open(filename, O_RDONLY);
354
while(count < 10000 && stat(console_file, &statbuf) < 0) {count++;}
355
fd = open(console_file, O_RDONLY);
331
logprintfl (EUCAERROR, "ERROR: could not open consoleOutput file %s for reading\n", filename);
357
logprintfl (EUCAERROR, "ERROR: could not open consoleOutput file %s for reading\n", console_file);
334
360
FD_SET(fd, &rfds);
336
362
tv.tv_usec = 500000;
337
363
rc = select(1, &rfds, NULL, NULL, &tv);
338
bzero(output, bufsize);
364
bzero(console_main, bufsize);
342
368
while(rc && count < 1000) {
343
rc = read(fd, output, bufsize-1);
369
rc = read(fd, console_main, bufsize-1);
354
if (output[0] == '\0') {
355
snprintf(output, bufsize, "EMPTY");
358
*consoleOutput = base64_enc((unsigned char *)output, strlen(output));
378
unlink(console_file);
382
console_output = malloc( (64*1024) + 4096 );
383
if (console_output) {
384
bzero(console_output, (64*1024) + 4096 );
385
if (console_append) {
386
strncat(console_output, console_append, 4096);
389
strncat(console_output, console_main, 1024*64);
391
*consoleOutput = base64_enc((unsigned char *)console_output, strlen(console_output));
395
if (console_append) free(console_append);
396
if (console_main) free(console_main);
397
if (console_output) free(console_output);
404
442
/*get credentials, decrypt them*/
405
443
//parse_target(remoteDev);
406
444
/*login to target*/
407
if((local_iscsi_dev = connect_iscsi_target(nc->connect_storage_cmd_path, remoteDev)) == NULL)
409
snprintf (xml, 1024, "<disk type='block'><driver name='phy'/><source dev='%s'/><target dev='%s'/></disk>", local_iscsi_dev, localDevReal);
445
local_iscsi_dev = connect_iscsi_target(nc->connect_storage_cmd_path, remoteDev);
446
if (!local_iscsi_dev || !strstr(local_iscsi_dev, "/dev")) {
447
logprintfl(EUCAERROR, "AttachVolume(): failed to connect to iscsi target\n");
450
snprintf (xml, 1024, "<disk type='block'><driver name='phy'/><source dev='%s'/><target dev='%s'/></disk>", local_iscsi_dev, localDevReal);
411
453
snprintf (xml, 1024, "<disk type='block'><driver name='phy'/><source dev='%s'/><target dev='%s'/></disk>", remoteDev, localDevReal);
412
454
rc = stat(remoteDev, &statbuf);