mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-06-18 06:48:09 +00:00
Server type in template preferences
This commit is contained in:
@ -10,6 +10,8 @@ import { DockerTemplate } from '../../../../models/templates/docker-template';
|
|||||||
import { DockerService } from '../../../../services/docker.service';
|
import { DockerService } from '../../../../services/docker.service';
|
||||||
import { DockerConfigurationService } from '../../../../services/docker-configuration.service';
|
import { DockerConfigurationService } from '../../../../services/docker-configuration.service';
|
||||||
import { DockerImage } from '../../../../models/docker/docker-image';
|
import { DockerImage } from '../../../../models/docker/docker-image';
|
||||||
|
import { ComputeService } from '../../../../services/compute.service';
|
||||||
|
import { Compute } from '../../../../models/compute';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -21,7 +23,6 @@ export class AddDockerTemplateComponent implements OnInit {
|
|||||||
server: Server;
|
server: Server;
|
||||||
dockerTemplate: DockerTemplate;
|
dockerTemplate: DockerTemplate;
|
||||||
consoleTypes: string[] = [];
|
consoleTypes: string[] = [];
|
||||||
isGns3VmChosen: boolean = false;
|
|
||||||
isRemoteComputerChosen: boolean = false;
|
isRemoteComputerChosen: boolean = false;
|
||||||
dockerImages: DockerImage[] = [];
|
dockerImages: DockerImage[] = [];
|
||||||
newImageSelected: boolean = false;
|
newImageSelected: boolean = false;
|
||||||
@ -29,6 +30,10 @@ export class AddDockerTemplateComponent implements OnInit {
|
|||||||
virtualMachineForm: FormGroup;
|
virtualMachineForm: FormGroup;
|
||||||
containerNameForm: FormGroup;
|
containerNameForm: FormGroup;
|
||||||
networkAdaptersForm: FormGroup;
|
networkAdaptersForm: FormGroup;
|
||||||
|
|
||||||
|
isGns3VmAvailable: boolean = false;
|
||||||
|
isGns3VmChosen: boolean = false;
|
||||||
|
isLocalComputerChosen: boolean = true;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
@ -38,7 +43,8 @@ export class AddDockerTemplateComponent implements OnInit {
|
|||||||
private router: Router,
|
private router: Router,
|
||||||
private formBuilder: FormBuilder,
|
private formBuilder: FormBuilder,
|
||||||
private templateMocksService: TemplateMocksService,
|
private templateMocksService: TemplateMocksService,
|
||||||
private configurationService: DockerConfigurationService
|
private configurationService: DockerConfigurationService,
|
||||||
|
private computeService: ComputeService
|
||||||
) {
|
) {
|
||||||
this.dockerTemplate = new DockerTemplate();
|
this.dockerTemplate = new DockerTemplate();
|
||||||
|
|
||||||
@ -65,14 +71,20 @@ export class AddDockerTemplateComponent implements OnInit {
|
|||||||
this.templateMocksService.getDockerTemplate().subscribe((dockerTemplate: DockerTemplate) => {
|
this.templateMocksService.getDockerTemplate().subscribe((dockerTemplate: DockerTemplate) => {
|
||||||
this.dockerTemplate = dockerTemplate;
|
this.dockerTemplate = dockerTemplate;
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.computeService.getComputes(server).subscribe((computes: Compute[]) => {
|
||||||
|
if (computes.filter(compute => compute.compute_id === 'vm').length > 0) this.isGns3VmAvailable = true;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setServerType(serverType: string) {
|
setServerType(serverType: string) {
|
||||||
if (serverType === 'gns3 vm') {
|
if (serverType === 'gns3 vm' && this.isGns3VmAvailable) {
|
||||||
this.isGns3VmChosen = true;
|
this.isGns3VmChosen = true;
|
||||||
|
this.isLocalComputerChosen = false;
|
||||||
} else {
|
} else {
|
||||||
this.isRemoteComputerChosen = true;
|
this.isGns3VmChosen = false;
|
||||||
|
this.isLocalComputerChosen = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,6 +102,7 @@ export class AddDockerTemplateComponent implements OnInit {
|
|||||||
this.dockerTemplate.image = this.virtualMachineForm.get('filename').value;
|
this.dockerTemplate.image = this.virtualMachineForm.get('filename').value;
|
||||||
this.dockerTemplate.name = this.containerNameForm.get('templateName').value;
|
this.dockerTemplate.name = this.containerNameForm.get('templateName').value;
|
||||||
this.dockerTemplate.adapters = this.networkAdaptersForm.get('adapters').value;
|
this.dockerTemplate.adapters = this.networkAdaptersForm.get('adapters').value;
|
||||||
|
this.dockerTemplate.compute_id = this.isGns3VmChosen ? 'vm' : 'local';
|
||||||
|
|
||||||
this.dockerService.addTemplate(this.server, this.dockerTemplate).subscribe((template: DockerTemplate) => {
|
this.dockerService.addTemplate(this.server, this.dockerTemplate).subscribe((template: DockerTemplate) => {
|
||||||
this.goBack();
|
this.goBack();
|
||||||
|
@ -6,6 +6,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="default-content">
|
<div class="default-content">
|
||||||
<mat-card class="matCard">
|
<mat-card class="matCard">
|
||||||
|
<mat-radio-group class="radio-group">
|
||||||
|
<mat-radio-button class="radio-button" value="1" (click)="setServerType('local')" checked>Run the VPCS node on your local computer</mat-radio-button>
|
||||||
|
<mat-radio-button [disabled]="!isGns3VmAvailable" class="radio-button" value="2" (click)="setServerType('gns3 vm')">Run the VPCS node on the GNS3 VM</mat-radio-button>
|
||||||
|
</mat-radio-group>
|
||||||
|
|
||||||
<form [formGroup]="templateNameForm">
|
<form [formGroup]="templateNameForm">
|
||||||
<mat-form-field class="form-field">
|
<mat-form-field class="form-field">
|
||||||
<input matInput formControlName="templateName" type="text" placeholder="Template name">
|
<input matInput formControlName="templateName" type="text" placeholder="Template name">
|
||||||
|
@ -8,6 +8,8 @@ import { ToasterService } from '../../../../services/toaster.service';
|
|||||||
import { v4 as uuid } from 'uuid';
|
import { v4 as uuid } from 'uuid';
|
||||||
import { TemplateMocksService } from '../../../../services/template-mocks.service';
|
import { TemplateMocksService } from '../../../../services/template-mocks.service';
|
||||||
import { FormGroup, FormBuilder, FormControl, Validators } from '@angular/forms';
|
import { FormGroup, FormBuilder, FormControl, Validators } from '@angular/forms';
|
||||||
|
import { ComputeService } from '../../../../services/compute.service';
|
||||||
|
import { Compute } from '../../../../models/compute';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -19,6 +21,10 @@ export class AddVpcsTemplateComponent implements OnInit {
|
|||||||
server: Server;
|
server: Server;
|
||||||
templateName: string = '';
|
templateName: string = '';
|
||||||
templateNameForm: FormGroup
|
templateNameForm: FormGroup
|
||||||
|
|
||||||
|
isGns3VmAvailable: boolean = false;
|
||||||
|
isGns3VmChosen: boolean = false;
|
||||||
|
isLocalComputerChosen: boolean = true;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
@ -27,7 +33,8 @@ export class AddVpcsTemplateComponent implements OnInit {
|
|||||||
private router: Router,
|
private router: Router,
|
||||||
private toasterService: ToasterService,
|
private toasterService: ToasterService,
|
||||||
private templateMocksService: TemplateMocksService,
|
private templateMocksService: TemplateMocksService,
|
||||||
private formBuilder: FormBuilder
|
private formBuilder: FormBuilder,
|
||||||
|
private computeService: ComputeService
|
||||||
) {
|
) {
|
||||||
this.templateNameForm = this.formBuilder.group({
|
this.templateNameForm = this.formBuilder.group({
|
||||||
templateName: new FormControl(null, [Validators.required])
|
templateName: new FormControl(null, [Validators.required])
|
||||||
@ -38,9 +45,23 @@ export class AddVpcsTemplateComponent implements OnInit {
|
|||||||
const server_id = this.route.snapshot.paramMap.get("server_id");
|
const server_id = this.route.snapshot.paramMap.get("server_id");
|
||||||
this.serverService.get(parseInt(server_id, 10)).then((server: Server) => {
|
this.serverService.get(parseInt(server_id, 10)).then((server: Server) => {
|
||||||
this.server = server;
|
this.server = server;
|
||||||
|
|
||||||
|
this.computeService.getComputes(server).subscribe((computes: Compute[]) => {
|
||||||
|
if (computes.filter(compute => compute.compute_id === 'vm').length > 0) this.isGns3VmAvailable = true;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setServerType(serverType: string) {
|
||||||
|
if (serverType === 'gns3 vm' && this.isGns3VmAvailable) {
|
||||||
|
this.isGns3VmChosen = true;
|
||||||
|
this.isLocalComputerChosen = false;
|
||||||
|
} else {
|
||||||
|
this.isGns3VmChosen = false;
|
||||||
|
this.isLocalComputerChosen = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
goBack() {
|
goBack() {
|
||||||
this.router.navigate(['/server', this.server.id, 'preferences', 'vpcs', 'templates']);
|
this.router.navigate(['/server', this.server.id, 'preferences', 'vpcs', 'templates']);
|
||||||
}
|
}
|
||||||
@ -57,6 +78,7 @@ export class AddVpcsTemplateComponent implements OnInit {
|
|||||||
|
|
||||||
vpcsTemplate.template_id = uuid(),
|
vpcsTemplate.template_id = uuid(),
|
||||||
vpcsTemplate.name = this.templateName,
|
vpcsTemplate.name = this.templateName,
|
||||||
|
vpcsTemplate.compute_id = this.isGns3VmChosen ? 'vm' : 'local';
|
||||||
|
|
||||||
this.vpcsService.addTemplate(this.server, vpcsTemplate).subscribe(() => {
|
this.vpcsService.addTemplate(this.server, vpcsTemplate).subscribe(() => {
|
||||||
this.goBack();
|
this.goBack();
|
||||||
|
Reference in New Issue
Block a user