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