mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-01-20 11:38:59 +00:00
start/stop/suspend/reload commands added
This commit is contained in:
parent
3f696a9200
commit
34a31449f3
@ -1,6 +1,10 @@
|
||||
import { Component, OnInit, AfterViewInit, OnDestroy, Input, ViewChild, ElementRef } from '@angular/core';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { ProjectWebServiceHandler } from '../../../handlers/project-web-service-handler';
|
||||
import { NodeService } from '../../../services/node.service';
|
||||
import { NodesDataSource } from '../../../cartography/datasources/nodes-datasource';
|
||||
import { Project } from '../../../models/project';
|
||||
import { Server } from '../../../models/server';
|
||||
|
||||
|
||||
@Component({
|
||||
@ -9,12 +13,21 @@ import { ProjectWebServiceHandler } from '../../../handlers/project-web-service-
|
||||
styleUrls: ['./log-console.component.scss']
|
||||
})
|
||||
export class LogConsoleComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
@Input() project: Project;
|
||||
@Input() server: Server;
|
||||
@ViewChild('console', {static: false}) console: ElementRef;
|
||||
private subscription: Subscription;
|
||||
command: string = '';
|
||||
|
||||
private regexStart: RegExp = /^start (.*?)$/;
|
||||
private regexStop: RegExp = /^stop (.*?)$/;
|
||||
private regexSuspend: RegExp = /^suspend (.*?)$/;
|
||||
private regexReload: RegExp = /^reload (.*?)$/;
|
||||
|
||||
constructor(
|
||||
private projectWebServiceHandler: ProjectWebServiceHandler
|
||||
private projectWebServiceHandler: ProjectWebServiceHandler,
|
||||
private nodeService: NodeService,
|
||||
private nodesDataSource: NodesDataSource
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
@ -41,6 +54,72 @@ export class LogConsoleComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
handleCommand() {
|
||||
if (this.command === 'start all') {
|
||||
this.showMessage("Starting all nodes...");
|
||||
this.nodeService.startAll(this.server, this.project).subscribe(() => {
|
||||
this.showMessage("All nodes started.")
|
||||
});
|
||||
} else if (this.command === 'stop all') {
|
||||
this.showMessage("Stopping all nodes...");
|
||||
this.nodeService.stopAll(this.server, this.project).subscribe(() => {
|
||||
this.showMessage("All nodes stopped.")
|
||||
});
|
||||
} else if (this.command === 'suspend all') {
|
||||
this.showMessage("Suspending all nodes...");
|
||||
this.nodeService.suspendAll(this.server, this.project).subscribe(() => {
|
||||
this.showMessage("All nodes suspended.")
|
||||
});
|
||||
} else if (this.command === 'reload all') {
|
||||
this.showMessage("Reloading all nodes...");
|
||||
this.nodeService.reloadAll(this.server, this.project).subscribe(() => {
|
||||
this.showMessage("All nodes reloaded.")
|
||||
});
|
||||
} else if (this.regexStart.test(this.command)) {
|
||||
let splittedCommand = this.command.split(/[ ,]+/);
|
||||
let node = this.nodesDataSource.getItems().find(n => {
|
||||
n.name.valueOf() === splittedCommand[1].valueOf();
|
||||
return n;
|
||||
});
|
||||
if (node) {
|
||||
this.showMessage(`Starting node ${splittedCommand[1]}...`);
|
||||
this.nodeService.start(this.server, node).subscribe(() => this.showMessage(`Node ${node.name} started.`));
|
||||
} else {
|
||||
this.showMessage(`Node with ${splittedCommand[1]} name was not found.`);
|
||||
}
|
||||
} else if (this.regexStop.test(this.command)) {
|
||||
let splittedCommand = this.command.split(/[ ,]+/);
|
||||
let node = this.nodesDataSource.getItems().find(n => {
|
||||
n.name.valueOf() === splittedCommand[1].valueOf();
|
||||
return n;
|
||||
});
|
||||
if (node) {
|
||||
this.showMessage(`Stopping node ${splittedCommand[1]}...`);
|
||||
this.nodeService.stop(this.server, node).subscribe(() => this.showMessage(`Node ${node.name} stopped.`));
|
||||
} else {
|
||||
this.showMessage(`Node with ${splittedCommand[1]} name was not found.`);
|
||||
}
|
||||
} else if (this.regexSuspend.test(this.command)) {
|
||||
let splittedCommand = this.command.split(/[ ,]+/);
|
||||
let node = this.nodesDataSource.getItems().find(n => {
|
||||
n.name.valueOf() === splittedCommand[1].valueOf();
|
||||
return n;
|
||||
});
|
||||
if (node) {
|
||||
this.showMessage(`Suspending node ${splittedCommand[1]}...`);
|
||||
this.nodeService.suspend(this.server, node).subscribe(() => this.showMessage(`Node ${node.name} stopped.`));
|
||||
} else {
|
||||
this.showMessage(`Node with ${splittedCommand[1]} name was not found.`);
|
||||
}
|
||||
} else if (this.regexReload.test(this.command)) {
|
||||
let splittedCommand = this.command.split(/[ ,]+/);
|
||||
let node = this.nodesDataSource.getItems().find(n => {
|
||||
n.name.valueOf() === splittedCommand[1].valueOf();
|
||||
return n;
|
||||
});
|
||||
if (node) {
|
||||
this.showMessage(`Reloading node ${splittedCommand[1]}...`);
|
||||
this.nodeService.reload(this.server, node).subscribe(() => this.showMessage(`Node ${node.name} reloaded.`));
|
||||
} else {
|
||||
this.showMessage(`Node with ${splittedCommand[1]} name was not found.`);
|
||||
}
|
||||
} else {
|
||||
this.showMessage(`Unknown syntax: ${this.command}`);
|
||||
}
|
||||
|
@ -120,4 +120,4 @@
|
||||
<app-node-label-dragged [server]="server"></app-node-label-dragged>
|
||||
<app-text-added [server]="server" [project]="project" (drawingSaved)="onDrawingSaved()"> </app-text-added>
|
||||
<app-text-edited [server]="server"></app-text-edited>
|
||||
<app-log-console></app-log-console>
|
||||
<app-log-console [server]="server" [project]="project"></app-log-console>
|
||||
|
@ -29,10 +29,18 @@ export class NodeService {
|
||||
return this.httpServer.post(server, `/projects/${project.project_id}/nodes/stop`, {});
|
||||
}
|
||||
|
||||
suspend(server: Server, node: Node) {
|
||||
return this.httpServer.post<Node>(server, `/projects/${node.project_id}/nodes/${node.node_id}/suspend`, {});
|
||||
}
|
||||
|
||||
suspendAll(server: Server, project: Project) {
|
||||
return this.httpServer.post(server, `/projects/${project.project_id}/nodes/suspend`, {});
|
||||
}
|
||||
|
||||
reload(server: Server, node: Node) {
|
||||
return this.httpServer.post<Node>(server, `/projects/${node.project_id}/nodes/${node.node_id}/reload`, {});
|
||||
}
|
||||
|
||||
reloadAll(server: Server, project: Project) {
|
||||
return this.httpServer.post(server, `/projects/${project.project_id}/nodes/reload`, {});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user