]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: rbd: snapshot edit implementation
authorRicardo Dias <rdias@suse.com>
Tue, 10 Apr 2018 09:41:24 +0000 (10:41 +0100)
committerRicardo Dias <rdias@suse.com>
Fri, 13 Apr 2018 14:58:48 +0000 (15:58 +0100)
Signed-off-by: Ricardo Dias <rdias@suse.com>
src/pybind/mgr/dashboard/controllers/rbd.py

index 6d50d67d4c27b43bdf394ac16cbdec41557b1632..f082b980f05ca21c60d3649279d34e77cf0c76c1 100644 (file)
@@ -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}