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