]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/mirroring/pool-list/pool-list.component.ts
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / block / mirroring / pool-list / pool-list.component.ts
CommitLineData
11fdf7f2 1import { Component, OnDestroy, OnInit, TemplateRef, ViewChild } from '@angular/core';
2a845540 2import { Router } from '@angular/router';
11fdf7f2 3
f67539c2 4import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
11fdf7f2
TL
5import { Observable, Subscriber, Subscription } from 'rxjs';
6
f67539c2
TL
7import { RbdMirroringService } from '~/app/shared/api/rbd-mirroring.service';
8import { TableStatusViewCache } from '~/app/shared/classes/table-status-view-cache';
9import { CriticalConfirmationModalComponent } from '~/app/shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
2a845540 10import { URLVerbs } from '~/app/shared/constants/app.constants';
f67539c2
TL
11import { Icons } from '~/app/shared/enum/icons.enum';
12import { CdTableAction } from '~/app/shared/models/cd-table-action';
13import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
14import { FinishedTask } from '~/app/shared/models/finished-task';
15import { Permission } from '~/app/shared/models/permissions';
16import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
17import { ModalService } from '~/app/shared/services/modal.service';
18import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
11fdf7f2
TL
19import { PoolEditPeerModalComponent } from '../pool-edit-peer-modal/pool-edit-peer-modal.component';
20
2a845540 21const BASE_URL = '/block/mirroring';
11fdf7f2
TL
22@Component({
23 selector: 'cd-mirroring-pools',
24 templateUrl: './pool-list.component.html',
25 styleUrls: ['./pool-list.component.scss']
26})
27export class PoolListComponent implements OnInit, OnDestroy {
9f95a23c 28 @ViewChild('healthTmpl', { static: true })
11fdf7f2 29 healthTmpl: TemplateRef<any>;
39ae355f
TL
30 @ViewChild('localTmpl', { static: true })
31 localTmpl: TemplateRef<any>;
32 @ViewChild('remoteTmpl', { static: true })
33 remoteTmpl: TemplateRef<any>;
11fdf7f2
TL
34
35 subs: Subscription;
36
37 permission: Permission;
38 tableActions: CdTableAction[];
39 selection = new CdTableSelection();
40
f67539c2 41 modalRef: NgbModalRef;
11fdf7f2
TL
42
43 data: [];
44 columns: {};
45
f67539c2
TL
46 tableStatus = new TableStatusViewCache();
47
11fdf7f2
TL
48 constructor(
49 private authStorageService: AuthStorageService,
50 private rbdMirroringService: RbdMirroringService,
f67539c2 51 private modalService: ModalService,
2a845540
TL
52 private taskWrapper: TaskWrapperService,
53 private router: Router
11fdf7f2
TL
54 ) {
55 this.data = [];
56 this.permission = this.authStorageService.getPermissions().rbdMirroring;
57
58 const editModeAction: CdTableAction = {
59 permission: 'update',
9f95a23c 60 icon: Icons.edit,
11fdf7f2 61 click: () => this.editModeModal(),
f67539c2 62 name: $localize`Edit Mode`,
11fdf7f2
TL
63 canBePrimary: () => true
64 };
65 const addPeerAction: CdTableAction = {
66 permission: 'create',
9f95a23c 67 icon: Icons.add,
f67539c2 68 name: $localize`Add Peer`,
11fdf7f2
TL
69 click: () => this.editPeersModal('add'),
70 disable: () => !this.selection.first() || this.selection.first().mirror_mode === 'disabled',
71 visible: () => !this.getPeerUUID(),
72 canBePrimary: () => false
73 };
74 const editPeerAction: CdTableAction = {
75 permission: 'update',
9f95a23c 76 icon: Icons.exchange,
f67539c2 77 name: $localize`Edit Peer`,
11fdf7f2
TL
78 click: () => this.editPeersModal('edit'),
79 visible: () => !!this.getPeerUUID()
80 };
81 const deletePeerAction: CdTableAction = {
82 permission: 'delete',
9f95a23c 83 icon: Icons.destroy,
f67539c2 84 name: $localize`Delete Peer`,
11fdf7f2
TL
85 click: () => this.deletePeersModal(),
86 visible: () => !!this.getPeerUUID()
87 };
88 this.tableActions = [editModeAction, addPeerAction, editPeerAction, deletePeerAction];
89 }
90
91 ngOnInit() {
92 this.columns = [
f67539c2
TL
93 { prop: 'name', name: $localize`Name`, flexGrow: 2 },
94 { prop: 'mirror_mode', name: $localize`Mode`, flexGrow: 2 },
95 { prop: 'leader_id', name: $localize`Leader`, flexGrow: 2 },
39ae355f
TL
96 {
97 prop: 'image_local_count',
98 name: $localize`# Local`,
99 headerTemplate: this.localTmpl,
100 flexGrow: 2
101 },
102 {
103 prop: 'image_remote_count',
104 name: $localize`# Remote`,
105 headerTemplate: this.remoteTmpl,
106 flexGrow: 2
107 },
11fdf7f2
TL
108 {
109 prop: 'health',
f67539c2 110 name: $localize`Health`,
11fdf7f2
TL
111 cellTemplate: this.healthTmpl,
112 flexGrow: 1
113 }
114 ];
115
f6b5b4d7 116 this.subs = this.rbdMirroringService.subscribeSummary((data) => {
11fdf7f2 117 this.data = data.content_data.pools;
f67539c2 118 this.tableStatus = new TableStatusViewCache(data.status);
11fdf7f2
TL
119 });
120 }
121
122 ngOnDestroy(): void {
123 this.subs.unsubscribe();
124 }
125
126 refresh() {
127 this.rbdMirroringService.refresh();
128 }
129
130 editModeModal() {
2a845540
TL
131 this.router.navigate([
132 BASE_URL,
133 { outlets: { modal: [URLVerbs.EDIT, this.selection.first().name] } }
134 ]);
11fdf7f2
TL
135 }
136
9f95a23c 137 editPeersModal(mode: string) {
11fdf7f2
TL
138 const initialState = {
139 poolName: this.selection.first().name,
140 mode: mode
141 };
142 if (mode === 'edit') {
143 initialState['peerUUID'] = this.getPeerUUID();
144 }
f67539c2 145 this.modalRef = this.modalService.show(PoolEditPeerModalComponent, initialState);
11fdf7f2
TL
146 }
147
148 deletePeersModal() {
149 const poolName = this.selection.first().name;
150 const peerUUID = this.getPeerUUID();
151
152 this.modalRef = this.modalService.show(CriticalConfirmationModalComponent, {
f67539c2
TL
153 itemDescription: $localize`mirror peer`,
154 itemNames: [`${poolName} (${peerUUID})`],
155 submitActionObservable: () =>
156 new Observable((observer: Subscriber<any>) => {
157 this.taskWrapper
158 .wrapTaskAroundCall({
159 task: new FinishedTask('rbd/mirroring/peer/delete', {
160 pool_name: poolName
161 }),
162 call: this.rbdMirroringService.deletePeer(poolName, peerUUID)
163 })
164 .subscribe({
165 error: (resp) => observer.error(resp),
166 complete: () => {
167 this.rbdMirroringService.refresh();
168 observer.complete();
169 }
170 });
171 })
11fdf7f2
TL
172 });
173 }
174
9f95a23c 175 getPeerUUID(): any {
11fdf7f2
TL
176 const selection = this.selection.first();
177 const pool = this.data.find((o) => selection && selection.name === o['name']);
178 if (pool && pool['peer_uuids']) {
179 return pool['peer_uuids'][0];
180 }
9f95a23c
TL
181
182 return undefined;
11fdf7f2
TL
183 }
184
185 updateSelection(selection: CdTableSelection) {
186 this.selection = selection;
187 }
188}