From 64c56023d3918d3a08594d47c3b48198628f1868 Mon Sep 17 00:00:00 2001 From: Gil Bregman Date: Thu, 23 May 2024 21:34:50 +0300 Subject: [PATCH] Simplify the RBD image handling in create namespace Fixes #670 Signed-off-by: Gil Bregman --- control/cephutils.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/control/cephutils.py b/control/cephutils.py index 000722c9..f95c5a7c 100644 --- a/control/cephutils.py +++ b/control/cephutils.py @@ -140,17 +140,10 @@ def get_image_size(self, pool_name, image_name) -> int: with cluster.open_ioctx(pool_name) as ioctx: rbd_inst = rbd.RBD() try: - images = rbd_inst.list(ioctx) - if image_name in images: - try: - with rbd.Image(ioctx, image_name) as img: - img_stat = img.stat() - image_size = img_stat["size"] - except Exception as ex: - self.logger.exception(f"Can't get image object for {pool_name}/{image_name}") - raise ex - else: - raise rbd.ImageNotFound(f"Image {pool_name}/{image_name} doesn't exist", errno = errno.ENODEV) + with rbd.Image(ioctx, image_name) as img: + image_size = img.size() + except rbd.ImageNotFound: + raise rbd.ImageNotFound(f"Image {pool_name}/{image_name} doesn't exist", errno = errno.ENODEV) except Exception as ex: self.logger.exception(f"Error while trying to get the size of image {pool_name}/{image_name}") raise ex