]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/blob
2771725d5830a37b44f565984017e1899adbc915
[ceph-ci.git] /
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';
18
19 const BASE_URL = 'block/nvmeof/subsystems';
20
21 @Component({
22   selector: 'cd-nvmeof-namespaces-list',
23   templateUrl: './nvmeof-namespaces-list.component.html',
24   styleUrls: ['./nvmeof-namespaces-list.component.scss'],
25   standalone: false
26 })
27 export class NvmeofNamespacesListComponent implements OnInit {
28   @Input()
29   subsystemNQN: string;
30   @Input()
31   group: string;
32
33   namespacesColumns: any;
34   tableActions: CdTableAction[];
35   selection = new CdTableSelection();
36   permission: Permission;
37   namespaces: NvmeofSubsystemNamespace[];
38
39   constructor(
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
49   ) {
50     this.permission = this.authStorageService.getPermissions().nvmeof;
51   }
52
53   ngOnInit() {
54     this.namespacesColumns = [
55       {
56         name: $localize`ID`,
57         prop: 'nsid'
58       },
59       {
60         name: $localize`Bdev Name`,
61         prop: 'bdev_name'
62       },
63       {
64         name: $localize`Pool `,
65         prop: 'rbd_pool_name',
66         flexGrow: 2
67       },
68       {
69         name: $localize`Image`,
70         prop: 'rbd_image_name',
71         flexGrow: 3
72       },
73       {
74         name: $localize`Image Size`,
75         prop: 'rbd_image_size',
76         pipe: this.dimlessBinaryPipe
77       },
78       {
79         name: $localize`Block Size`,
80         prop: 'block_size',
81         pipe: this.dimlessBinaryPipe
82       },
83       {
84         name: $localize`IOPS`,
85         prop: 'rw_ios_per_second',
86         sortable: false,
87         pipe: this.iopsPipe,
88         flexGrow: 1.5
89       },
90       {
91         name: $localize`R/W Throughput`,
92         prop: 'rw_mbytes_per_second',
93         sortable: false,
94         pipe: this.mbPerSecondPipe,
95         flexGrow: 1.5
96       },
97       {
98         name: $localize`Read Throughput`,
99         prop: 'r_mbytes_per_second',
100         sortable: false,
101         pipe: this.mbPerSecondPipe,
102         flexGrow: 1.5
103       },
104       {
105         name: $localize`Write Throughput`,
106         prop: 'w_mbytes_per_second',
107         sortable: false,
108         pipe: this.mbPerSecondPipe,
109         flexGrow: 1.5
110       },
111       {
112         name: $localize`Load Balancing Group`,
113         prop: 'load_balancing_group',
114         flexGrow: 1.5
115       }
116     ];
117     this.tableActions = [
118       {
119         name: this.actionLabels.CREATE,
120         permission: 'create',
121         icon: Icons.add,
122         click: () =>
123           this.router.navigate(
124             [BASE_URL, { outlets: { modal: [URLVerbs.CREATE, this.subsystemNQN, 'namespace'] } }],
125             { queryParams: { group: this.group } }
126           ),
127         canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
128       },
129       {
130         name: this.actionLabels.EDIT,
131         permission: 'update',
132         icon: Icons.edit,
133         click: () =>
134           this.router.navigate(
135             [
136               BASE_URL,
137               {
138                 outlets: {
139                   modal: [
140                     URLVerbs.EDIT,
141                     this.subsystemNQN,
142                     'namespace',
143                     this.selection.first().nsid
144                   ]
145                 }
146               }
147             ],
148             { queryParams: { group: this.group } }
149           )
150       },
151       {
152         name: this.actionLabels.DELETE,
153         permission: 'delete',
154         icon: Icons.destroy,
155         click: () => this.deleteNamespaceModal()
156       }
157     ];
158   }
159
160   updateSelection(selection: CdTableSelection) {
161     this.selection = selection;
162   }
163
164   listNamespaces() {
165     this.nvmeofService
166       .listNamespaces(this.subsystemNQN, this.group)
167       .subscribe((res: NvmeofSubsystemNamespace[]) => {
168         this.namespaces = res;
169       });
170   }
171
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,
182             nsid: namespace.nsid
183           }),
184           call: this.nvmeofService.deleteNamespace(this.subsystemNQN, namespace.nsid, this.group)
185         })
186     });
187   }
188 }