From ec61f0746b9e4fec5b2d57f06479723b5b7f29c4 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Fri, 13 Mar 2020 10:24:01 +0100 Subject: [PATCH] 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 --- internal/util/cephcmds.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/internal/util/cephcmds.go b/internal/util/cephcmds.go index 19ab4961a..fef15814b 100644 --- a/internal/util/cephcmds.go +++ b/internal/util/cephcmds.go @@ -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