From 9edb3b8e728394a37e470a9455cc9c7f071b0889 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Wed, 24 Jun 2020 12:16:47 +0530 Subject: [PATCH] rbd: Add getImageID to get id of an image add a new function called getImageID to fetch the image id of an image which need to be stored and retrived for Delete operation. Signed-off-by: Madhu Rajanna --- internal/rbd/rbd_util.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index eac5d834e..604c5d5ce 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -235,6 +235,25 @@ func (rv *rbdVolume) openIoctx() error { return nil } +// getImageID queries rbd about the given image and stores its id, returns +// ErrImageNotFound if provided image is not found +func (rv *rbdVolume) getImageID() error { + if rv.ImageID != "" { + return nil + } + image, err := rv.open() + if err != nil { + return err + } + defer image.Close() + + id, err := image.GetId() + if err != nil { + return err + } + rv.ImageID = id + return nil +} // open the rbdVolume after it has been connected. // ErrPoolNotFound or ErrImageNotFound are returned in case the pool or image // can not be found, other errors will contain more details about other issues