]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-snapshot-list/rbd-snapshot-actions.model.ts
import ceph quincy 17.2.4
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / block / rbd-snapshot-list / rbd-snapshot-actions.model.ts
1 import { RbdService } from '~/app/shared/api/rbd.service';
2 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
3 import { Icons } from '~/app/shared/enum/icons.enum';
4 import { CdTableAction } from '~/app/shared/models/cd-table-action';
5 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
6
7 export class RbdSnapshotActionsModel {
8 create: CdTableAction;
9 rename: CdTableAction;
10 protect: CdTableAction;
11 unprotect: CdTableAction;
12 clone: CdTableAction;
13 copy: CdTableAction;
14 rollback: CdTableAction;
15 deleteSnap: CdTableAction;
16 ordering: CdTableAction[];
17
18 cloneFormatVersion = 1;
19
20 constructor(
21 actionLabels: ActionLabelsI18n,
22 public featuresName: string[],
23 rbdService: RbdService
24 ) {
25 rbdService.cloneFormatVersion().subscribe((version: number) => {
26 this.cloneFormatVersion = version;
27 });
28
29 this.create = {
30 permission: 'create',
31 icon: Icons.add,
32 name: actionLabels.CREATE
33 };
34 this.rename = {
35 permission: 'update',
36 icon: Icons.edit,
37 name: actionLabels.RENAME,
38 disable: (selection: CdTableSelection) => this.disableForMirrorSnapshot(selection)
39 };
40 this.protect = {
41 permission: 'update',
42 icon: Icons.lock,
43 visible: (selection: CdTableSelection) =>
44 selection.hasSingleSelection && !selection.first().is_protected,
45 name: actionLabels.PROTECT,
46 disable: (selection: CdTableSelection) => this.disableForMirrorSnapshot(selection)
47 };
48 this.unprotect = {
49 permission: 'update',
50 icon: Icons.unlock,
51 visible: (selection: CdTableSelection) =>
52 selection.hasSingleSelection && selection.first().is_protected,
53 name: actionLabels.UNPROTECT,
54 disable: (selection: CdTableSelection) => this.disableForMirrorSnapshot(selection)
55 };
56 this.clone = {
57 permission: 'create',
58 canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
59 disable: (selection: CdTableSelection) =>
60 this.getCloneDisableDesc(selection, this.featuresName) ||
61 this.disableForMirrorSnapshot(selection),
62 icon: Icons.clone,
63 name: actionLabels.CLONE
64 };
65 this.copy = {
66 permission: 'create',
67 canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
68 disable: (selection: CdTableSelection) =>
69 !selection.hasSingleSelection ||
70 selection.first().cdExecuting ||
71 this.disableForMirrorSnapshot(selection),
72 icon: Icons.copy,
73 name: actionLabels.COPY
74 };
75 this.rollback = {
76 permission: 'update',
77 icon: Icons.undo,
78 name: actionLabels.ROLLBACK,
79 disable: (selection: CdTableSelection) => this.disableForMirrorSnapshot(selection)
80 };
81 this.deleteSnap = {
82 permission: 'delete',
83 icon: Icons.destroy,
84 disable: (selection: CdTableSelection) => {
85 const first = selection.first();
86 return (
87 !selection.hasSingleSelection ||
88 first.cdExecuting ||
89 first.is_protected ||
90 this.disableForMirrorSnapshot(selection)
91 );
92 },
93 name: actionLabels.DELETE
94 };
95
96 this.ordering = [
97 this.create,
98 this.rename,
99 this.protect,
100 this.unprotect,
101 this.clone,
102 this.copy,
103 this.rollback,
104 this.deleteSnap
105 ];
106 }
107
108 getCloneDisableDesc(selection: CdTableSelection, featuresName: string[]): boolean | string {
109 if (selection.hasSingleSelection && !selection.first().cdExecuting) {
110 if (!featuresName?.includes('layering')) {
111 return $localize`Parent image must support Layering`;
112 }
113
114 if (this.cloneFormatVersion === 1 && !selection.first().is_protected) {
115 return $localize`Snapshot must be protected in order to clone.`;
116 }
117
118 return false;
119 }
120
121 return true;
122 }
123
124 disableForMirrorSnapshot(selection: CdTableSelection) {
125 return (
126 selection.hasSingleSelection &&
127 selection.first().mirror_mode === 'snapshot' &&
128 selection.first().name.includes('.mirror.')
129 );
130 }
131 }