2017-11-15 04:45:08 +00:00
|
|
|
package mapper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/rancher/norman/types"
|
|
|
|
"github.com/rancher/norman/types/convert"
|
2017-11-29 21:38:39 +00:00
|
|
|
"github.com/rancher/norman/types/values"
|
2017-11-15 04:45:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type OSInfo struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o OSInfo) FromInternal(data map[string]interface{}) {
|
2018-07-31 12:40:45 +00:00
|
|
|
if data == nil {
|
|
|
|
return
|
|
|
|
}
|
2017-11-15 04:45:08 +00:00
|
|
|
cpuInfo := map[string]interface{}{
|
2017-11-29 21:38:39 +00:00
|
|
|
"count": values.GetValueN(data, "capacity", "cpu"),
|
2017-11-15 04:45:08 +00:00
|
|
|
}
|
|
|
|
|
2017-11-29 21:38:39 +00:00
|
|
|
kib := strings.TrimSuffix(convert.ToString(values.GetValueN(data, "capacity", "memory")), "Ki")
|
2017-11-15 04:45:08 +00:00
|
|
|
memoryInfo := map[string]interface{}{}
|
|
|
|
|
|
|
|
kibNum, err := convert.ToNumber(kib)
|
|
|
|
if err == nil {
|
|
|
|
memoryInfo["memTotalKiB"] = kibNum
|
|
|
|
}
|
|
|
|
|
|
|
|
osInfo := map[string]interface{}{
|
2017-11-29 21:38:39 +00:00
|
|
|
"dockerVersion": strings.TrimPrefix(convert.ToString(values.GetValueN(data, "nodeInfo", "containerRuntimeVersion")), "docker://"),
|
|
|
|
"kernelVersion": values.GetValueN(data, "nodeInfo", "kernelVersion"),
|
|
|
|
"operatingSystem": values.GetValueN(data, "nodeInfo", "osImage"),
|
2017-11-15 04:45:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
data["info"] = map[string]interface{}{
|
|
|
|
"cpu": cpuInfo,
|
|
|
|
"memory": memoryInfo,
|
|
|
|
"os": osInfo,
|
|
|
|
"kubernetes": map[string]interface{}{
|
2017-11-29 21:38:39 +00:00
|
|
|
"kubeletVersion": values.GetValueN(data, "nodeInfo", "kubeletVersion"),
|
|
|
|
"kubeProxyVersion": values.GetValueN(data, "nodeInfo", "kubeletVersion"),
|
2017-11-15 04:45:08 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-05 04:44:54 +00:00
|
|
|
func (o OSInfo) ToInternal(data map[string]interface{}) error {
|
|
|
|
return nil
|
2017-11-15 04:45:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (o OSInfo) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
|
|
|
|
return nil
|
|
|
|
}
|