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