mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-22 06:10:22 +00:00
util: use go-ceph instead of "rados" command for GetPoolID()
GetPoolID() did not return ErrPoolNotFound in case the pool could not be found. This has been addressed as well, so that looking for an existing pool behaves the same for checking by Name or ID. Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
b0270ced41
commit
c9b4ee42e0
@ -26,6 +26,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/ceph/go-ceph/rados"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -86,21 +87,23 @@ func getPools(ctx context.Context, monitors string, cr *Credentials) ([]cephStor
|
|||||||
return pools, nil
|
return pools, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPoolID searches a list of pools in a cluster and returns the ID of the pool that matches
|
// GetPoolID fetches the ID of the pool that matches the passed in poolName
|
||||||
// the passed in poolName parameter
|
// parameter
|
||||||
func GetPoolID(ctx context.Context, monitors string, cr *Credentials, poolName string) (int64, error) {
|
func GetPoolID(ctx context.Context, monitors string, cr *Credentials, poolName string) (int64, error) {
|
||||||
pools, err := getPools(ctx, monitors, cr)
|
conn, err := connPool.Get(monitors, cr.ID, cr.KeyFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
defer connPool.Put(conn)
|
||||||
|
|
||||||
for _, p := range pools {
|
id, err := conn.GetPoolByName(poolName)
|
||||||
if poolName == p.Name {
|
if err == rados.ErrNotFound {
|
||||||
return p.Number, nil
|
return 0, ErrPoolNotFound{poolName, fmt.Errorf("pool (%s) not found in Ceph cluster", poolName)}
|
||||||
}
|
} else if err != nil {
|
||||||
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0, fmt.Errorf("pool (%s) not found in Ceph cluster", poolName)
|
return id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPoolName lists all pools in a ceph cluster, and matches the pool whose pool ID is equal to
|
// GetPoolName lists all pools in a ceph cluster, and matches the pool whose pool ID is equal to
|
||||||
|
Loading…
Reference in New Issue
Block a user