util: implement GetPoolName() with go-ceph

Remove an other call to the "rados" executable and re-use the existing
connection to the Ceph cluster.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2020-03-13 10:24:01 +01:00 committed by mergify[bot]
parent be8c3c4b72
commit ec61f0746b

View File

@ -106,21 +106,20 @@ func GetPoolID(monitors string, cr *Credentials, poolName string) (int64, error)
return id, nil
}
// GetPoolName lists all pools in a ceph cluster, and matches the pool whose pool ID is equal to
// the requested poolID parameter
// GetPoolName fetches the pool whose pool ID is equal to the requested poolID
// parameter
func GetPoolName(ctx context.Context, monitors string, cr *Credentials, poolID int64) (string, error) {
pools, err := getPools(ctx, monitors, cr)
conn, err := connPool.Get(monitors, cr.ID, cr.KeyFile)
if err != nil {
return "", err
}
defer connPool.Put(conn)
for _, p := range pools {
if poolID == p.Number {
return p.Name, nil
}
name, err := conn.GetPoolByID(poolID)
if err != nil {
return "", ErrPoolNotFound{string(poolID), fmt.Errorf("pool ID (%d) not found in Ceph cluster", poolID)}
}
return "", ErrPoolNotFound{string(poolID), fmt.Errorf("pool ID (%d) not found in Ceph cluster", poolID)}
return name, nil
}
// GetPoolIDs searches a list of pools in a cluster and returns the IDs of the pools that matches