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