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 2.8 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package models
  2. const (
  3. ResourceTypeCPU = "CPU"
  4. ResourceTypeNPU = "NPU"
  5. ResourceTypeGPU = "GPU"
  6. ResourceTypeMLU = "MLU"
  7. ResourceTypeStorage = "storage"
  8. ResourceTypeMemory = "memory"
  9. )
  10. type ResourceData interface{}
  11. type ResourceDataConst interface {
  12. ResourceData | CPUResourceData | NPUResourceData | GPUResourceData | MLUResourceData | StorageResourceData | MemoryResourceData
  13. }
  14. type DetailType[T any] struct {
  15. Unit string `json:"unit"`
  16. Value T `json:"value"`
  17. }
  18. type CPUResourceData struct {
  19. Name string `json:"name"`
  20. Total DetailType[int64] `json:"total"`
  21. Available DetailType[int64] `json:"available"`
  22. }
  23. func NewCPUResourceData(name string, total DetailType[int64], available DetailType[int64]) CPUResourceData {
  24. return CPUResourceData{
  25. Name: name,
  26. Total: total,
  27. Available: available,
  28. }
  29. }
  30. type NPUResourceData struct {
  31. Name string `json:"name"`
  32. Total DetailType[int64] `json:"total"`
  33. Available DetailType[int64] `json:"available"`
  34. }
  35. func NewNPUResourceData(name string, total DetailType[int64], available DetailType[int64]) NPUResourceData {
  36. return NPUResourceData{
  37. Name: name,
  38. Total: total,
  39. Available: available,
  40. }
  41. }
  42. type GPUResourceData struct {
  43. Name string `json:"name"`
  44. Total DetailType[int64] `json:"total"`
  45. Available DetailType[int64] `json:"available"`
  46. }
  47. func NewGPUResourceData(name string, total DetailType[int64], available DetailType[int64]) GPUResourceData {
  48. return GPUResourceData{
  49. Name: name,
  50. Total: total,
  51. Available: available,
  52. }
  53. }
  54. type MLUResourceData struct {
  55. Name string `json:"name"`
  56. Total DetailType[int64] `json:"total"`
  57. Available DetailType[int64] `json:"available"`
  58. }
  59. func NewMLUResourceData(name string, total DetailType[int64], available DetailType[int64]) MLUResourceData {
  60. return MLUResourceData{
  61. Name: name,
  62. Total: total,
  63. Available: available,
  64. }
  65. }
  66. type StorageResourceData struct {
  67. Name string `json:"name"`
  68. Total DetailType[float64] `json:"total"`
  69. Available DetailType[float64] `json:"available"`
  70. }
  71. func NewStorageResourceData(name string, total DetailType[float64], available DetailType[float64]) StorageResourceData {
  72. return StorageResourceData{
  73. Name: name,
  74. Total: total,
  75. Available: available,
  76. }
  77. }
  78. type MemoryResourceData struct {
  79. Name string `json:"name"`
  80. Total DetailType[float64] `json:"total"`
  81. Available DetailType[float64] `json:"available"`
  82. }
  83. func NewMemoryResourceData(name string, total DetailType[float64], available DetailType[float64]) MemoryResourceData {
  84. return MemoryResourceData{
  85. Name: name,
  86. Total: total,
  87. Available: available,
  88. }
  89. }