Skip to content

Commit

Permalink
Simplify the RBD image handling in create namespace
Browse files Browse the repository at this point in the history
Fixes #670

Signed-off-by: Gil Bregman <[email protected]>
  • Loading branch information
gbregman committed May 23, 2024
1 parent 8e73f52 commit 64c5602
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions control/cephutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 64c5602

Please sign in to comment.