From 83fde0ef2833d36d65bd60d9b523ec62afc09de9 Mon Sep 17 00:00:00 2001 From: Ricardo Dias Date: Tue, 10 Apr 2018 10:41:24 +0100 Subject: [PATCH] mgr/dashboard: rbd: snapshot edit implementation Signed-off-by: Ricardo Dias --- src/pybind/mgr/dashboard/controllers/rbd.py | 32 +++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/pybind/mgr/dashboard/controllers/rbd.py b/src/pybind/mgr/dashboard/controllers/rbd.py index 6d50d67d4c2..f082b980f05 100644 --- a/src/pybind/mgr/dashboard/controllers/rbd.py +++ b/src/pybind/mgr/dashboard/controllers/rbd.py @@ -367,3 +367,35 @@ class RbdSnapshot(RESTController): status, value = task.wait(1.0) cherrypy.response.status = 200 return {'status': status, 'value': value} + + @classmethod + def _edit_snapshot(cls, pool_name, image_name, snapshot_name, + new_snap_name, is_protected): + ioctx = mgr.rados.open_ioctx(pool_name) + img = rbd.Image(ioctx, image_name) + try: + if new_snap_name and new_snap_name != snapshot_name: + img.rename_snap(snapshot_name, new_snap_name) + snapshot_name = new_snap_name + if is_protected is not None and \ + is_protected != img.is_protected_snap(snapshot_name): + if is_protected: + img.protect_snap(snapshot_name) + else: + img.unprotect_snap(snapshot_name) + except rbd.OSError as e: + return {'success': False, 'detail': str(e), 'errno': e.errno} + return {'success': True} + + @RESTController.args_from_json + def set(self, pool_name, image_name, snapshot_name, new_snap_name=None, + is_protected=None): + task = TaskManager.run('rbd/snap/edit', + {'pool_name': pool_name, + 'image_name': image_name, + 'snapshot_name': snapshot_name}, + self._edit_snapshot, + [pool_name, image_name, snapshot_name, + new_snap_name, is_protected]) + status, value = task.wait(1.0) + return {'status': status, 'value': value} -- 2.39.5