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 <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2020-06-24 12:16:47 +05:30 committed by mergify[bot]
parent 9b518726ab
commit 9edb3b8e72

View File

@ -235,6 +235,25 @@ func (rv *rbdVolume) openIoctx() error {
return nil 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. // open the rbdVolume after it has been connected.
// ErrPoolNotFound or ErrImageNotFound are returned in case the pool or image // ErrPoolNotFound or ErrImageNotFound are returned in case the pool or image
// can not be found, other errors will contain more details about other issues // can not be found, other errors will contain more details about other issues