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.5 kB

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