cephfs: update fetchIP to support ipv6 addresses

Signed-off-by: Riya Singhal <rsinghal@redhat.com>
This commit is contained in:
Riya Singhal 2023-11-06 11:54:47 +05:30 committed by mergify[bot]
parent 304462c7cc
commit 0631c15025

View File

@ -212,9 +212,12 @@ func (ac *activeClient) fetchIP() (string, error) {
clientInfo := ac.Inst clientInfo := ac.Inst
parts := strings.Fields(clientInfo) parts := strings.Fields(clientInfo)
if len(parts) >= 2 { if len(parts) >= 2 {
ip := strings.Split(parts[1], ":")[0] lastColonIndex := strings.LastIndex(parts[1], ":")
firstPart := parts[1][:lastColonIndex]
return ip, nil ip := net.ParseIP(firstPart)
if ip != nil {
return ip.String(), nil
}
} }
return "", fmt.Errorf("failed to extract IP address, incorrect format: %s", clientInfo) return "", fmt.Errorf("failed to extract IP address, incorrect format: %s", clientInfo)