From 0e4bece441f47a378debfabb94b269f823b852ff Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Sun, 14 Feb 2021 17:02:49 -0500 Subject: [PATCH] Add missing inc/dec of snapshot_count --- daemon-common/ceph.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/daemon-common/ceph.py b/daemon-common/ceph.py index e8b99c14..a2352204 100644 --- a/daemon-common/ceph.py +++ b/daemon-common/ceph.py @@ -715,6 +715,16 @@ def add_snapshot(zk_conn, pool, volume, name): '/ceph/snapshots/{}/{}/{}/stats'.format(pool, volume, name): '{}' }) + # 3. Update the count of snapshots on this volume + volume_stats_raw = zkhandler.readdata(zk_conn, '/ceph/volumes/{}/{}/stats'.format(pool, volume)) + volume_stats = dict(json.loads(volume_stats_raw)) + # Format the size to something nicer + volume_stats['snapshot_count'] = volume_stats['snapshot_count'] + 1 + volume_stats_raw = json.dumps(volume_stats) + zkhandler.writedata(zk_conn, { + '/ceph/volumes/{}/{}/stats'.format(pool, volume): volume_stats_raw + }) + return True, 'Created RBD snapshot "{}" of volume "{}" in pool "{}".'.format(name, volume, pool) @@ -751,6 +761,16 @@ def remove_snapshot(zk_conn, pool, volume, name): # 2. Delete snapshot from Zookeeper zkhandler.deletekey(zk_conn, '/ceph/snapshots/{}/{}/{}'.format(pool, volume, name)) + # 3. Update the count of snapshots on this volume + volume_stats_raw = zkhandler.readdata(zk_conn, '/ceph/volumes/{}/{}/stats'.format(pool, volume)) + volume_stats = dict(json.loads(volume_stats_raw)) + # Format the size to something nicer + volume_stats['snapshot_count'] = volume_stats['snapshot_count'] - 1 + volume_stats_raw = json.dumps(volume_stats) + zkhandler.writedata(zk_conn, { + '/ceph/volumes/{}/{}/stats'.format(pool, volume): volume_stats_raw + }) + return True, 'Removed RBD snapshot "{}" of volume "{}" in pool "{}".'.format(name, volume, pool)