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 { DeleteConfirmationModalComponent } from '~/app/shared/components/delete-confirmation-modal/delete-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'],
27 export class NvmeofNamespacesListComponent implements OnInit {
33 namespacesColumns: any;
34 tableActions: CdTableAction[];
35 selection = new CdTableSelection();
36 permission: Permission;
37 namespaces: NvmeofSubsystemNamespace[];
40 public actionLabels: ActionLabelsI18n,
41 private router: Router,
42 private modalService: ModalCdsService,
43 private authStorageService: AuthStorageService,
44 private taskWrapper: TaskWrapperService,
45 private nvmeofService: NvmeofService,
46 private dimlessBinaryPipe: DimlessBinaryPipe,
47 private mbPerSecondPipe: MbpersecondPipe,
48 private iopsPipe: IopsPipe
50 this.permission = this.authStorageService.getPermissions().nvmeof;
54 this.namespacesColumns = [
60 name: $localize`Bdev Name`,
64 name: $localize`Pool `,
65 prop: 'rbd_pool_name',
69 name: $localize`Image`,
70 prop: 'rbd_image_name',
74 name: $localize`Image Size`,
75 prop: 'rbd_image_size',
76 pipe: this.dimlessBinaryPipe
79 name: $localize`Block Size`,
81 pipe: this.dimlessBinaryPipe
84 name: $localize`IOPS`,
85 prop: 'rw_ios_per_second',
91 name: $localize`R/W Throughput`,
92 prop: 'rw_mbytes_per_second',
94 pipe: this.mbPerSecondPipe,
98 name: $localize`Read Throughput`,
99 prop: 'r_mbytes_per_second',
101 pipe: this.mbPerSecondPipe,
105 name: $localize`Write Throughput`,
106 prop: 'w_mbytes_per_second',
108 pipe: this.mbPerSecondPipe,
112 name: $localize`Load Balancing Group`,
113 prop: 'load_balancing_group',
117 this.tableActions = [
119 name: this.actionLabels.CREATE,
120 permission: 'create',
123 this.router.navigate(
124 [BASE_URL, { outlets: { modal: [URLVerbs.CREATE, this.subsystemNQN, 'namespace'] } }],
125 { queryParams: { group: this.group } }
127 canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
130 name: this.actionLabels.EDIT,
131 permission: 'update',
134 this.router.navigate(
143 this.selection.first().nsid
148 { queryParams: { group: this.group } }
152 name: this.actionLabels.DELETE,
153 permission: 'delete',
155 click: () => this.deleteNamespaceModal()
160 updateSelection(selection: CdTableSelection) {
161 this.selection = selection;
166 .listNamespaces(this.subsystemNQN, this.group)
167 .subscribe((res: NvmeofSubsystemNamespace[]) => {
168 this.namespaces = res;
172 deleteNamespaceModal() {
173 const namespace = this.selection.first();
174 this.modalService.show(DeleteConfirmationModalComponent, {
175 itemDescription: 'Namespace',
176 itemNames: [namespace.nsid],
177 actionDescription: 'delete',
178 submitActionObservable: () =>
179 this.taskWrapper.wrapTaskAroundCall({
180 task: new FinishedTask('nvmeof/namespace/delete', {
181 nqn: this.subsystemNQN,
184 call: this.nvmeofService.deleteNamespace(this.subsystemNQN, namespace.nsid, this.group)