volume.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package llm
  2. import (
  3. "fmt"
  4. "reflect"
  5. "yunion.io/x/jsonutils"
  6. "yunion.io/x/pkg/gotypes"
  7. "yunion.io/x/onecloud/pkg/apis"
  8. computeapi "yunion.io/x/onecloud/pkg/apis/compute"
  9. )
  10. func init() {
  11. gotypes.RegisterSerializable(reflect.TypeOf(&Volume{}), func() gotypes.ISerializable {
  12. return &Volume{}
  13. })
  14. gotypes.RegisterSerializable(reflect.TypeOf(&Volumes{}), func() gotypes.ISerializable {
  15. return &Volumes{}
  16. })
  17. gotypes.RegisterSerializable(reflect.TypeOf(&ContainerVolumeRelations{}), func() gotypes.ISerializable {
  18. return &ContainerVolumeRelations{}
  19. })
  20. }
  21. const (
  22. VOLUME_STATUS_READY = computeapi.DISK_READY
  23. VOLUME_STATUS_START_SYNC_STATUS = "start_syncstatus"
  24. VOLUME_STATUS_SYNC_STATUS = "syncstatus"
  25. VOLUME_STATUS_SYNC_STATUS_FAILED = "syncstatus_fail"
  26. VOLUME_STATUS_START_RESET = "start_reset"
  27. VOLUME_STATUS_RESETTING = "resetting"
  28. VOLUME_STATUS_RESET_FAILED = "reset_fail"
  29. VOLUME_STATUS_START_RESIZE = "start_resize"
  30. VOLUME_STATUS_RESIZING = "resizing"
  31. VOLUME_STATUS_RESIZE_FAILED = "resize_fail"
  32. VOLUME_STATUS_ASSIGNING = "assigning"
  33. )
  34. type VolumeDetails struct {
  35. apis.VirtualResourceDetails
  36. Volume
  37. Template string `json:"template"`
  38. DesktopId string `json:"desktop_id"`
  39. DesktopName string `json:"desktop_name"`
  40. DesktopStatus string `json:"desktop_status"`
  41. Disk string `json:"disk"`
  42. StorageId string `json:"storage_id"`
  43. Storage string `json:"storage"`
  44. StorageStatus string `json:"storage_status"`
  45. StorageHosts []computeapi.StorageHost `json:"storage_hosts"`
  46. Hosts []HostInfo `json:"hosts"`
  47. HostInfo
  48. InstanceId string `json:"instance_id"`
  49. InstanceName string `json:"instance_name"`
  50. }
  51. type ContainerVolumeRelation struct {
  52. MountPath string `json:"mount_path"`
  53. SubDirectory string `json:"sub_directory"`
  54. Overlay *apis.ContainerVolumeMountDiskOverlay `json:"overlay"`
  55. FsUser *int64 `json:"fs_user"`
  56. FsGroup *int64 `json:"fs_group"`
  57. }
  58. // key is string format of integer
  59. type ContainerVolumeRelations map[string]*ContainerVolumeRelation
  60. func (s ContainerVolumeRelations) String() string {
  61. return jsonutils.Marshal(s).String()
  62. }
  63. func (s ContainerVolumeRelations) IsZero() bool {
  64. return len(s) == 0
  65. }
  66. type Volume struct {
  67. // db.SStandaloneAnonResourceBase
  68. Id string `json:"id"`
  69. Name string `json:"name"`
  70. StorageType string `json:"storage_type"`
  71. TemplateId string `json:"template_id"`
  72. SizeMB int `json:"size_mb"`
  73. // Container index to mount path relation
  74. Containers ContainerVolumeRelations `json:"containers"`
  75. }
  76. func (s Volume) String() string {
  77. return jsonutils.Marshal(s).String()
  78. }
  79. func (s Volume) IsZero() bool {
  80. return s.SizeMB == 0
  81. }
  82. func (s Volume) GetVolumeByContainer(containerIndex int) *ContainerVolumeRelation {
  83. if len(s.Containers) == 0 {
  84. return nil
  85. }
  86. key := fmt.Sprintf("%d", containerIndex)
  87. return s.Containers[key]
  88. }
  89. type Volumes []Volume
  90. func (s Volumes) String() string {
  91. return jsonutils.Marshal(s).String()
  92. }
  93. func (s Volumes) IsZero() bool {
  94. return len(s) == 0
  95. }
  96. type VolumeCreateInput struct {
  97. apis.VirtualResourceCreateInput
  98. ImageId string `json:"image_id"`
  99. Size int `json:"size"`
  100. StorageType string `json:"storage_type"`
  101. PreferHost string `json:"prefer_host"`
  102. }
  103. type VolumePerformResetInput struct {
  104. SizeGb int `json:"size_gb"`
  105. }
  106. type VolumePerformResizeInput struct {
  107. Size string `json:"size"`
  108. }
  109. type VolumeResizeTaskInput struct {
  110. SizeMB int `json:"size_mb"`
  111. DesktopStatus string `json:"desktop_status"`
  112. }
  113. type VolumeListInput struct {
  114. apis.VirtualResourceListInput
  115. Host string `json:"host"`
  116. Unused *bool `json:"unused"`
  117. Size string `json:"size"`
  118. DesktopId string `json:"desktop_id"`
  119. }