Skip to content

Commit 67afcf6

Browse files
authored
Merge pull request ceph#58386 from YiteGu/dashboard-rename-api
mgr/dashboard: add cephfs rename REST API Reviewed-by: Dhairya Parmar <[email protected]> Reviewed-by: Nizamudeen A <[email protected]>
2 parents 3c60f06 + bac2689 commit 67afcf6

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

qa/tasks/mgr/dashboard/test_cephfs.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ def statfs(self, path):
9494
self.assertIsInstance(data, dict)
9595
return data
9696

97+
def rename_path(self, src_path, dst_path):
98+
params = {'src_path': src_path, 'dst_path': dst_path}
99+
self._put(f"/api/cephfs/{self.get_fs_id()}/rename-path",
100+
data=params)
101+
self.assertStatus(200)
102+
97103
@DashboardTestCase.RunAs('test', 'test', ['block-manager'])
98104
def test_access_permissions(self):
99105
fs_id = self.get_fs_id()
@@ -361,3 +367,9 @@ def test_cephfs_clients_get_after_mds_down(self):
361367
self.fs.set_joinable()
362368
self._get(f"/api/cephfs/{fs_id}/clients")
363369
self.assertStatus(200)
370+
371+
def test_rename_path(self):
372+
self.mk_dirs('/apple')
373+
self.rename_path('/apple', '/orange')
374+
self.ls_dir('/orange', 0)
375+
self.rm_dir('/orange')

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,17 @@ def rm_snapshot(self, fs_id, path, name):
639639
cfs = self._cephfs_instance(fs_id)
640640
cfs.rm_snapshot(path, name)
641641

642+
@RESTController.Resource('PUT', path='/rename-path')
643+
def rename_path(self, fs_id, src_path, dst_path) -> None:
644+
"""
645+
Rename a file or directory.
646+
:param fs_id: The filesystem identifier.
647+
:param src_path: The path to the existing file or directory.
648+
:param dst_path: The new name of the file or directory.
649+
"""
650+
cfs = self._cephfs_instance(fs_id)
651+
cfs.rename_path(src_path, dst_path)
652+
642653

643654
class CephFSClients(object):
644655
def __init__(self, module_inst, fscid):

src/pybind/mgr/dashboard/openapi.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3116,6 +3116,55 @@ paths:
31163116
- jwt: []
31173117
tags:
31183118
- Cephfs
3119+
/api/cephfs/{fs_id}/rename-path:
3120+
put:
3121+
description: "\n Rename a file or directory.\n :param fs_id: The\
3122+
\ filesystem identifier.\n :param src_path: The path to the existing\
3123+
\ file or directory.\n :param dst_path: The new name of the file or\
3124+
\ directory.\n "
3125+
parameters:
3126+
- in: path
3127+
name: fs_id
3128+
required: true
3129+
schema:
3130+
type: string
3131+
requestBody:
3132+
content:
3133+
application/json:
3134+
schema:
3135+
properties:
3136+
dst_path:
3137+
type: string
3138+
src_path:
3139+
type: string
3140+
required:
3141+
- src_path
3142+
- dst_path
3143+
type: object
3144+
responses:
3145+
'200':
3146+
content:
3147+
application/vnd.ceph.api.v1.0+json:
3148+
type: object
3149+
description: Resource updated.
3150+
'202':
3151+
content:
3152+
application/vnd.ceph.api.v1.0+json:
3153+
type: object
3154+
description: Operation is still executing. Please check the task queue.
3155+
'400':
3156+
description: Operation exception. Please check the response body for details.
3157+
'401':
3158+
description: Unauthenticated access. Please login first.
3159+
'403':
3160+
description: Unauthorized access. Please check your permissions.
3161+
'500':
3162+
description: Unexpected error. Please check the response body for the stack
3163+
trace.
3164+
security:
3165+
- jwt: []
3166+
tags:
3167+
- Cephfs
31193168
/api/cephfs/{fs_id}/snapshot:
31203169
delete:
31213170
description: "\n Remove a snapshot.\n :param fs_id: The filesystem\

src/pybind/mgr/dashboard/services/cephfs.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,12 @@ def statfs(self, path) -> dict:
298298
rfiles = int(self.cfs.getxattr(path, 'ceph.dir.rfiles'))
299299
rsubdirs = int(self.cfs.getxattr(path, 'ceph.dir.rsubdirs'))
300300
return {'bytes': rbytes, 'files': rfiles, 'subdirs': rsubdirs}
301+
302+
def rename_path(self, src_path, dst_path) -> None:
303+
"""
304+
Rename a file or directory.
305+
:param src: the path to the existing file or directory.
306+
:param dst: the new name of the file or directory.
307+
"""
308+
logger.info("Renaming: from %s to %s", src_path, dst_path)
309+
self.cfs.rename(src_path, dst_path)

0 commit comments

Comments
 (0)