mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-05-29 13:34:20 +00:00
Update import-appliance.component.ts
This commit is contained in:
parent
a704d0dcd0
commit
e965bc11e2
@ -1,7 +1,6 @@
|
||||
import { Component, Input, OnInit } from "@angular/core";
|
||||
import { Project } from '../../../models/project';
|
||||
import { Server } from '../../../models/server';
|
||||
import { ComputeService } from '../../../services/compute.service';
|
||||
import { ToasterService } from '../../../services/toaster.service';
|
||||
import { ServerResponse } from '../../../models/serverResponse';
|
||||
import { FileUploader, ParsedResponseHeaders, FileItem } from 'ng2-file-upload';
|
||||
@ -15,6 +14,7 @@ import { DockerService } from '../../../services/docker.service';
|
||||
import { QemuService } from '../../../services/qemu.service';
|
||||
import { IouService } from '../../../services/iou.service';
|
||||
import { IosService } from '../../../services/ios.service';
|
||||
import { TemplatePortalDirective } from '@angular/cdk/portal';
|
||||
|
||||
|
||||
@Component({
|
||||
@ -28,7 +28,6 @@ export class ImportApplianceComponent implements OnInit {
|
||||
uploader: FileUploader;
|
||||
|
||||
constructor(
|
||||
private computeService: ComputeService,
|
||||
private toasterService: ToasterService,
|
||||
private dockerService: DockerService,
|
||||
private qemuService: QemuService,
|
||||
@ -67,17 +66,46 @@ export class ImportApplianceComponent implements OnInit {
|
||||
fileReader.onloadend = () => {
|
||||
let appliance = JSON.parse(fileReader.result as string);
|
||||
let emulator: string;
|
||||
console.log(appliance);
|
||||
|
||||
if (appliance.qemu) {
|
||||
// option to select qemu image is missing
|
||||
template = new QemuTemplate();
|
||||
template.template_type = 'qemu';
|
||||
template.adapter_type = appliance.qemu.adapter_type;
|
||||
template.adapters = appliance.qemu.adapters;
|
||||
template.ram = appliance.qemu.ram;
|
||||
template.options = appliance.qemu.options;
|
||||
template.console_type = appliance.qemu.console_type;
|
||||
} else if (appliance.iou) {
|
||||
// option to choose IOU image is missing
|
||||
template = new IouTemplate();
|
||||
template.template_type = 'iou';
|
||||
template.console_type = appliance.iou.console_type;
|
||||
template.console_auto_start = appliance.iou.console_auto_start;
|
||||
template.ethernet_adapters = appliance.iou.ethernet_adapters;
|
||||
template.l1_keepalives = appliance.iou.l1_keepalives;
|
||||
template.nvram = appliance.iou.nvram;
|
||||
template.ram = appliance.iou.ram;
|
||||
template.serial_adapters = appliance.iou.serial_adapters;
|
||||
} else if (appliance.dynamips) {
|
||||
// option to choose IOS image is missing
|
||||
template = new IosTemplate();
|
||||
template.template_type = 'dynamips';
|
||||
template.platform = appliance.dynamips.platform;
|
||||
template.ram = appliance.dynamips.ram;
|
||||
template.nvram = appliance.dynamips.nvram;
|
||||
template.startup_config = appliance.dynamips.startup_config;
|
||||
template.wic0 = appliance.dynamips.wic0;
|
||||
template.wic1 = appliance.dynamips.wic1;
|
||||
template.wic2 = appliance.dynamips.wic2;
|
||||
template.slot0 = appliance.dynamips.slot0;
|
||||
template.slot1 = appliance.dynamips.slot1;
|
||||
template.slot2 = appliance.dynamips.slot2;
|
||||
template.slot3 = appliance.dynamips.slot3;
|
||||
template.slot4 = appliance.dynamips.slot4;
|
||||
template.slot5 = appliance.dynamips.slot5;
|
||||
template.slot6 = appliance.dynamips.slot6;
|
||||
template.slot7 = appliance.dynamips.slot7;
|
||||
} else if (appliance.docker) {
|
||||
template = new DockerTemplate();
|
||||
template.template_type = 'docker';
|
||||
@ -92,22 +120,27 @@ export class ImportApplianceComponent implements OnInit {
|
||||
template.category = appliance.category;
|
||||
template.builtin = false;
|
||||
template.default_name_format = '{name}-{0}';
|
||||
|
||||
//to exchange
|
||||
template.compute_id = "vm";
|
||||
// qemu - VM
|
||||
// iou - VM + main server
|
||||
// dynamips - vm + main server
|
||||
// docker - vm
|
||||
|
||||
if (template.category === 'guest') {
|
||||
template.symbol = `:/symbols/computer.svg`;
|
||||
} else {
|
||||
template.symbol = `:/symbols/${template.category}_guest.svg`;
|
||||
}
|
||||
console.log(template);
|
||||
|
||||
const url = this.computeService.getUploadPath(this.server, template.template_type, name);
|
||||
const url = this.getUploadPath(this.server, template.template_type, name);
|
||||
this.uploader.queue.forEach(elem => (elem.url = url));
|
||||
const itemToUpload = this.uploader.queue[0];
|
||||
this.uploader.uploadItem(itemToUpload);
|
||||
};
|
||||
fileReader.readAsText(file);
|
||||
}
|
||||
|
||||
getUploadPath(server: Server, emulator: string, filename: string) {
|
||||
return `http://${server.host}:${server.port}/v2/${emulator}/images/${filename}`;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user