Basic implementation for qemu

This commit is contained in:
Piotr Pekala 2019-09-11 08:11:43 -07:00
parent 41707d6724
commit 8fe6a3d517
5 changed files with 289 additions and 5 deletions

View File

@ -219,6 +219,7 @@ import { PortsComponent } from './components/preferences/common/ports/ports.comp
import { ConfiguratorDialogSwitchComponent } from './components/project-map/node-editors/configurator/switch/configurator-switch.component';
import { ConfiguratorDialogVirtualBoxComponent } from './components/project-map/node-editors/configurator/virtualbox/configurator-virtualbox.component';
import { CustomAdaptersTableComponent } from './components/preferences/common/custom-adapters-table/custom-adapters-table.component';
import { ConfiguratorDialogQemuComponent } from './components/project-map/node-editors/configurator/qemu/configurator-qemu.component';
if (environment.production) {
Raven.config('https://b2b1cfd9b043491eb6b566fd8acee358@sentry.io/842726', {
@ -365,7 +366,8 @@ if (environment.production) {
PortsComponent,
ConfiguratorDialogSwitchComponent,
ConfiguratorDialogVirtualBoxComponent,
CustomAdaptersTableComponent
CustomAdaptersTableComponent,
ConfiguratorDialogQemuComponent
],
imports: [
BrowserModule,
@ -470,7 +472,8 @@ if (environment.production) {
ConfiguratorDialogEthernetHubComponent,
ConfiguratorDialogEthernetSwitchComponent,
ConfiguratorDialogSwitchComponent,
ConfiguratorDialogVirtualBoxComponent
ConfiguratorDialogVirtualBoxComponent,
ConfiguratorDialogQemuComponent
],
bootstrap: [AppComponent]
})

View File

@ -19,6 +19,36 @@ export class Properties {
vmname: string;
ports_mapping: PortsMapping[];
mappings: any;
bios_image: string;
bios_image_md5sum?: any;
boot_priority: string;
cdrom_image: string;
cdrom_image_md5sum?: any;
cpu_throttling: number;
cpus: number;
hda_disk_image: string;
hda_disk_image_md5sum: string;
hda_disk_interface: string;
hdb_disk_image: string;
hdb_disk_image_md5sum?: any;
hdb_disk_interface: string;
hdc_disk_image: string;
hdc_disk_image_md5sum?: any;
hdc_disk_interface: string;
hdd_disk_image: string;
hdd_disk_image_md5sum?: any;
hdd_disk_interface: string;
initrd: string;
initrd_md5sum?: any;
kernel_command_line: string;
kernel_image: string;
kernel_image_md5sum?: any;
legacy_networking: boolean;
mac_address: string;
options: string;
platform: string;
process_priority: string;
qemu_path: string;
}
export class Node {

View File

@ -7,6 +7,7 @@ import { ConfiguratorDialogEthernetHubComponent } from '../../../node-editors/co
import { ConfiguratorDialogEthernetSwitchComponent } from '../../../node-editors/configurator/ethernet-switch/configurator-ethernet-switch.component';
import { ConfiguratorDialogSwitchComponent } from '../../../node-editors/configurator/switch/configurator-switch.component';
import { ConfiguratorDialogVirtualBoxComponent } from '../../../node-editors/configurator/virtualbox/configurator-virtualbox.component';
import { ConfiguratorDialogQemuComponent } from '../../../node-editors/configurator/qemu/configurator-qemu.component';
@Component({
@ -38,7 +39,7 @@ export class ConfigActionComponent {
} else if (this.node.node_type === 'iou') {
} else if (this.node.node_type === 'qemu') {
this.dialogRef = this.dialog.open(ConfiguratorDialogQemuComponent, this.conf);
} else if (this.node.node_type === 'virtualbox') {
this.dialogRef = this.dialog.open(ConfiguratorDialogVirtualBoxComponent, this.conf);
} else if (this.node.node_type === 'vmware') {
@ -48,9 +49,9 @@ export class ConfigActionComponent {
} else if (this.node.node_type === 'nat') {
} else if (this.node.node_type === 'frame_relay_switch') {
this.dialogRef = this.dialog.open(ConfiguratorDialogSwitchComponent, this.conf);
this.dialogRef = this.dialog.open(ConfiguratorDialogSwitchComponent, this.conf); // to do
} else if (this.node.node_type === 'atm_switch') {
this.dialogRef = this.dialog.open(ConfiguratorDialogSwitchComponent, this.conf);
this.dialogRef = this.dialog.open(ConfiguratorDialogSwitchComponent, this.conf); // to do
} else if (this.node.node_type === 'traceng') {
}

View File

@ -0,0 +1,157 @@
<h1 mat-dialog-title>Configurator for node {{name}}</h1>
<div class="modal-form-container">
<div class="content">
<div class="default-content">
<mat-card class="matCard">
<mat-tab-group *ngIf="name">
<mat-tab label="General settings">
<br/><form [formGroup]="generalSettingsForm">
<mat-form-field class="form-field">
<input matInput type="text" formControlName="name" [(ngModel)]="node.name" placeholder="Name">
</mat-form-field>
</form>
<mat-form-field class="form-field">
<input matInput type="number" [(ngModel)]="node.properties.ram" placeholder="RAM">
</mat-form-field>
<mat-form-field class="form-field">
<input matInput type="number" [(ngModel)]="node.properties.cpus" placeholder="vCPUs">
</mat-form-field>
<mat-form-field class="form-field">
<mat-select placeholder="Qemu binary" [(ngModel)]="node.properties.qemu_path">
<mat-option *ngFor="let binary of binaries" [value]="binary.path">
{{binary.path}}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field class="form-field">
<mat-select placeholder="Boot priority" [(ngModel)]="node.properties.boot_priority">
<mat-option *ngFor="let priority of bootPriorities" [value]="priority[1]">
{{priority[0]}}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field class="form-field">
<mat-select placeholder="On close" [(ngModel)]="node.properties.on_close">
<mat-option *ngFor="let option of onCloseOptions" [value]="option[1]">
{{option[0]}}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field class="select">
<mat-select placeholder="Console type" [(ngModel)]="node.console_type">
<mat-option *ngFor="let type of consoleTypes" [value]="type">
{{type}}
</mat-option>
</mat-select>
</mat-form-field>
<mat-checkbox [(ngModel)]="node.properties.console_auto_start">
Auto start console
</mat-checkbox>
</mat-tab>
<mat-tab label="HDD">
<mat-card>
<mat-card-title></mat-card-title>
<mat-card-subtitle>
HDA (Primary Master)
</mat-card-subtitle>
<mat-card-content>
<mat-form-field class="form-field">
<input matInput [(ngModel)]="node.properties.hda_disk_image" placeholder="Disk image">
</mat-form-field>
<mat-form-field class="form-field">
<mat-select placeholder="Disk interface" [(ngModel)]="node.properties.hda_disk_interface">
<mat-option *ngFor="let interface of diskInterfaces" [value]="interface">
{{interface}}
</mat-option>
</mat-select>
</mat-form-field>
</mat-card-content>
</mat-card>
<mat-card>
<mat-card-title></mat-card-title>
<mat-card-subtitle>
HDB (Primary Slave)
</mat-card-subtitle>
<mat-card-content>
<mat-form-field class="form-field">
<input matInput [(ngModel)]="node.properties.hdb_disk_image" placeholder="Disk image">
</mat-form-field>
<mat-form-field class="form-field">
<mat-select placeholder="Disk interface" [(ngModel)]="node.properties.hdb_disk_interface">
<mat-option *ngFor="let interface of diskInterfaces" [value]="interface">
{{interface}}
</mat-option>
</mat-select>
</mat-form-field>
</mat-card-content>
</mat-card>
<mat-card>
<mat-card-title></mat-card-title>
<mat-card-subtitle>
HDC (Secondary Master)
</mat-card-subtitle>
<mat-card-content>
<mat-form-field class="form-field">
<input matInput [(ngModel)]="node.properties.hdc_disk_image" placeholder="Disk image">
</mat-form-field>
<mat-form-field class="form-field">
<mat-select placeholder="Disk interface" [(ngModel)]="node.properties.hdc_disk_interface">
<mat-option *ngFor="let interface of diskInterfaces" [value]="interface">
{{interface}}
</mat-option>
</mat-select>
</mat-form-field>
</mat-card-content>
</mat-card>
<mat-card>
<mat-card-title></mat-card-title>
<mat-card-subtitle>
HDD (Secondary Slave)
</mat-card-subtitle>
<mat-card-content>
<mat-form-field class="form-field">
<input matInput [(ngModel)]="node.properties.hdd_disk_image" placeholder="Disk image">
</mat-form-field>
<mat-form-field class="form-field">
<mat-select placeholder="Disk interface" [(ngModel)]="node.properties.hdd_disk_interface">
<mat-option *ngFor="let interface of diskInterfaces" [value]="interface">
{{interface}}
</mat-option>
</mat-select>
</mat-form-field>
</mat-card-content>
</mat-card>
</mat-tab>
<mat-tab label="CD/DVD">
</mat-tab>
<mat-tab label="Network">
<br/><mat-checkbox [(ngModel)]="node.properties.use_any_adapter">
Allow GNS3 to use any configured VirtualBox adapter
</mat-checkbox>
<app-custom-adapters-table
#customAdapters
[networkTypes]="networkTypes"
[displayedColumns]="displayedColumns"
[adapters]="node.ports"
></app-custom-adapters-table>
</mat-tab>
<mat-tab label="Advanced">
</mat-tab>
<mat-tab label="Usage">
<mat-form-field class="form-field">
<textarea matInput type="text" [(ngModel)]="node.properties.usage"></textarea>
</mat-form-field>
</mat-tab>
</mat-tab-group>
</mat-card>
</div>
</div>
</div>
<div mat-dialog-actions>
<button mat-button (click)="onCancelClick()" color="accent">Cancel</button>
<button mat-button (click)="onSaveClick()" tabindex="2" mat-raised-button color="primary">Apply</button>
</div>

View File

@ -0,0 +1,93 @@
import { Component, OnInit, Input, ViewChild } from "@angular/core";
import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
import { Node } from '../../../../../cartography/models/node';
import { Server } from '../../../../../models/server';
import { NodeService } from '../../../../../services/node.service';
import { ToasterService } from '../../../../../services/toaster.service';
import { MatDialogRef } from '@angular/material';
import { CustomAdaptersTableComponent } from '../../../../../components/preferences/common/custom-adapters-table/custom-adapters-table.component';
import { QemuService } from '../../../../../services/qemu.service';
import { QemuConfigurationService } from '../../../../../services/qemu-configuration.service';
import { QemuBinary } from '../../../../../models/qemu/qemu-binary';
@Component({
selector: 'app-configurator-qemu',
templateUrl: './configurator-qemu.component.html',
styleUrls: ['../configurator.component.scss']
})
export class ConfiguratorDialogQemuComponent implements OnInit {
server: Server;
node: Node;
name: string;
generalSettingsForm: FormGroup;
consoleTypes: string[] = [];
binaries: QemuBinary[] = [];
onCloseOptions = [];
bootPriorities = [];
diskInterfaces: string[] = [];
displayedColumns: string[] = ['adapter_number', 'port_name', 'adapter_type', 'actions'];
networkTypes = [];
@ViewChild("customAdapters", {static: false}) customAdapters: CustomAdaptersTableComponent;
constructor(
public dialogRef: MatDialogRef<ConfiguratorDialogQemuComponent>,
public nodeService: NodeService,
private toasterService: ToasterService,
private formBuilder: FormBuilder,
private qemuService: QemuService,
private qemuConfigurationService: QemuConfigurationService
) {
this.generalSettingsForm = this.formBuilder.group({
name: new FormControl('', Validators.required),
ram: new FormControl('', Validators.required)
});
}
ngOnInit() {
this.nodeService.getNode(this.server, this.node).subscribe((node: Node) => {
this.node = node;
this.name = node.name;
this.getConfiguration();
})
this.qemuService.getBinaries(this.server).subscribe((qemuBinaries: QemuBinary[]) => {
this.binaries = qemuBinaries;
});
}
getConfiguration() {
this.consoleTypes = this.qemuConfigurationService.getConsoleTypes();
this.onCloseOptions = this.qemuConfigurationService.getOnCloseOptions();
this.networkTypes = this.qemuConfigurationService.getNetworkTypes();
this.bootPriorities = this.qemuConfigurationService.getBootPriorities();
this.diskInterfaces = this.qemuConfigurationService.getDiskInterfaces();
}
onSaveClick() {
if (this.generalSettingsForm.valid) {
this.node.custom_adapters = [];
this.customAdapters.adapters.forEach(n => {
this.node.custom_adapters.push({
adapter_number: n.adapter_number,
adapter_type: n.adapter_type
})
});
this.node.properties.adapters = this.node.custom_adapters.length;
this.nodeService.updateNodeWithCustomAdapters(this.server, this.node).subscribe(() => {
this.toasterService.success(`Node ${this.node.name} updated.`);
this.onCancelClick();
});
} else {
this.toasterService.error(`Fill all required fields.`);
}
}
onCancelClick() {
this.dialogRef.close();
}
}