util: move getMonsAndClusterID to util

as we had duplicate functions in both cephfs
and rbd this commit moves the function to util.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna
2020-08-10 11:57:28 +05:30
committed by mergify[bot]
parent 18f4e9d519
commit bfde065f92
3 changed files with 27 additions and 40 deletions

View File

@ -19,7 +19,6 @@ package cephfs
import (
"context"
"encoding/json"
"errors"
"fmt"
"time"
@ -135,8 +134,9 @@ func genSnapFromOptions(ctx context.Context, req *csi.CreateSnapshotRequest) (sn
cephfsSnap.RequestName = req.GetName()
snapOptions := req.GetParameters()
cephfsSnap.Monitors, cephfsSnap.ClusterID, err = getMonsAndClusterID(ctx, snapOptions)
cephfsSnap.Monitors, cephfsSnap.ClusterID, err = util.GetMonsAndClusterID(snapOptions)
if err != nil {
klog.Errorf(util.Log(ctx, "failed getting mons (%s)"), err)
return nil, err
}
if namePrefix, ok := snapOptions["snapshotNamePrefix"]; ok {
@ -145,23 +145,6 @@ func genSnapFromOptions(ctx context.Context, req *csi.CreateSnapshotRequest) (sn
return cephfsSnap, nil
}
func getMonsAndClusterID(ctx context.Context, options map[string]string) (monitors, clusterID string, err error) {
var ok bool
if clusterID, ok = options["clusterID"]; !ok {
err = errors.New("clusterID must be set")
return
}
if monitors, err = util.Mons(util.CsiConfigFile, clusterID); err != nil {
klog.Errorf(util.Log(ctx, "failed getting mons (%s)"), err)
err = fmt.Errorf("failed to fetch monitor list using clusterID (%s): %w", clusterID, err)
return
}
return
}
func parseTime(ctx context.Context, createTime string) (*timestamp.Timestamp, error) {
tm := &timestamp.Timestamp{}
layout := "2006-01-02 15:04:05.000000"