mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 18:43:34 +00:00
rbd: add MakeVolumeGroupID() utility function
The Manager.MakeVolumeGroupID() function can be used to build a CSI VolumeGroupID from the backend (pool and name of the RBD-group). This will be used when checking if an RBD-image belongs to a group already. It is also possible to resolve the VolumeGroup by passing the VolumeGroupID to the existing Manager.GetVolumeGroupByID() function. Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
committed by
mergify[bot]
parent
a8ee0fe304
commit
32285c8365
@ -20,6 +20,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ceph/ceph-csi/internal/util"
|
||||
@ -166,6 +167,28 @@ func generateVolumeGroupName(namePrefix, groupUUID string) string {
|
||||
return namePrefix + groupUUID
|
||||
}
|
||||
|
||||
// MakeVolumeGroupID is a utility function that takes details of a VolumeGroup
|
||||
// and creates the CSI VolumeGroupId out of those.
|
||||
func MakeVolumeGroupID(clusterID string, poolID int64, name, prefix string) (string, error) {
|
||||
namePrefix := prefix
|
||||
if prefix == "" {
|
||||
namePrefix = defaultVolumeGroupNamingPrefix
|
||||
}
|
||||
|
||||
id, found := strings.CutPrefix(name, namePrefix)
|
||||
if !found {
|
||||
return "", fmt.Errorf("volume group name %q does not start with %q", name, namePrefix)
|
||||
}
|
||||
|
||||
handle := util.CSIIdentifier{
|
||||
ClusterID: clusterID,
|
||||
LocationID: poolID,
|
||||
ObjectUUID: id,
|
||||
}
|
||||
|
||||
return handle.ComposeCSIID()
|
||||
}
|
||||
|
||||
/*
|
||||
CheckReservation checks if given request name contains a valid reservation
|
||||
- If there is a valid reservation, then the corresponding VolumeGroupData for
|
||||
|
Reference in New Issue
Block a user