From 0628c69ef71a89f6186b718257b5cc65844b85bf Mon Sep 17 00:00:00 2001 From: Pedro Gonzalez Gomez Date: Wed, 16 Aug 2023 07:52:05 +0200 Subject: [PATCH] mgr/dashboard: cephfs remove subvolume group Fixes: https://tracker.ceph.com/issues/62452 Signed-off-by: Pedro Gonzalez Gomez --- .../mgr/dashboard/controllers/cephfs.py | 10 ++++++ .../cephfs-subvolume-group.component.spec.ts | 5 ++- .../cephfs-subvolume-group.component.ts | 26 +++++++++++++- .../cephfs-subvolume-list.component.ts | 6 ++++ .../api/cephfs-subvolume-group.service.ts | 9 +++++ .../shared/services/task-message.service.ts | 3 ++ src/pybind/mgr/dashboard/openapi.yaml | 36 +++++++++++++++++++ 7 files changed, 93 insertions(+), 2 deletions(-) diff --git a/src/pybind/mgr/dashboard/controllers/cephfs.py b/src/pybind/mgr/dashboard/controllers/cephfs.py index 99cf9810baac7..a5dceb4138d51 100644 --- a/src/pybind/mgr/dashboard/controllers/cephfs.py +++ b/src/pybind/mgr/dashboard/controllers/cephfs.py @@ -786,3 +786,13 @@ def set(self, vol_name: str, group_name: str, size: str): f'Failed to update subvolume group {group_name}: {err}' ) return f'Subvolume group {group_name} updated successfully' + + def delete(self, vol_name: str, group_name: str): + error_code, _, err = mgr.remote( + 'volumes', '_cmd_fs_subvolumegroup_rm', None, { + 'vol_name': vol_name, 'group_name': group_name}) + if error_code != 0: + raise DashboardException( + f'Failed to delete subvolume group {group_name}: {err}' + ) + return f'Subvolume group {group_name} removed successfully' diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-subvolume-group/cephfs-subvolume-group.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-subvolume-group/cephfs-subvolume-group.component.spec.ts index b36bd2cb09000..b9a3856ef8af3 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-subvolume-group/cephfs-subvolume-group.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-subvolume-group/cephfs-subvolume-group.component.spec.ts @@ -2,6 +2,9 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { CephfsSubvolumeGroupComponent } from './cephfs-subvolume-group.component'; import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { ToastrModule } from 'ngx-toastr'; +import { RouterTestingModule } from '@angular/router/testing'; +import { SharedModule } from '~/app/shared/shared.module'; describe('CephfsSubvolumeGroupComponent', () => { let component: CephfsSubvolumeGroupComponent; @@ -10,7 +13,7 @@ describe('CephfsSubvolumeGroupComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [CephfsSubvolumeGroupComponent], - imports: [HttpClientTestingModule] + imports: [HttpClientTestingModule, SharedModule, ToastrModule.forRoot(), RouterTestingModule] }).compileComponents(); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-subvolume-group/cephfs-subvolume-group.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-subvolume-group/cephfs-subvolume-group.component.ts index 48c239ce0b7eb..3807ae61b67c9 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-subvolume-group/cephfs-subvolume-group.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-subvolume-group/cephfs-subvolume-group.component.ts @@ -15,6 +15,9 @@ import { ActionLabelsI18n } from '~/app/shared/constants/app.constants'; import { AuthStorageService } from '~/app/shared/services/auth-storage.service'; import { ModalService } from '~/app/shared/services/modal.service'; import { Permissions } from '~/app/shared/models/permissions'; +import { CriticalConfirmationModalComponent } from '~/app/shared/components/critical-confirmation-modal/critical-confirmation-modal.component'; +import { FinishedTask } from '~/app/shared/models/finished-task'; +import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service'; @Component({ selector: 'cd-cephfs-subvolume-group', @@ -55,7 +58,8 @@ export class CephfsSubvolumeGroupComponent implements OnInit, OnChanges { private cephfsSubvolumeGroup: CephfsSubvolumeGroupService, private actionLabels: ActionLabelsI18n, private modalService: ModalService, - private authStorageService: AuthStorageService + private authStorageService: AuthStorageService, + private taskWrapper: TaskWrapperService ) { this.permissions = this.authStorageService.getPermissions(); } @@ -111,6 +115,12 @@ export class CephfsSubvolumeGroupComponent implements OnInit, OnChanges { permission: 'update', icon: Icons.edit, click: () => this.openModal(true) + }, + { + name: this.actionLabels.REMOVE, + permission: 'delete', + icon: Icons.destroy, + click: () => this.removeSubVolumeModal() } ]; @@ -151,4 +161,18 @@ export class CephfsSubvolumeGroupComponent implements OnInit, OnChanges { { size: 'lg' } ); } + + removeSubVolumeModal() { + const name = this.selection.first().name; + this.modalService.show(CriticalConfirmationModalComponent, { + itemDescription: 'subvolume group', + itemNames: [name], + actionDescription: 'remove', + submitActionObservable: () => + this.taskWrapper.wrapTaskAroundCall({ + task: new FinishedTask('cephfs/subvolume/group/remove', { subvolumegroupName: name }), + call: this.cephfsSubvolumeGroup.remove(this.fsName, name) + }) + }); + } } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-subvolume-list/cephfs-subvolume-list.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-subvolume-list/cephfs-subvolume-list.component.ts index 25b5ef14a58cc..c9ff01e2ddd9a 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-subvolume-list/cephfs-subvolume-list.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-subvolume-list/cephfs-subvolume-list.component.ts @@ -121,6 +121,12 @@ export class CephfsSubvolumeListComponent implements OnInit, OnChanges { { size: 'lg' } ) }, + { + name: this.actionLabels.EDIT, + permission: 'update', + icon: Icons.edit, + click: () => this.openModal(true) + }, { name: this.actionLabels.REMOVE, permission: 'delete', diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/cephfs-subvolume-group.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/cephfs-subvolume-group.service.ts index 642f4609f3d00..db7fcfacd597e 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/cephfs-subvolume-group.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/cephfs-subvolume-group.service.ts @@ -67,4 +67,13 @@ export class CephfsSubvolumeGroupService { size: size }); } + + remove(volName: string, groupName: string) { + return this.http.delete(`${this.baseURL}/${volName}`, { + params: { + group_name: groupName + }, + observe: 'response' + }); + } } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-message.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-message.service.ts index eb4ae7651f725..023a1529fa746 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-message.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-message.service.ts @@ -373,6 +373,9 @@ export class TaskMessageService { ), 'cephfs/subvolume/group/edit': this.newTaskMessage(this.commonOperations.update, (metadata) => this.subvolumegroup(metadata) + ), + 'cephfs/subvolume/group/remove': this.newTaskMessage(this.commonOperations.remove, (metadata) => + this.subvolumegroup(metadata) ) }; diff --git a/src/pybind/mgr/dashboard/openapi.yaml b/src/pybind/mgr/dashboard/openapi.yaml index 02d377d8fdb2c..e09aa6c3b1ce9 100644 --- a/src/pybind/mgr/dashboard/openapi.yaml +++ b/src/pybind/mgr/dashboard/openapi.yaml @@ -1839,6 +1839,42 @@ paths: tags: - CephfsSubvolumeGroup /api/cephfs/subvolume/group/{vol_name}: + delete: + parameters: + - in: path + name: vol_name + required: true + schema: + type: string + - in: query + name: group_name + required: true + schema: + type: string + responses: + '202': + content: + application/vnd.ceph.api.v1.0+json: + type: object + description: Operation is still executing. Please check the task queue. + '204': + content: + application/vnd.ceph.api.v1.0+json: + type: object + description: Resource deleted. + '400': + description: Operation exception. Please check the response body for details. + '401': + description: Unauthenticated access. Please login first. + '403': + description: Unauthorized access. Please check your permissions. + '500': + description: Unexpected error. Please check the response body for the stack + trace. + security: + - jwt: [] + tags: + - CephfsSubvolumeGroup get: parameters: - in: path