mirror of
https://github.com/ceph/ceph
synced 2025-03-24 11:17:53 +00:00
Merge pull request #61973 from rhcs-dashboard/wip-70122-reef
reef: mgr/dashboard: disable deleting bucket with objects Reviewed-by: Afreen Misbah <afreen@ibm.com>
This commit is contained in:
commit
aa0fc9b6e8
@ -457,11 +457,18 @@ class RgwBucket(RgwRESTController):
|
|||||||
self._set_acl(bucket_name, canned_acl, uid, daemon_name)
|
self._set_acl(bucket_name, canned_acl, uid, daemon_name)
|
||||||
return self._append_bid(result)
|
return self._append_bid(result)
|
||||||
|
|
||||||
def delete(self, bucket, purge_objects='true', daemon_name=None):
|
def delete(self, bucket, daemon_name=None):
|
||||||
return self.proxy(daemon_name, 'DELETE', 'bucket', {
|
try:
|
||||||
'bucket': bucket,
|
bucket_info = self.proxy(daemon_name, 'GET', 'bucket', {'bucket': bucket})
|
||||||
'purge-objects': purge_objects
|
num_objects = bucket_info.get('usage', {}).get('rgw.main', {}).get('num_objects', 0)
|
||||||
}, json_response=False)
|
if num_objects > 0:
|
||||||
|
raise DashboardException(msg='Unable to delete bucket"{}" - Bucket is not empty. '
|
||||||
|
'Remove all objects before deletion.'.format(bucket))
|
||||||
|
return self.proxy(daemon_name, 'DELETE', 'bucket', {
|
||||||
|
'bucket': bucket
|
||||||
|
}, json_response=False)
|
||||||
|
except (DashboardException, RequestException) as e: # pragma: no cover
|
||||||
|
raise DashboardException(e, component='rgw')
|
||||||
|
|
||||||
@RESTController.Collection(method='PUT', path='/setEncryptionConfig')
|
@RESTController.Collection(method='PUT', path='/setEncryptionConfig')
|
||||||
@allow_empty_body
|
@allow_empty_body
|
||||||
|
@ -117,12 +117,22 @@ export class RgwBucketListComponent extends ListWithDetails implements OnInit, O
|
|||||||
permission: 'delete',
|
permission: 'delete',
|
||||||
icon: Icons.destroy,
|
icon: Icons.destroy,
|
||||||
click: () => this.deleteAction(),
|
click: () => this.deleteAction(),
|
||||||
|
disable: () => this.isDeleteDisabled(),
|
||||||
name: this.actionLabels.DELETE
|
name: this.actionLabels.DELETE
|
||||||
};
|
};
|
||||||
this.tableActions = [addAction, editAction, deleteAction];
|
this.tableActions = [addAction, editAction, deleteAction];
|
||||||
this.setTableRefreshTimeout();
|
this.setTableRefreshTimeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isDeleteDisabled(): boolean | string {
|
||||||
|
if (!this.selection.first()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return this.selection.first()?.num_objects > 0
|
||||||
|
? $localize`Bucket is not empty. Remove all objects before deletion.`
|
||||||
|
: false;
|
||||||
|
}
|
||||||
|
|
||||||
getBucketList(context: CdTableFetchDataContext) {
|
getBucketList(context: CdTableFetchDataContext) {
|
||||||
this.setTableRefreshTimeout();
|
this.setTableRefreshTimeout();
|
||||||
this.subs.add(
|
this.subs.add(
|
||||||
|
@ -97,19 +97,9 @@ describe('RgwBucketService', () => {
|
|||||||
expect(req.request.method).toBe('PUT');
|
expect(req.request.method).toBe('PUT');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call delete, with purgeObjects = true', () => {
|
it('should call delete', () => {
|
||||||
service.delete('foo').subscribe();
|
service.delete('foo').subscribe();
|
||||||
const req = httpTesting.expectOne(
|
const req = httpTesting.expectOne(`api/rgw/bucket/foo?${RgwHelper.DAEMON_QUERY_PARAM}`);
|
||||||
`api/rgw/bucket/foo?${RgwHelper.DAEMON_QUERY_PARAM}&purge_objects=true`
|
|
||||||
);
|
|
||||||
expect(req.request.method).toBe('DELETE');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should call delete, with purgeObjects = false', () => {
|
|
||||||
service.delete('foo', false).subscribe();
|
|
||||||
const req = httpTesting.expectOne(
|
|
||||||
`api/rgw/bucket/foo?${RgwHelper.DAEMON_QUERY_PARAM}&purge_objects=false`
|
|
||||||
);
|
|
||||||
expect(req.request.method).toBe('DELETE');
|
expect(req.request.method).toBe('DELETE');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -184,9 +184,8 @@ export class RgwBucketService extends ApiClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(bucket: string, purgeObjects = true) {
|
delete(bucket: string) {
|
||||||
return this.rgwDaemonService.request((params: HttpParams) => {
|
return this.rgwDaemonService.request((params: HttpParams) => {
|
||||||
params = params.append('purge_objects', purgeObjects ? 'true' : 'false');
|
|
||||||
return this.http.delete(`${this.url}/${bucket}`, { params: params });
|
return this.http.delete(`${this.url}/${bucket}`, { params: params });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -9759,11 +9759,6 @@ paths:
|
|||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
- default: 'true'
|
|
||||||
in: query
|
|
||||||
name: purge_objects
|
|
||||||
schema:
|
|
||||||
type: string
|
|
||||||
- allowEmptyValue: true
|
- allowEmptyValue: true
|
||||||
in: query
|
in: query
|
||||||
name: daemon_name
|
name: daemon_name
|
||||||
|
Loading…
Reference in New Issue
Block a user