Fix for virtualbox

This commit is contained in:
Piotr Pekala 2019-09-11 04:58:45 -07:00
parent 838359b4ac
commit e904454623
5 changed files with 31 additions and 7 deletions

View File

@ -1,5 +1,6 @@
import { Label } from './label';
import { Port } from '../../models/port';
import { CustomAdapter } from '../../models/qemu/qemu-custom-adapter';
export class PortsMapping {
name: string;
@ -27,6 +28,7 @@ export class Node {
console_auto_start: boolean;
console_host: string;
console_type: string;
custom_adapters?: CustomAdapter[];
first_port_name: string;
height: number;
label: Label;

View File

@ -19,9 +19,7 @@ export class CustomAdaptersTableComponent {
adapter_number: this.adapters.length,
adapter_type: this.networkTypes[0]
}
this.adapters.push(adapter);
console.log(this.adapters);
this.adapters = [adapter];
this.adapters = this.adapters.concat([adapter]);
}
delete(adapter: CustomAdapter) {

View File

@ -6,7 +6,7 @@
<mat-card class="matCard">
<mat-tab-group *ngIf="name">
<mat-tab label="General settings">
<form [formGroup]="generalSettingsForm">
<br/><form [formGroup]="generalSettingsForm">
<mat-form-field class="form-field">
<input matInput formControlName="name" type="text" [(ngModel)]="node.name" placeholder="Name">
</mat-form-field>
@ -36,10 +36,11 @@
</mat-checkbox>
</mat-tab>
<mat-tab label="Network">
<mat-checkbox [(ngModel)]="node.properties.use_any_adapter">
<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"

View File

@ -1,4 +1,4 @@
import { Component, OnInit, Input } from "@angular/core";
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';
@ -6,6 +6,7 @@ import { NodeService } from '../../../../../services/node.service';
import { ToasterService } from '../../../../../services/toaster.service';
import { MatDialogRef } from '@angular/material';
import { VirtualBoxConfigurationService } from '../../../../../services/virtual-box-configuration.service';
import { CustomAdaptersTableComponent } from '../../../../../components/preferences/common/custom-adapters-table/custom-adapters-table.component';
@Component({
@ -25,6 +26,8 @@ export class ConfiguratorDialogVirtualBoxComponent implements OnInit {
displayedColumns: string[] = ['adapter_number', 'port_name', 'adapter_type', 'actions'];
networkTypes = [];
@ViewChild("customAdapters", {static: false}) customAdapters: CustomAdaptersTableComponent;
constructor(
public dialogRef: MatDialogRef<ConfiguratorDialogVirtualBoxComponent>,
public nodeService: NodeService,
@ -58,7 +61,17 @@ export class ConfiguratorDialogVirtualBoxComponent implements OnInit {
onSaveClick() {
if (this.generalSettingsForm.valid) {
this.nodeService.updateNode(this.server, this.node).subscribe(() => {
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();
});

View File

@ -94,6 +94,16 @@ export class NodeService {
});
}
updateNodeWithCustomAdapters(server: Server, node: Node): Observable<Node> {
return this.httpServer.put<Node>(server, `/projects/${node.project_id}/nodes/${node.node_id}`, {
console_type: node.console_type,
console_auto_start: node.console_auto_start,
custom_adapters: node.custom_adapters,
name: node.name,
properties: node.properties
});
}
delete(server: Server, node: Node) {
return this.httpServer.delete<Node>(server, `/projects/${node.project_id}/nodes/${node.node_id}`);
}