From: Tiago Melo Date: Tue, 3 Jul 2018 09:58:03 +0000 (+0100) Subject: mgr/dashboard: Add UI for RBD Trash Delete X-Git-Tag: v14.0.1~164^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=11067e06862ee6c695a454900a8d2739bbd32b41;p=ceph.git mgr/dashboard: Add UI for RBD Trash Delete Signed-off-by: Tiago Melo --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-trash-list/rbd-trash-list.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-trash-list/rbd-trash-list.component.html index 51a2be256be9b..e033ab841ff9b 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-trash-list/rbd-trash-list.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-trash-list/rbd-trash-list.component.html @@ -31,3 +31,12 @@ {{ value | cdDate }} + + +

+ This image is protected until {{ expiresAt | cdDate }}. +

+
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-trash-list/rbd-trash-list.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-trash-list/rbd-trash-list.component.spec.ts index 1bb18d2bdaecb..26dbdb66d594f 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-trash-list/rbd-trash-list.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-trash-list/rbd-trash-list.component.spec.ts @@ -93,5 +93,13 @@ describe('RbdTrashListComponent', () => { expect(component.images.length).toBe(2); expect(component.images.every((image) => !image.cdExecuting)).toBeTruthy(); }); + + it('should show when an existing image is being modified', () => { + addTask('rbd/trash/remove', '1'); + addTask('rbd/trash/restore', '2'); + expect(component.images.length).toBe(2); + expectImageTasks(component.images[0], 'Deleting'); + expectImageTasks(component.images[1], 'Restoring'); + }); }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-trash-list/rbd-trash-list.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-trash-list/rbd-trash-list.component.ts index e4474dd2c22a9..6f0f6437c6f72 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-trash-list/rbd-trash-list.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-trash-list/rbd-trash-list.component.ts @@ -5,6 +5,7 @@ import * as moment from 'moment'; import { BsModalRef, BsModalService } from 'ngx-bootstrap'; import { RbdService } from '../../../shared/api/rbd.service'; +import { DeletionModalComponent } from '../../../shared/components/deletion-modal/deletion-modal.component'; import { TableComponent } from '../../../shared/datatable/table/table.component'; import { CellTemplate } from '../../../shared/enum/cell-template.enum'; import { ViewCacheStatus } from '../../../shared/enum/view-cache-status.enum'; @@ -12,10 +13,12 @@ import { CdTableAction } from '../../../shared/models/cd-table-action'; import { CdTableColumn } from '../../../shared/models/cd-table-column'; import { CdTableSelection } from '../../../shared/models/cd-table-selection'; import { ExecutingTask } from '../../../shared/models/executing-task'; +import { FinishedTask } from '../../../shared/models/finished-task'; import { Permission } from '../../../shared/models/permissions'; import { CdDatePipe } from '../../../shared/pipes/cd-date.pipe'; import { AuthStorageService } from '../../../shared/services/auth-storage.service'; import { TaskListService } from '../../../shared/services/task-list.service'; +import { TaskWrapperService } from '../../../shared/services/task-wrapper.service'; import { RbdTrashRestoreModalComponent } from '../rbd-trash-restore-modal/rbd-trash-restore-modal.component'; @Component({ @@ -29,6 +32,8 @@ export class RbdTrashListComponent implements OnInit { table: TableComponent; @ViewChild('expiresTpl') expiresTpl: TemplateRef; + @ViewChild('deleteTpl') + deleteTpl: TemplateRef; columns: CdTableColumn[]; executingTasks: ExecutingTask[] = []; @@ -45,7 +50,8 @@ export class RbdTrashListComponent implements OnInit { private rbdService: RbdService, private modalService: BsModalService, private cdDatePipe: CdDatePipe, - private taskListService: TaskListService + private taskListService: TaskListService, + private taskWrapper: TaskWrapperService ) { this.permission = this.authStorageService.getPermissions().rbdImage; @@ -55,7 +61,13 @@ export class RbdTrashListComponent implements OnInit { click: () => this.restoreModal(), name: 'Restore' }; - this.tableActions = [restoreAction]; + const deleteAction: CdTableAction = { + permission: 'delete', + icon: 'fa-times', + click: () => this.deleteModal(), + name: 'Delete' + }; + this.tableActions = [restoreAction, deleteAction]; } ngOnInit() { @@ -157,4 +169,32 @@ export class RbdTrashListComponent implements OnInit { this.modalRef = this.modalService.show(RbdTrashRestoreModalComponent, { initialState }); } + + deleteModal() { + const poolName = this.selection.first().pool_name; + const imageName = this.selection.first().name; + const imageId = this.selection.first().id; + const expiresAt = this.selection.first().deferment_end_time; + + this.modalRef = this.modalService.show(DeletionModalComponent, { + initialState: { + itemDescription: 'RBD', + bodyTemplate: this.deleteTpl, + bodyContext: { $implicit: expiresAt }, + submitActionObservable: () => + this.taskWrapper.wrapTaskAroundCall({ + task: new FinishedTask('rbd/trash/remove', { + pool_name: poolName, + image_id: imageId, + image_name: imageName + }), + call: this.rbdService.removeTrash(poolName, imageId, imageName, true) + }) + } + }); + } + + isExpired(expiresAt): boolean { + return moment().isAfter(expiresAt); + } } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rbd.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rbd.service.ts index 97efc6d331e35..765d2054f8687 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rbd.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rbd.service.ts @@ -115,4 +115,11 @@ export class RbdService { { observe: 'response' } ); } + + removeTrash(poolName, imageId, imageName, force = false) { + return this.http.delete( + `api/block/image/trash/${poolName}/${imageId}/?image_name=${imageName}&force=${force}`, + { observe: 'response' } + ); + } } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/deletion-modal/deletion-modal.component.html b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/deletion-modal/deletion-modal.component.html index ee4532677f94b..d12d9006bba23 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/deletion-modal/deletion-modal.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/deletion-modal/deletion-modal.component.html @@ -10,7 +10,7 @@ [formGroup]="deletionForm" novalidate>