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

@ -18,6 +18,7 @@ package util
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"strings"
@ -111,3 +112,19 @@ func CephFSSubvolumeGroup(pathToConfig, clusterID string) (string, error) {
}
return cluster.CephFS.SubvolumeGroup, nil
}
// GetMonsAndClusterID returns monitors and clusterID information read from
// configfile.
func GetMonsAndClusterID(options map[string]string) (string, string, error) {
clusterID, ok := options["clusterID"]
if !ok {
return "", "", errors.New("clusterID must be set")
}
monitors, err := Mons(CsiConfigFile, clusterID)
if err != nil {
return "", "", fmt.Errorf("failed to fetch monitor list using clusterID (%s): %w", clusterID, err)
}
return monitors, clusterID, nil
}