Skip to content

Commit 9bb8ee4

Browse files
authored
Merge pull request ceph#55120 from rhcs-dashboard/snapshot-delete
mgr/dashboard: delete cephfs snapshot Reviewed-by: Pedro Gonzalez Gomez <[email protected]> Reviewed-by: afreen23 <NOT@FOUND>
2 parents d5457a2 + c3d7f70 commit 9bb8ee4

File tree

6 files changed

+125
-2
lines changed

6 files changed

+125
-2
lines changed

src/pybind/mgr/dashboard/controllers/cephfs.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,19 @@ def create(self, vol_name: str, subvol_name: str, snap_name: str, group_name='')
891891
)
892892
return f'Subvolume snapshot {snap_name} created successfully'
893893

894+
def delete(self, vol_name: str, subvol_name: str, snap_name: str, group_name='', force=True):
895+
params = {'vol_name': vol_name, 'sub_name': subvol_name, 'snap_name': snap_name}
896+
if group_name:
897+
params['group_name'] = group_name
898+
params['force'] = str_to_bool(force)
899+
error_code, _, err = mgr.remote('volumes', '_cmd_fs_subvolume_snapshot_rm', None,
900+
params)
901+
if error_code != 0:
902+
raise DashboardException(
903+
f'Failed to delete subvolume snapshot {snap_name}: {err}'
904+
)
905+
return f'Subvolume snapshot {snap_name} removed successfully'
906+
894907

895908
@APIRouter('/cephfs/snaphost/schedule', Scope.CEPHFS)
896909
@APIDoc("Cephfs Snapshot Scheduling API", "CephFSSnapshotSchedule")

src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-subvolume-snapshots-list/cephfs-subvolume-snapshots-list.component.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
33
import { CephfsSubvolumeSnapshotsListComponent } from './cephfs-subvolume-snapshots-list.component';
44
import { HttpClientTestingModule } from '@angular/common/http/testing';
55
import { SharedModule } from '~/app/shared/shared.module';
6+
import { ToastrModule } from 'ngx-toastr';
67

78
describe('CephfsSubvolumeSnapshotsListComponent', () => {
89
let component: CephfsSubvolumeSnapshotsListComponent;
@@ -11,7 +12,7 @@ describe('CephfsSubvolumeSnapshotsListComponent', () => {
1112
beforeEach(async () => {
1213
await TestBed.configureTestingModule({
1314
declarations: [CephfsSubvolumeSnapshotsListComponent],
14-
imports: [HttpClientTestingModule, SharedModule]
15+
imports: [HttpClientTestingModule, SharedModule, ToastrModule.forRoot()]
1516
}).compileComponents();
1617

1718
fixture = TestBed.createComponent(CephfsSubvolumeSnapshotsListComponent);

src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-subvolume-snapshots-list/cephfs-subvolume-snapshots-list.component.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
1616
import { Permissions } from '~/app/shared/models/permissions';
1717
import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
1818
import { CdDatePipe } from '~/app/shared/pipes/cd-date.pipe';
19+
import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
20+
import { CriticalConfirmationModalComponent } from '~/app/shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
21+
import { FinishedTask } from '~/app/shared/models/finished-task';
22+
import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
1923

2024
@Component({
2125
selector: 'cd-cephfs-subvolume-snapshots-list',
@@ -30,6 +34,7 @@ export class CephfsSubvolumeSnapshotsListComponent implements OnInit, OnChanges
3034
tableActions: CdTableAction[];
3135
selection = new CdTableSelection();
3236
permissions: Permissions;
37+
modalRef: NgbModalRef;
3338

3439
subVolumes$: Observable<CephfsSubvolume[]>;
3540
snapshots$: Observable<any[]>;
@@ -53,7 +58,8 @@ export class CephfsSubvolumeSnapshotsListComponent implements OnInit, OnChanges
5358
private actionLabels: ActionLabelsI18n,
5459
private modalService: ModalService,
5560
private authStorageService: AuthStorageService,
56-
private cdDatePipe: CdDatePipe
61+
private cdDatePipe: CdDatePipe,
62+
private taskWrapper: TaskWrapperService
5763
) {
5864
this.permissions = this.authStorageService.getPermissions();
5965
}
@@ -91,6 +97,12 @@ export class CephfsSubvolumeSnapshotsListComponent implements OnInit, OnChanges
9197
permission: 'create',
9298
icon: Icons.add,
9399
click: () => this.openModal()
100+
},
101+
{
102+
name: this.actionLabels.REMOVE,
103+
permission: 'delete',
104+
icon: Icons.destroy,
105+
click: () => this.deleteSnapshot()
94106
}
95107
];
96108

@@ -190,4 +202,36 @@ export class CephfsSubvolumeSnapshotsListComponent implements OnInit, OnChanges
190202
updateSelection(selection: CdTableSelection) {
191203
this.selection = selection;
192204
}
205+
206+
deleteSnapshot() {
207+
const snapshotName = this.selection.first().name;
208+
const subVolumeName = this.activeSubVolumeName;
209+
const subVolumeGroupName = this.activeGroupName;
210+
const fsName = this.fsName;
211+
this.modalRef = this.modalService.show(CriticalConfirmationModalComponent, {
212+
actionDescription: 'Remove',
213+
itemNames: [snapshotName],
214+
itemDescription: 'Snapshot',
215+
submitAction: () =>
216+
this.taskWrapper
217+
.wrapTaskAroundCall({
218+
task: new FinishedTask('cephfs/subvolume/snapshot/delete', {
219+
fsName: fsName,
220+
subVolumeName: subVolumeName,
221+
subVolumeGroupName: subVolumeGroupName,
222+
snapshotName: snapshotName
223+
}),
224+
call: this.cephfsSubvolumeService.deleteSnapshot(
225+
fsName,
226+
subVolumeName,
227+
snapshotName,
228+
subVolumeGroupName
229+
)
230+
})
231+
.subscribe({
232+
complete: () => this.modalRef.close(),
233+
error: () => this.modalRef.componentInstance.stopLoadingSpinner()
234+
})
235+
});
236+
}
193237
}

src/pybind/mgr/dashboard/frontend/src/app/shared/api/cephfs-subvolume.service.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,14 @@ export class CephfsSubvolumeService {
161161
{ observe: 'response' }
162162
);
163163
}
164+
165+
deleteSnapshot(fsName: string, subVolumeName: string, snapshotName: string, groupName = '') {
166+
return this.http.delete(`${this.baseURL}/snapshot/${fsName}/${subVolumeName}`, {
167+
params: {
168+
snap_name: snapshotName,
169+
group_name: groupName
170+
},
171+
observe: 'response'
172+
});
173+
}
164174
}

src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-message.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,10 @@ export class TaskMessageService {
383383
'cephfs/subvolume/snapshot/create': this.newTaskMessage(
384384
this.commonOperations.create,
385385
(metadata) => this.snapshot(metadata)
386+
),
387+
'cephfs/subvolume/snapshot/delete': this.newTaskMessage(
388+
this.commonOperations.delete,
389+
(metadata) => this.snapshot(metadata)
386390
)
387391
};
388392

src/pybind/mgr/dashboard/openapi.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,6 +2066,57 @@ paths:
20662066
tags:
20672067
- CephfsSubvolumeSnapshot
20682068
/api/cephfs/subvolume/snapshot/{vol_name}/{subvol_name}:
2069+
delete:
2070+
parameters:
2071+
- in: path
2072+
name: vol_name
2073+
required: true
2074+
schema:
2075+
type: string
2076+
- in: path
2077+
name: subvol_name
2078+
required: true
2079+
schema:
2080+
type: string
2081+
- in: query
2082+
name: snap_name
2083+
required: true
2084+
schema:
2085+
type: string
2086+
- default: ''
2087+
in: query
2088+
name: group_name
2089+
schema:
2090+
type: string
2091+
- default: true
2092+
in: query
2093+
name: force
2094+
schema:
2095+
type: boolean
2096+
responses:
2097+
'202':
2098+
content:
2099+
application/vnd.ceph.api.v1.0+json:
2100+
type: object
2101+
description: Operation is still executing. Please check the task queue.
2102+
'204':
2103+
content:
2104+
application/vnd.ceph.api.v1.0+json:
2105+
type: object
2106+
description: Resource deleted.
2107+
'400':
2108+
description: Operation exception. Please check the response body for details.
2109+
'401':
2110+
description: Unauthenticated access. Please login first.
2111+
'403':
2112+
description: Unauthorized access. Please check your permissions.
2113+
'500':
2114+
description: Unexpected error. Please check the response body for the stack
2115+
trace.
2116+
security:
2117+
- jwt: []
2118+
tags:
2119+
- CephfsSubvolumeSnapshot
20692120
get:
20702121
parameters:
20712122
- in: path

0 commit comments

Comments
 (0)