You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

unifyops.go 3.6 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package models
  2. import (
  3. "gitlink.org.cn/cloudream/common/pkgs/types"
  4. myreflect "gitlink.org.cn/cloudream/common/utils/reflect"
  5. "gitlink.org.cn/cloudream/common/utils/serder"
  6. )
  7. const (
  8. ResourceTypeCPU = "CPU"
  9. ResourceTypeNPU = "NPU"
  10. ResourceTypeGPU = "GPU"
  11. ResourceTypeMLU = "MLU"
  12. ResourceTypeStorage = "STORAGE"
  13. ResourceTypeMemory = "MEMORY"
  14. )
  15. type SlwNode struct {
  16. ID int64 `json:"ID"`
  17. Name string `json:"name"`
  18. SlwRegionID int64 `json:"slwRegionID"`
  19. StgNodeID int64 `json:"stgNodeID"`
  20. StorageID int64 `json:"StorageID"`
  21. }
  22. type ResourceData interface{}
  23. type ResourceDataConst interface {
  24. ResourceData | CPUResourceData | NPUResourceData | GPUResourceData | MLUResourceData | StorageResourceData | MemoryResourceData
  25. }
  26. var ResourceDataTypeUnion = types.NewTypeUnion[ResourceData](
  27. myreflect.TypeOf[CPUResourceData](),
  28. myreflect.TypeOf[NPUResourceData](),
  29. myreflect.TypeOf[GPUResourceData](),
  30. myreflect.TypeOf[MLUResourceData](),
  31. myreflect.TypeOf[StorageResourceData](),
  32. myreflect.TypeOf[MemoryResourceData](),
  33. )
  34. var ResourceDataTaggedTypeUnion = serder.NewTaggedTypeUnion(ResourceDataTypeUnion, "Name", "name")
  35. type DetailType[T any] struct {
  36. Unit string `json:"unit"`
  37. Value T `json:"value"`
  38. }
  39. type CPUResourceData struct {
  40. Name string `json:"name" union:"CPU"`
  41. Total DetailType[int64] `json:"total"`
  42. Available DetailType[int64] `json:"available"`
  43. }
  44. func NewCPUResourceData(name string, total DetailType[int64], available DetailType[int64]) CPUResourceData {
  45. return CPUResourceData{
  46. Name: name,
  47. Total: total,
  48. Available: available,
  49. }
  50. }
  51. type NPUResourceData struct {
  52. Name string `json:"name" union:"NPU"`
  53. Total DetailType[int64] `json:"total"`
  54. Available DetailType[int64] `json:"available"`
  55. }
  56. func NewNPUResourceData(name string, total DetailType[int64], available DetailType[int64]) NPUResourceData {
  57. return NPUResourceData{
  58. Name: name,
  59. Total: total,
  60. Available: available,
  61. }
  62. }
  63. type GPUResourceData struct {
  64. Name string `json:"name" union:"GPU"`
  65. Total DetailType[int64] `json:"total"`
  66. Available DetailType[int64] `json:"available"`
  67. }
  68. func NewGPUResourceData(name string, total DetailType[int64], available DetailType[int64]) GPUResourceData {
  69. return GPUResourceData{
  70. Name: name,
  71. Total: total,
  72. Available: available,
  73. }
  74. }
  75. type MLUResourceData struct {
  76. Name string `json:"name" union:"MLU"`
  77. Total DetailType[int64] `json:"total"`
  78. Available DetailType[int64] `json:"available"`
  79. }
  80. func NewMLUResourceData(name string, total DetailType[int64], available DetailType[int64]) MLUResourceData {
  81. return MLUResourceData{
  82. Name: name,
  83. Total: total,
  84. Available: available,
  85. }
  86. }
  87. type StorageResourceData struct {
  88. Name string `json:"name" union:"STORAGE"`
  89. Total DetailType[float64] `json:"total"`
  90. Available DetailType[float64] `json:"available"`
  91. }
  92. func NewStorageResourceData(name string, total DetailType[float64], available DetailType[float64]) StorageResourceData {
  93. return StorageResourceData{
  94. Name: name,
  95. Total: total,
  96. Available: available,
  97. }
  98. }
  99. type MemoryResourceData struct {
  100. Name string `json:"name" union:"MEMORY"`
  101. Total DetailType[float64] `json:"total"`
  102. Available DetailType[float64] `json:"available"`
  103. }
  104. func NewMemoryResourceData(name string, total DetailType[float64], available DetailType[float64]) MemoryResourceData {
  105. return MemoryResourceData{
  106. Name: name,
  107. Total: total,
  108. Available: available,
  109. }
  110. }