1 import { Component, Input, 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 {
32 namespacesColumns: any;
33 tableActions: CdTableAction[];
34 selection = new CdTableSelection();
35 permission: Permission;
36 namespaces: NvmeofSubsystemNamespace[];
39 public actionLabels: ActionLabelsI18n,
40 private router: Router,
41 private modalService: ModalCdsService,
42 private authStorageService: AuthStorageService,
43 private taskWrapper: TaskWrapperService,
44 private nvmeofService: NvmeofService,
45 private dimlessBinaryPipe: DimlessBinaryPipe,
46 private mbPerSecondPipe: MbpersecondPipe,
47 private iopsPipe: IopsPipe
49 this.permission = this.authStorageService.getPermissions().nvmeof;
53 this.namespacesColumns = [
59 name: $localize`Bdev Name`,
63 name: $localize`Pool `,
64 prop: 'rbd_pool_name',
68 name: $localize`Image`,
69 prop: 'rbd_image_name',
73 name: $localize`Image Size`,
74 prop: 'rbd_image_size',
75 pipe: this.dimlessBinaryPipe
78 name: $localize`Block Size`,
80 pipe: this.dimlessBinaryPipe
83 name: $localize`IOPS`,
84 prop: 'rw_ios_per_second',
90 name: $localize`R/W Throughput`,
91 prop: 'rw_mbytes_per_second',
93 pipe: this.mbPerSecondPipe,
97 name: $localize`Read Throughput`,
98 prop: 'r_mbytes_per_second',
100 pipe: this.mbPerSecondPipe,
104 name: $localize`Write Throughput`,
105 prop: 'w_mbytes_per_second',
107 pipe: this.mbPerSecondPipe,
111 name: $localize`Load Balancing Group`,
112 prop: 'load_balancing_group',
116 this.tableActions = [
118 name: this.actionLabels.CREATE,
119 permission: 'create',
122 this.router.navigate(
123 [BASE_URL, { outlets: { modal: [URLVerbs.CREATE, this.subsystemNQN, 'namespace'] } }],
124 { queryParams: { group: this.group } }
126 canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
129 name: this.actionLabels.EDIT,
130 permission: 'update',
133 this.router.navigate(
142 this.selection.first().nsid
147 { queryParams: { group: this.group } }
151 name: this.actionLabels.DELETE,
152 permission: 'delete',
154 click: () => this.deleteNamespaceModal()
159 updateSelection(selection: CdTableSelection) {
160 this.selection = selection;
165 .listNamespaces(this.subsystemNQN, this.group)
166 .subscribe((res: NvmeofSubsystemNamespace[]) => {
167 this.namespaces = res;
171 deleteNamespaceModal() {
172 const namespace = this.selection.first();
173 this.modalService.show(CriticalConfirmationModalComponent, {
174 itemDescription: 'Namespace',
175 itemNames: [namespace.nsid],
176 actionDescription: 'delete',
177 submitActionObservable: () =>
178 this.taskWrapper.wrapTaskAroundCall({
179 task: new FinishedTask('nvmeof/namespace/delete', {
180 nqn: this.subsystemNQN,
183 call: this.nvmeofService.deleteNamespace(this.subsystemNQN, namespace.nsid, this.group)