Skip to content

Commit f002368

Browse files
authored
Merge pull request ceph#60935 from rhcs-dashboard/smb-cluster-delete
mgr/dashboard: delete smb cluster Reviewed-by: Nizamudeen A <[email protected]> Reviewed-by: Ankush Behl <[email protected]> Reviewed-by: Afreen Misbah <[email protected]>
2 parents 3874c48 + 9e512e0 commit f002368

File tree

8 files changed

+147
-2
lines changed

8 files changed

+147
-2
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,24 @@ def create(self, cluster_resource: Cluster) -> Simplified:
137137
except RuntimeError as e:
138138
raise DashboardException(e, component='smb')
139139

140+
@DeletePermission
141+
@EndpointDoc("Remove an smb cluster",
142+
parameters={
143+
'cluster_id': (str, 'Unique identifier for the cluster')},
144+
responses={204: None})
145+
def delete(self, cluster_id: str):
146+
"""
147+
Remove an smb cluster
148+
149+
:param cluster_id: Cluster identifier
150+
:return: None.
151+
"""
152+
resource = {}
153+
resource['resource_type'] = self._resource
154+
resource['cluster_id'] = cluster_id
155+
resource['intent'] = Intent.REMOVED
156+
return mgr.remote('smb', 'apply_resources', json.dumps(resource)).one().to_simplified()
157+
140158

141159
@APIRouter('/smb/share', Scope.SMB)
142160
@APIDoc("SMB Share Management API", "SMB")

src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-cluster-list/smb-cluster-list.component.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
[hasDetails]="false"
1111
(setExpandedRow)="setExpandedRow($event)"
1212
(fetchData)="loadSMBCluster($event)"
13+
(updateSelection)="updateSelection($event)"
1314
>
15+
<div class="table-actions">
16+
<cd-table-actions
17+
class="btn-group"
18+
[permission]="permission"
19+
[selection]="selection"
20+
[tableActions]="tableActions"
21+
>
22+
</cd-table-actions>
23+
</div>
1424
</cd-table>
1525
</ng-container>

src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-cluster-list/smb-cluster-list.component.ts

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ import { Permission } from '~/app/shared/models/permissions';
1515
import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
1616
import { SmbService } from '~/app/shared/api/smb.service';
1717
import { SMBCluster } from '../smb.model';
18+
import { Icons } from '~/app/shared/enum/icons.enum';
19+
import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
20+
import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
21+
import { ModalCdsService } from '~/app/shared/services/modal-cds.service';
22+
import { CriticalConfirmationModalComponent } from '~/app/shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
23+
import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
24+
import { FinishedTask } from '~/app/shared/models/finished-task';
1825

1926
@Component({
2027
selector: 'cd-smb-cluster-list',
@@ -28,17 +35,28 @@ export class SmbClusterListComponent extends ListWithDetails implements OnInit {
2835
permission: Permission;
2936
tableActions: CdTableAction[];
3037
context: CdTableFetchDataContext;
31-
3238
smbClusters$: Observable<SMBCluster[]>;
3339
subject$ = new BehaviorSubject<SMBCluster[]>([]);
40+
selection = new CdTableSelection();
41+
modalRef: NgbModalRef;
3442

3543
constructor(
3644
private authStorageService: AuthStorageService,
3745
public actionLabels: ActionLabelsI18n,
38-
private smbService: SmbService
46+
private smbService: SmbService,
47+
private modalService: ModalCdsService,
48+
private taskWrapper: TaskWrapperService
3949
) {
4050
super();
4151
this.permission = this.authStorageService.getPermissions().smb;
52+
this.tableActions = [
53+
{
54+
permission: 'delete',
55+
icon: Icons.destroy,
56+
click: () => this.removeSMBClusterModal(),
57+
name: this.actionLabels.REMOVE
58+
}
59+
];
4260
}
4361

4462
ngOnInit() {
@@ -70,4 +88,25 @@ export class SmbClusterListComponent extends ListWithDetails implements OnInit {
7088
loadSMBCluster() {
7189
this.subject$.next([]);
7290
}
91+
92+
updateSelection(selection: CdTableSelection) {
93+
this.selection = selection;
94+
}
95+
96+
removeSMBClusterModal() {
97+
const cluster_id = this.selection.first().cluster_id;
98+
99+
this.modalService.show(CriticalConfirmationModalComponent, {
100+
itemDescription: $localize`Cluster`,
101+
itemNames: [cluster_id],
102+
actionDescription: $localize`remove`,
103+
submitActionObservable: () =>
104+
this.taskWrapper.wrapTaskAroundCall({
105+
task: new FinishedTask('smb/cluster/remove', {
106+
cluster_id: cluster_id
107+
}),
108+
call: this.smbService.removeCluster(cluster_id)
109+
})
110+
});
111+
}
73112
}

src/pybind/mgr/dashboard/frontend/src/app/shared/api/smb.service.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,10 @@ describe('SmbService', () => {
2828
const req = httpTesting.expectOne('api/smb/cluster');
2929
expect(req.request.method).toBe('GET');
3030
});
31+
32+
it('should call remove', () => {
33+
service.removeCluster('cluster_1').subscribe();
34+
const req = httpTesting.expectOne('api/smb/cluster/cluster_1');
35+
expect(req.request.method).toBe('DELETE');
36+
});
3137
});

src/pybind/mgr/dashboard/frontend/src/app/shared/api/smb.service.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,10 @@ export class SmbService {
1515
listClusters(): Observable<SMBCluster[]> {
1616
return this.http.get<SMBCluster[]>(`${this.baseURL}/cluster`);
1717
}
18+
19+
removeCluster(clusterId: string) {
20+
return this.http.delete(`${this.baseURL}/cluster/${clusterId}`, {
21+
observe: 'response'
22+
});
23+
}
1824
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,10 @@ export class TaskMessageService {
396396
'nfs/delete': this.newTaskMessage(this.commonOperations.delete, (metadata) =>
397397
this.nfs(metadata)
398398
),
399+
// smb
400+
'smb/cluster/remove': this.newTaskMessage(this.commonOperations.remove, (metadata) =>
401+
this.smb(metadata)
402+
),
399403
// Grafana tasks
400404
'grafana/dashboards/update': this.newTaskMessage(
401405
this.commonOperations.update,
@@ -539,6 +543,10 @@ export class TaskMessageService {
539543
}'`;
540544
}
541545

546+
smb(metadata: { cluster_id: string }) {
547+
return $localize`SMB Cluster '${metadata.cluster_id}'`;
548+
}
549+
542550
service(metadata: any) {
543551
return $localize`service '${metadata.service_name}'`;
544552
}

src/pybind/mgr/dashboard/openapi.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14599,6 +14599,43 @@ paths:
1459914599
tags:
1460014600
- SMB
1460114601
/api/smb/cluster/{cluster_id}:
14602+
delete:
14603+
description: "\n Remove an smb cluster\n\n :param cluster_id:\
14604+
\ Cluster identifier\n :return: None.\n "
14605+
parameters:
14606+
- description: Unique identifier for the cluster
14607+
in: path
14608+
name: cluster_id
14609+
required: true
14610+
schema:
14611+
type: string
14612+
responses:
14613+
'202':
14614+
content:
14615+
application/vnd.ceph.api.v1.0+json:
14616+
type: object
14617+
description: Operation is still executing. Please check the task queue.
14618+
'204':
14619+
content:
14620+
application/vnd.ceph.api.v1.0+json:
14621+
schema:
14622+
properties: {}
14623+
type: object
14624+
description: Resource deleted.
14625+
'400':
14626+
description: Operation exception. Please check the response body for details.
14627+
'401':
14628+
description: Unauthenticated access. Please login first.
14629+
'403':
14630+
description: Unauthorized access. Please check your permissions.
14631+
'500':
14632+
description: Unexpected error. Please check the response body for the stack
14633+
trace.
14634+
security:
14635+
- jwt: []
14636+
summary: Remove an smb cluster
14637+
tags:
14638+
- SMB
1460214639
get:
1460314640
description: "\n Get an smb cluster by cluster id\n "
1460414641
parameters:

src/pybind/mgr/dashboard/tests/test_smb.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,27 @@ def test_create_user(self):
121121
self.assertStatus(201)
122122
self.assertInJsonBody(json.dumps(self._clusters['resources'][1]))
123123

124+
def test_remove(self):
125+
_res = {
126+
"resource": {
127+
"resource_type": "ceph.smb.cluster",
128+
"cluster_id": "smbRemoveCluster",
129+
"intent": "removed"
130+
},
131+
"state": "removed",
132+
"success": "true"
133+
}
134+
_res_simplified = {
135+
"resource_type": "ceph.smb.cluster",
136+
"cluster_id": "smbRemoveCluster",
137+
"intent": "removed"
138+
}
139+
mgr.remote = Mock(return_value=Mock(return_value=_res))
140+
mgr.remote.return_value.one.return_value.to_simplified = Mock(return_value=_res_simplified)
141+
self._delete(f'{self._endpoint}/smbRemoveCluster')
142+
self.assertStatus(204)
143+
mgr.remote.assert_called_once_with('smb', 'apply_resources', json.dumps(_res_simplified))
144+
124145

125146
class SMBShareTest(ControllerTestCase):
126147
_endpoint = '/api/smb/share'

0 commit comments

Comments
 (0)