|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- package models
-
- import (
- myreflect "gitlink.org.cn/cloudream/common/utils/reflect"
- "gitlink.org.cn/cloudream/common/utils/serder"
- )
-
- const (
- ResourceTypeCPU = "CPU"
- ResourceTypeNPU = "NPU"
- ResourceTypeGPU = "GPU"
- ResourceTypeMLU = "MLU"
- ResourceTypeStorage = "STORAGE"
- ResourceTypeMemory = "MEMORY"
- )
-
- type SlwNode struct {
- ID int64 `json:"ID"`
- Name string `json:"name"`
- SlwRegionID int64 `json:"slwRegionID"`
- }
-
- type ResourceData interface{}
- type ResourceDataConst interface {
- ResourceData | CPUResourceData | NPUResourceData | GPUResourceData | MLUResourceData | StorageResourceData | MemoryResourceData
- }
-
- var ResourceDataTypeUnion = serder.NewTypeUnion[ResourceData]("name",
- serder.NewStringTypeResolver().
- Add(ResourceTypeCPU, myreflect.TypeOf[CPUResourceData]()).
- Add(ResourceTypeNPU, myreflect.TypeOf[NPUResourceData]()).
- Add(ResourceTypeGPU, myreflect.TypeOf[GPUResourceData]()).
- Add(ResourceTypeMLU, myreflect.TypeOf[MLUResourceData]()).
- Add(ResourceTypeStorage, myreflect.TypeOf[StorageResourceData]()).
- Add(ResourceTypeMemory, myreflect.TypeOf[MemoryResourceData]()),
- )
-
- type DetailType[T any] struct {
- Unit string `json:"unit"`
- Value T `json:"value"`
- }
-
- type CPUResourceData struct {
- Name string `json:"name"`
- Total DetailType[int64] `json:"total"`
- Available DetailType[int64] `json:"available"`
- }
-
- func NewCPUResourceData(name string, total DetailType[int64], available DetailType[int64]) CPUResourceData {
- return CPUResourceData{
- Name: name,
- Total: total,
- Available: available,
- }
- }
-
- type NPUResourceData struct {
- Name string `json:"name"`
- Total DetailType[int64] `json:"total"`
- Available DetailType[int64] `json:"available"`
- }
-
- func NewNPUResourceData(name string, total DetailType[int64], available DetailType[int64]) NPUResourceData {
- return NPUResourceData{
- Name: name,
- Total: total,
- Available: available,
- }
- }
-
- type GPUResourceData struct {
- Name string `json:"name"`
- Total DetailType[int64] `json:"total"`
- Available DetailType[int64] `json:"available"`
- }
-
- func NewGPUResourceData(name string, total DetailType[int64], available DetailType[int64]) GPUResourceData {
- return GPUResourceData{
- Name: name,
- Total: total,
- Available: available,
- }
- }
-
- type MLUResourceData struct {
- Name string `json:"name"`
- Total DetailType[int64] `json:"total"`
- Available DetailType[int64] `json:"available"`
- }
-
- func NewMLUResourceData(name string, total DetailType[int64], available DetailType[int64]) MLUResourceData {
- return MLUResourceData{
- Name: name,
- Total: total,
- Available: available,
- }
- }
-
- type StorageResourceData struct {
- Name string `json:"name"`
- Total DetailType[float64] `json:"total"`
- Available DetailType[float64] `json:"available"`
- }
-
- func NewStorageResourceData(name string, total DetailType[float64], available DetailType[float64]) StorageResourceData {
- return StorageResourceData{
- Name: name,
- Total: total,
- Available: available,
- }
- }
-
- type MemoryResourceData struct {
- Name string `json:"name"`
- Total DetailType[float64] `json:"total"`
- Available DetailType[float64] `json:"available"`
- }
-
- func NewMemoryResourceData(name string, total DetailType[float64], available DetailType[float64]) MemoryResourceData {
- return MemoryResourceData{
- Name: name,
- Total: total,
- Available: available,
- }
- }
|