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.

models.go 3.7 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
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package uopsdk
  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 SlwNodeID int64
  16. type SlwNodeImageID int64
  17. type SlwNode struct {
  18. ID SlwNodeID `json:"ID"`
  19. Name string `json:"name"`
  20. SlwRegionID int64 `json:"slwRegionID"`
  21. StgNodeID int64 `json:"stgNodeID"`
  22. StorageID int64 `json:"StorageID"`
  23. }
  24. type ResourceData interface {
  25. Noop()
  26. }
  27. var ResourceDataTypeUnion = types.NewTypeUnion[ResourceData](
  28. myreflect.TypeOf[CPUResourceData](),
  29. myreflect.TypeOf[NPUResourceData](),
  30. myreflect.TypeOf[GPUResourceData](),
  31. myreflect.TypeOf[MLUResourceData](),
  32. myreflect.TypeOf[StorageResourceData](),
  33. myreflect.TypeOf[MemoryResourceData](),
  34. )
  35. var ResourceDataTaggedTypeUnion = serder.NewTaggedTypeUnion(ResourceDataTypeUnion, "Name", "name")
  36. type ResourceDataBase struct{}
  37. func (d *ResourceDataBase) Noop() {}
  38. type DetailType[T any] struct {
  39. Unit string `json:"unit"`
  40. Value T `json:"value"`
  41. }
  42. type CPUResourceData struct {
  43. ResourceDataBase
  44. Name string `json:"name" union:"CPU"`
  45. Total DetailType[int64] `json:"total"`
  46. Available DetailType[int64] `json:"available"`
  47. }
  48. func NewCPUResourceData(name string, total DetailType[int64], available DetailType[int64]) *CPUResourceData {
  49. return &CPUResourceData{
  50. Name: name,
  51. Total: total,
  52. Available: available,
  53. }
  54. }
  55. type NPUResourceData struct {
  56. ResourceDataBase
  57. Name string `json:"name" union:"NPU"`
  58. Total DetailType[int64] `json:"total"`
  59. Available DetailType[int64] `json:"available"`
  60. }
  61. func NewNPUResourceData(name string, total DetailType[int64], available DetailType[int64]) *NPUResourceData {
  62. return &NPUResourceData{
  63. Name: name,
  64. Total: total,
  65. Available: available,
  66. }
  67. }
  68. type GPUResourceData struct {
  69. ResourceDataBase
  70. Name string `json:"name" union:"GPU"`
  71. Total DetailType[int64] `json:"total"`
  72. Available DetailType[int64] `json:"available"`
  73. }
  74. func NewGPUResourceData(name string, total DetailType[int64], available DetailType[int64]) *GPUResourceData {
  75. return &GPUResourceData{
  76. Name: name,
  77. Total: total,
  78. Available: available,
  79. }
  80. }
  81. type MLUResourceData struct {
  82. ResourceDataBase
  83. Name string `json:"name" union:"MLU"`
  84. Total DetailType[int64] `json:"total"`
  85. Available DetailType[int64] `json:"available"`
  86. }
  87. func NewMLUResourceData(name string, total DetailType[int64], available DetailType[int64]) *MLUResourceData {
  88. return &MLUResourceData{
  89. Name: name,
  90. Total: total,
  91. Available: available,
  92. }
  93. }
  94. type StorageResourceData struct {
  95. ResourceDataBase
  96. Name string `json:"name" union:"STORAGE"`
  97. Total DetailType[float64] `json:"total"`
  98. Available DetailType[float64] `json:"available"`
  99. }
  100. func NewStorageResourceData(name string, total DetailType[float64], available DetailType[float64]) *StorageResourceData {
  101. return &StorageResourceData{
  102. Name: name,
  103. Total: total,
  104. Available: available,
  105. }
  106. }
  107. type MemoryResourceData struct {
  108. ResourceDataBase
  109. Name string `json:"name" union:"MEMORY"`
  110. Total DetailType[float64] `json:"total"`
  111. Available DetailType[float64] `json:"available"`
  112. }
  113. func NewMemoryResourceData(name string, total DetailType[float64], available DetailType[float64]) *MemoryResourceData {
  114. return &MemoryResourceData{
  115. Name: name,
  116. Total: total,
  117. Available: available,
  118. }
  119. }