From fb06398517339b0fd3e5a94f1a36c4be2c5161f3 Mon Sep 17 00:00:00 2001 From: Piotr Pekala Date: Tue, 17 Sep 2019 00:57:06 -0700 Subject: [PATCH] Configurator for VMware added --- src/app/app.module.ts | 7 +- .../config-action/config-action.component.ts | 3 +- .../vmware/configurator-vmware.component.html | 63 +++++++++++++++ .../vmware/configurator-vmware.component.ts | 80 +++++++++++++++++++ 4 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 src/app/components/project-map/node-editors/configurator/vmware/configurator-vmware.component.html create mode 100644 src/app/components/project-map/node-editors/configurator/vmware/configurator-vmware.component.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 30297819..6410bb63 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -223,6 +223,7 @@ import { ConfiguratorDialogQemuComponent } from './components/project-map/node-e import { ConfiguratorDialogCloudComponent } from './components/project-map/node-editors/configurator/cloud/configurator-cloud.component'; import { UdpTunnelsComponent } from './components/preferences/common/udp-tunnels/udp-tunnels.component'; import { ConfiguratorDialogAtmSwitchComponent } from './components/project-map/node-editors/configurator/atm_switch/configurator-atm-switch.component'; +import { ConfiguratorDialogVmwareComponent } from './components/project-map/node-editors/configurator/vmware/configurator-vmware.component'; if (environment.production) { Raven.config('https://b2b1cfd9b043491eb6b566fd8acee358@sentry.io/842726', { @@ -373,7 +374,8 @@ if (environment.production) { ConfiguratorDialogQemuComponent, ConfiguratorDialogCloudComponent, UdpTunnelsComponent, - ConfiguratorDialogAtmSwitchComponent + ConfiguratorDialogAtmSwitchComponent, + ConfiguratorDialogVmwareComponent ], imports: [ BrowserModule, @@ -481,7 +483,8 @@ if (environment.production) { ConfiguratorDialogVirtualBoxComponent, ConfiguratorDialogQemuComponent, ConfiguratorDialogCloudComponent, - ConfiguratorDialogAtmSwitchComponent + ConfiguratorDialogAtmSwitchComponent, + ConfiguratorDialogVmwareComponent ], bootstrap: [AppComponent] }) diff --git a/src/app/components/project-map/context-menu/actions/config-action/config-action.component.ts b/src/app/components/project-map/context-menu/actions/config-action/config-action.component.ts index 42712438..53621f68 100644 --- a/src/app/components/project-map/context-menu/actions/config-action/config-action.component.ts +++ b/src/app/components/project-map/context-menu/actions/config-action/config-action.component.ts @@ -10,6 +10,7 @@ import { ConfiguratorDialogVirtualBoxComponent } from '../../../node-editors/con import { ConfiguratorDialogQemuComponent } from '../../../node-editors/configurator/qemu/configurator-qemu.component'; import { ConfiguratorDialogCloudComponent } from '../../../node-editors/configurator/cloud/configurator-cloud.component'; import { ConfiguratorDialogAtmSwitchComponent } from '../../../node-editors/configurator/atm_switch/configurator-atm-switch.component'; +import { ConfiguratorDialogVmwareComponent } from '../../../node-editors/configurator/vmware/configurator-vmware.component'; @Component({ @@ -45,7 +46,7 @@ export class ConfigActionComponent { } else if (this.node.node_type === 'virtualbox') { this.dialogRef = this.dialog.open(ConfiguratorDialogVirtualBoxComponent, this.conf); } else if (this.node.node_type === 'vmware') { - + this.dialogRef = this.dialog.open(ConfiguratorDialogVmwareComponent, this.conf); } else if (this.node.node_type === 'docker') { } else if (this.node.node_type === 'nat') { diff --git a/src/app/components/project-map/node-editors/configurator/vmware/configurator-vmware.component.html b/src/app/components/project-map/node-editors/configurator/vmware/configurator-vmware.component.html new file mode 100644 index 00000000..c872e58a --- /dev/null +++ b/src/app/components/project-map/node-editors/configurator/vmware/configurator-vmware.component.html @@ -0,0 +1,63 @@ +

Configurator for node {{name}}

+ + + +
+ + +
diff --git a/src/app/components/project-map/node-editors/configurator/vmware/configurator-vmware.component.ts b/src/app/components/project-map/node-editors/configurator/vmware/configurator-vmware.component.ts new file mode 100644 index 00000000..707e36ff --- /dev/null +++ b/src/app/components/project-map/node-editors/configurator/vmware/configurator-vmware.component.ts @@ -0,0 +1,80 @@ +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 { VmwareConfigurationService } from '../../../../../services/vmware-configuration.service'; + + +@Component({ + selector: 'app-configurator-vmware', + templateUrl: './configurator-vmware.component.html', + styleUrls: ['../configurator.component.scss'] +}) +export class ConfiguratorDialogVmwareComponent implements OnInit { + server: Server; + node: Node; + name: string; + generalSettingsForm: FormGroup; + consoleTypes: string[] = []; + onCloseOptions = []; + + displayedColumns: string[] = ['adapter_number', 'port_name', 'adapter_type', 'actions']; + networkTypes = []; + + @ViewChild("customAdapters", {static: false}) customAdapters: CustomAdaptersTableComponent; + + constructor( + public dialogRef: MatDialogRef, + public nodeService: NodeService, + private toasterService: ToasterService, + private formBuilder: FormBuilder, + private vmwareConfigurationService: VmwareConfigurationService + ) { + this.generalSettingsForm = this.formBuilder.group({ + name: new FormControl('', Validators.required) + }); + } + + ngOnInit() { + this.nodeService.getNode(this.server, this.node).subscribe((node: Node) => { + this.node = node; + this.name = node.name; + this.getConfiguration(); + }) + } + + getConfiguration() { + this.consoleTypes = this.vmwareConfigurationService.getConsoleTypes(); + this.onCloseOptions = this.vmwareConfigurationService.getOnCloseoptions(); + this.networkTypes = this.vmwareConfigurationService.getNetworkTypes(); + } + + 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(); + } +}