2021-10-01 15:39:45 +00:00
|
|
|
//go:build !nautilus && ceph_preview
|
2021-09-16 09:45:22 +00:00
|
|
|
// +build !nautilus,ceph_preview
|
|
|
|
|
|
|
|
package admin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ImageSpec values are used to identify an RBD image wherever Ceph APIs
|
|
|
|
// require an image_spec/image_id_spec using image name/id and optional
|
|
|
|
// pool and namespace.
|
2021-10-01 15:35:37 +00:00
|
|
|
// PREVIEW
|
2021-09-16 09:45:22 +00:00
|
|
|
type ImageSpec struct {
|
|
|
|
spec string
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewImageSpec is used to construct an ImageSpec given an image name/id
|
|
|
|
// and optional namespace and pool names.
|
2021-10-01 15:35:37 +00:00
|
|
|
// PREVIEW
|
|
|
|
//
|
2021-09-16 09:45:22 +00:00
|
|
|
// NewImageSpec constructs an ImageSpec to identify an RBD image and thus
|
|
|
|
// requires image name/id, whereas NewLevelSpec constructs LevelSpec to
|
|
|
|
// identify entire pool, pool namespace or single RBD image, all of which
|
|
|
|
// requires pool name.
|
|
|
|
func NewImageSpec(pool, namespace, image string) ImageSpec {
|
|
|
|
var s string
|
|
|
|
if pool != "" && namespace != "" {
|
|
|
|
s = fmt.Sprintf("%s/%s/%s", pool, namespace, image)
|
|
|
|
} else if pool != "" {
|
|
|
|
s = fmt.Sprintf("%s/%s", pool, image)
|
|
|
|
} else {
|
|
|
|
s = image
|
|
|
|
}
|
|
|
|
return ImageSpec{s}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewRawImageSpec returns a ImageSpec directly based on the spec string
|
2021-10-01 15:35:37 +00:00
|
|
|
// argument without constructing it from component values.
|
|
|
|
// PREVIEW
|
|
|
|
//
|
|
|
|
// This should only be used if NewImageSpec can not create the imagespec value
|
|
|
|
// you want to pass to ceph.
|
2021-09-16 09:45:22 +00:00
|
|
|
func NewRawImageSpec(spec string) ImageSpec {
|
|
|
|
return ImageSpec{spec}
|
|
|
|
}
|