package slownet
import (
"fmt"
"os"
"path/filepath"
"ascend-common/common-utils/utils"
)
const (
roceSubPath = "super-pod-roce"
pingListRangeFile = "ping_list_range.json"
)
func GetRoCEPingListFilePath(superPodId, serverIndex string) (string, error) {
rootPath, err := GetRasNetRootPath()
if err != nil {
return "", err
}
return filepath.Join(rootPath, netFaultSubPath, roceSubPath, fmt.Sprintf("ping_list_%s_%s.json",
superPodId, serverIndex)), nil
}
func GetPingListRangePath() (string, error) {
rootPath, err := GetRasNetRootPath()
if err != nil {
return "", err
}
return filepath.Join(rootPath, netFaultSubPath, roceSubPath, pingListRangeFile), nil
}
func CheckIsExistAndValid(filePath string) error {
if !utils.IsLexist(filePath) {
return fmt.Errorf("%s file is not exist", filePath)
}
fileInfo, errStat := os.Stat(filePath)
if errStat != nil {
return fmt.Errorf("get %s file status info failed, err: %v", filePath, errStat)
}
if fileInfo.Size() == 0 {
return fmt.Errorf("%s file content is empty", filePath)
}
return nil
}
func GetRackTopologyFilePath(superPodId, rackId, serverIndex int32) (string, error) {
rootPath, err := GetRasNetRootPath()
if err != nil {
return "", err
}
return filepath.Join(rootPath, netFaultSubPath, fmt.Sprintf("super-pod-%d", superPodId),
fmt.Sprintf("rack-%d", rackId), fmt.Sprintf("topo_%d.json", serverIndex)), nil
}