|
|
@ -1,6 +1,7 @@
|
|
|
|
package util
|
|
|
|
package util
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"github.com/go-kratos/kratos/v2/log"
|
|
|
|
"github.com/go-kratos/kratos/v2/log"
|
|
|
@ -60,12 +61,18 @@ func DecodeNodeDevices(str string, log *log.Helper) ([]*DeviceInfo, error) {
|
|
|
|
for _, val := range tmp {
|
|
|
|
for _, val := range tmp {
|
|
|
|
if strings.Contains(val, ",") {
|
|
|
|
if strings.Contains(val, ",") {
|
|
|
|
items := strings.Split(val, ",")
|
|
|
|
items := strings.Split(val, ",")
|
|
|
|
if len(items) == 7 {
|
|
|
|
if len(items) >= 7 || len(items) == 9 {
|
|
|
|
count, _ := strconv.Atoi(items[1])
|
|
|
|
count, _ := strconv.ParseInt(items[1], 10, 32)
|
|
|
|
devmem, _ := strconv.Atoi(items[2])
|
|
|
|
devmem, _ := strconv.ParseInt(items[2], 10, 32)
|
|
|
|
devcore, _ := strconv.Atoi(items[3])
|
|
|
|
devcore, _ := strconv.ParseInt(items[3], 10, 32)
|
|
|
|
health, _ := strconv.ParseBool(items[6])
|
|
|
|
health, _ := strconv.ParseBool(items[6])
|
|
|
|
numa, _ := strconv.Atoi(items[5])
|
|
|
|
numa, _ := strconv.Atoi(items[5])
|
|
|
|
|
|
|
|
mode := "hami-core"
|
|
|
|
|
|
|
|
index := 0
|
|
|
|
|
|
|
|
if len(items) == 9 {
|
|
|
|
|
|
|
|
index, _ = strconv.Atoi(items[7])
|
|
|
|
|
|
|
|
mode = items[8]
|
|
|
|
|
|
|
|
}
|
|
|
|
i := DeviceInfo{
|
|
|
|
i := DeviceInfo{
|
|
|
|
ID: items[0],
|
|
|
|
ID: items[0],
|
|
|
|
AliasId: items[0],
|
|
|
|
AliasId: items[0],
|
|
|
@ -75,6 +82,8 @@ func DecodeNodeDevices(str string, log *log.Helper) ([]*DeviceInfo, error) {
|
|
|
|
Type: items[4],
|
|
|
|
Type: items[4],
|
|
|
|
Numa: numa,
|
|
|
|
Numa: numa,
|
|
|
|
Health: health,
|
|
|
|
Health: health,
|
|
|
|
|
|
|
|
Mode: mode,
|
|
|
|
|
|
|
|
Index: uint(index),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
retval = append(retval, &i)
|
|
|
|
retval = append(retval, &i)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -307,3 +316,9 @@ func DecodePodDevices(pod *corev1.Pod, log *log.Helper) (PodDevices, error) {
|
|
|
|
log.Infof("Decoded pod annos: poddevices %v", pd)
|
|
|
|
log.Infof("Decoded pod annos: poddevices %v", pd)
|
|
|
|
return pd, nil
|
|
|
|
return pd, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func UnMarshalNodeDevices(str string) ([]*DeviceInfo, error) {
|
|
|
|
|
|
|
|
var dlist []*DeviceInfo
|
|
|
|
|
|
|
|
err := json.Unmarshal([]byte(str), &dlist)
|
|
|
|
|
|
|
|
return dlist, err
|
|
|
|
|
|
|
|
}
|
|
|
|