Skip to content

Commit

Permalink
Merge pull request ceph#52869 from rhcs-dashboard/fs-subvolumes-rm
Browse files Browse the repository at this point in the history
mgr/dashboard: cephfs subvolume remove

Reviewed-by: Pegonzal <NOT@FOUND>
Reviewed-by: Aashish Sharma <[email protected]>
Reviewed-by: cloudbehl <NOT@FOUND>
  • Loading branch information
nizamial09 authored Aug 14, 2023
2 parents 9545e57 + 3d53395 commit 4a78079
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 39 deletions.
32 changes: 21 additions & 11 deletions src/pybind/mgr/dashboard/controllers/cephfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,27 @@ def create(self, vol_name: str, subvol_name: str, **kwargs):

return f'Subvolume {subvol_name} created successfully'

def set(self, vol_name: str, subvol_name: str, size: str):
if size:
error_code, _, err = mgr.remote('volumes', '_cmd_fs_subvolume_resize', None, {
'vol_name': vol_name, 'sub_name': subvol_name, 'new_size': size})
if error_code != 0:
raise DashboardException(
f'Failed to update subvolume {subvol_name}: {err}'
)

return f'Subvolume {subvol_name} updated successfully'

def delete(self, vol_name: str, subvol_name: str):
error_code, _, err = mgr.remote(
'volumes', '_cmd_fs_subvolume_rm', None, {
'vol_name': vol_name, 'sub_name': subvol_name})
if error_code != 0:
raise RuntimeError(
f'Failed to delete subvolume {subvol_name}: {err}'
)
return f'Subvolume {subvol_name} removed successfully'


@APIRouter('/cephfs/subvolume/group', Scope.CEPHFS)
@APIDoc("Cephfs Subvolume Group Management API", "CephfsSubvolumeGroup")
Expand Down Expand Up @@ -744,14 +765,3 @@ def create(self, vol_name: str, group_name: str, **kwargs):
raise DashboardException(
f'Failed to create subvolume group {group_name}: {err}'
)

def set(self, vol_name: str, subvol_name: str, size: str):
if size:
error_code, _, err = mgr.remote('volumes', '_cmd_fs_subvolume_resize', None, {
'vol_name': vol_name, 'sub_name': subvol_name, 'new_size': size})
if error_code != 0:
raise DashboardException(
f'Failed to update subvolume {subvol_name}: {err}'
)

return f'Subvolume {subvol_name} updated successfully'
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { CephfsSubvolumeListComponent } from './cephfs-subvolume-list.component';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { SharedModule } from '~/app/shared/shared.module';
import { ToastrModule } from 'ngx-toastr';
import { RouterTestingModule } from '@angular/router/testing';

describe('CephfsSubvolumeListComponent', () => {
let component: CephfsSubvolumeListComponent;
Expand All @@ -11,7 +13,7 @@ describe('CephfsSubvolumeListComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [CephfsSubvolumeListComponent],
imports: [HttpClientTestingModule, SharedModule]
imports: [HttpClientTestingModule, SharedModule, ToastrModule.forRoot(), RouterTestingModule]
}).compileComponents();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import { ModalService } from '~/app/shared/services/modal.service';
import { CephfsSubvolumeFormComponent } from '../cephfs-subvolume-form/cephfs-subvolume-form.component';
import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
import { Permissions } from '~/app/shared/models/permissions';
import { CriticalConfirmationModalComponent } from '~/app/shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
import { FinishedTask } from '~/app/shared/models/finished-task';

@Component({
selector: 'cd-cephfs-subvolume-list',
Expand Down Expand Up @@ -53,7 +56,8 @@ export class CephfsSubvolumeListComponent implements OnInit, OnChanges {
private cephfsSubVolume: CephfsSubvolumeService,
private actionLabels: ActionLabelsI18n,
private modalService: ModalService,
private authStorageService: AuthStorageService
private authStorageService: AuthStorageService,
private taskWrapper: TaskWrapperService
) {
this.permissions = this.authStorageService.getPermissions();
}
Expand Down Expand Up @@ -107,14 +111,21 @@ export class CephfsSubvolumeListComponent implements OnInit, OnChanges {
name: this.actionLabels.CREATE,
permission: 'create',
icon: Icons.add,
click: () => this.openModal(),
canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
click: () =>
this.modalService.show(
CephfsSubvolumeFormComponent,
{
fsName: this.fsName,
pools: this.pools
},
{ size: 'lg' }
)
},
{
name: this.actionLabels.EDIT,
permission: 'update',
icon: Icons.edit,
click: () => this.openModal(true)
name: this.actionLabels.REMOVE,
permission: 'delete',
icon: Icons.destroy,
click: () => this.removeSubVolumeModal()
}
];

Expand Down Expand Up @@ -155,4 +166,18 @@ export class CephfsSubvolumeListComponent implements OnInit, OnChanges {
{ size: 'lg' }
);
}

removeSubVolumeModal() {
const name = this.selection.first().name;
this.modalService.show(CriticalConfirmationModalComponent, {
itemDescription: 'subvolume',
itemNames: [name],
actionDescription: 'remove',
submitActionObservable: () =>
this.taskWrapper.wrapTaskAroundCall({
task: new FinishedTask('cephfs/subvolume/remove', { subVolumeName: name }),
call: this.cephfsSubVolume.remove(this.fsName, name)
})
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,10 @@ describe('CephfsSubvolumeService', () => {
const req = httpTesting.expectOne('api/cephfs/subvolume/testFS');
expect(req.request.method).toBe('GET');
});

it('should call remove', () => {
service.remove('testFS', 'testSubvol').subscribe();
const req = httpTesting.expectOne('api/cephfs/subvolume/testFS?subvol_name=testSubvol');
expect(req.request.method).toBe('DELETE');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ export class CephfsSubvolumeService {
});
}

remove(fsName: string, subVolumeName: string) {
return this.http.delete(`${this.baseURL}/${fsName}`, {
params: {
subvol_name: subVolumeName
},
observe: 'response'
});
}

exists(subVolumeName: string, fsName: string) {
return this.info(fsName, subVolumeName).pipe(
mapTo(true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ export class TaskMessageService {
'cephfs/subvolume/edit': this.newTaskMessage(this.commonOperations.update, (metadata) =>
this.subvolume(metadata)
),
'cephfs/subvolume/remove': this.newTaskMessage(this.commonOperations.remove, (metadata) =>
this.subvolume(metadata)
),
'cephfs/subvolume/group/create': this.newTaskMessage(this.commonOperations.create, (metadata) =>
this.subvolumegroup(metadata)
)
Expand Down
76 changes: 56 additions & 20 deletions src/pybind/mgr/dashboard/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1865,37 +1865,30 @@ paths:
- jwt: []
tags:
- CephfsSubvolumeGroup
put:
/api/cephfs/subvolume/{vol_name}:
delete:
parameters:
- in: path
name: vol_name
required: true
schema:
type: string
requestBody:
content:
application/json:
schema:
properties:
size:
type: integer
subvol_name:
type: string
required:
- subvol_name
- size
type: object
- in: query
name: subvol_name
required: true
schema:
type: string
responses:
'200':
'202':
content:
application/vnd.ceph.api.v1.0+json:
type: object
description: Resource updated.
'202':
description: Operation is still executing. Please check the task queue.
'204':
content:
application/vnd.ceph.api.v1.0+json:
type: object
description: Operation is still executing. Please check the task queue.
description: Resource deleted.
'400':
description: Operation exception. Please check the response body for details.
'401':
Expand All @@ -1908,8 +1901,7 @@ paths:
security:
- jwt: []
tags:
- CephfsSubvolumeGroup
/api/cephfs/subvolume/{vol_name}:
- CephFSSubvolume
get:
parameters:
- in: path
Expand All @@ -1936,6 +1928,50 @@ paths:
- jwt: []
tags:
- CephFSSubvolume
put:
parameters:
- in: path
name: vol_name
required: true
schema:
type: string
requestBody:
content:
application/json:
schema:
properties:
size:
type: integer
subvol_name:
type: string
required:
- subvol_name
- size
type: object
responses:
'200':
content:
application/vnd.ceph.api.v1.0+json:
type: object
description: Resource updated.
'202':
content:
application/vnd.ceph.api.v1.0+json:
type: object
description: Operation is still executing. Please check the task queue.
'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:
- CephFSSubvolume
/api/cephfs/subvolume/{vol_name}/info:
get:
parameters:
Expand Down

0 comments on commit 4a78079

Please sign in to comment.