1 import { Component, Input, OnChanges, OnInit } from '@angular/core';
2 import { Router } from '@angular/router';
3 import { NvmeofService } from '~/app/shared/api/nvmeof.service';
4 import { CriticalConfirmationModalComponent } from '~/app/shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
5 import { ActionLabelsI18n, URLVerbs } from '~/app/shared/constants/app.constants';
6 import { Icons } from '~/app/shared/enum/icons.enum';
7 import { CdTableAction } from '~/app/shared/models/cd-table-action';
8 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
9 import { FinishedTask } from '~/app/shared/models/finished-task';
10 import { NvmeofSubsystemNamespace } from '~/app/shared/models/nvmeof';
11 import { Permission } from '~/app/shared/models/permissions';
12 import { DimlessBinaryPipe } from '~/app/shared/pipes/dimless-binary.pipe';
13 import { IopsPipe } from '~/app/shared/pipes/iops.pipe';
14 import { MbpersecondPipe } from '~/app/shared/pipes/mbpersecond.pipe';
15 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
16 import { ModalCdsService } from '~/app/shared/services/modal-cds.service';
17 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
19 const BASE_URL = 'block/nvmeof/subsystems';
22 selector: 'cd-nvmeof-namespaces-list',
23 templateUrl: './nvmeof-namespaces-list.component.html',
24 styleUrls: ['./nvmeof-namespaces-list.component.scss']
26 export class NvmeofNamespacesListComponent implements OnInit, OnChanges {
30 namespacesColumns: any;
31 tableActions: CdTableAction[];
32 selection = new CdTableSelection();
33 permission: Permission;
34 namespaces: NvmeofSubsystemNamespace[];
37 public actionLabels: ActionLabelsI18n,
38 private router: Router,
39 private modalService: ModalCdsService,
40 private authStorageService: AuthStorageService,
41 private taskWrapper: TaskWrapperService,
42 private nvmeofService: NvmeofService,
43 private dimlessBinaryPipe: DimlessBinaryPipe,
44 private mbPerSecondPipe: MbpersecondPipe,
45 private iopsPipe: IopsPipe
47 this.permission = this.authStorageService.getPermissions().nvmeof;
51 this.namespacesColumns = [
57 name: $localize`Bdev Name`,
61 name: $localize`Pool `,
62 prop: 'rbd_pool_name',
66 name: $localize`Image`,
67 prop: 'rbd_image_name',
71 name: $localize`Image Size`,
72 prop: 'rbd_image_size',
73 pipe: this.dimlessBinaryPipe
76 name: $localize`Block Size`,
78 pipe: this.dimlessBinaryPipe
81 name: $localize`IOPS`,
82 prop: 'rw_ios_per_second',
88 name: $localize`R/W Throughput`,
89 prop: 'rw_mbytes_per_second',
91 pipe: this.mbPerSecondPipe,
95 name: $localize`Read Throughput`,
96 prop: 'r_mbytes_per_second',
98 pipe: this.mbPerSecondPipe,
102 name: $localize`Write Throughput`,
103 prop: 'w_mbytes_per_second',
105 pipe: this.mbPerSecondPipe,
109 name: $localize`Load Balancing Group`,
110 prop: 'load_balancing_group',
114 this.tableActions = [
116 name: this.actionLabels.CREATE,
117 permission: 'create',
120 this.router.navigate([
122 { outlets: { modal: [URLVerbs.CREATE, this.subsystemNQN, 'namespace'] } }
124 canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
127 name: this.actionLabels.EDIT,
128 permission: 'update',
131 this.router.navigate([
135 modal: [URLVerbs.EDIT, this.subsystemNQN, 'namespace', this.selection.first().nsid]
141 name: this.actionLabels.DELETE,
142 permission: 'delete',
144 click: () => this.deleteSubsystemModal()
150 this.listNamespaces();
153 updateSelection(selection: CdTableSelection) {
154 this.selection = selection;
159 .listNamespaces(this.subsystemNQN)
160 .subscribe((res: NvmeofSubsystemNamespace[]) => {
161 this.namespaces = res;
165 deleteSubsystemModal() {
166 const namespace = this.selection.first();
167 this.modalService.show(CriticalConfirmationModalComponent, {
168 itemDescription: 'Namespace',
169 itemNames: [namespace.nsid],
170 actionDescription: 'delete',
171 submitActionObservable: () =>
172 this.taskWrapper.wrapTaskAroundCall({
173 task: new FinishedTask('nvmeof/namespace/delete', {
174 nqn: this.subsystemNQN,
177 call: this.nvmeofService.deleteNamespace(this.subsystemNQN, namespace.nsid)