storage.go 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package compute
  15. import (
  16. "strconv"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/onecloud/pkg/apis"
  19. )
  20. type StorageUsage struct {
  21. HostCount int `json:"host_count"`
  22. DiskCount int `json:"disk_count"`
  23. SnapshotCount int `json:"snapshot_count"`
  24. Used int64 `json:"used"`
  25. Wasted int64 `json:"wasted"`
  26. }
  27. func (self StorageUsage) IsZero() bool {
  28. return self.HostCount+self.DiskCount+self.SnapshotCount == 0
  29. }
  30. type StorageHardwareInfo struct {
  31. Model *string `json:"model"`
  32. Vendor *string `json:"vendor"`
  33. Bandwidth float64 `json:"bandwidth" help:"Bandwidth of the device, and the unit is GB/s"`
  34. }
  35. type StorageCreateInput struct {
  36. apis.EnabledStatusInfrasResourceBaseCreateInput
  37. // 存储类型
  38. //
  39. //
  40. //
  41. // | storage_type | 参数 |是否必传 | 默认值 | 说明 |
  42. // | -------- | ------- | -------- | -------- | --------- |
  43. // | rbd | rbd_mon_host | 是 | | ceph mon_host |
  44. // | rbd | rbd_pool | 是 | | ceph pool |
  45. // | rbd | rbd_key | 否 | |若cephx认证开启,此参数必传 |
  46. // | rbd | rbd_rados_mon_op_timeout | 否 | 3 |单位: 秒 |
  47. // | rbd | rbd_rados_osd_op_timeout | 否 | 1200 |单位: 秒 |
  48. // | rbd | rbd_client_mount_timeout | 否 | 120 |单位: 秒 |
  49. // | nfs | nfs_host | 是 | |网络文件系统主机 |
  50. // | nfs | nfs_shared_dir | 是 | |网络文件系统共享目录 |
  51. // local: 本地存储
  52. // rbd: ceph块存储, ceph存储创建时仅会检测是否重复创建,不会具体检测认证参数是否合法,只有挂载存储时
  53. // 计算节点会验证参数,若挂载失败,宿主机和存储不会关联,可以通过查看存储日志查找挂载失败原因
  54. // enum: ["local", "rbd", "nfs", "gpfs"]
  55. // required: true
  56. StorageType string `json:"storage_type"`
  57. // 存储介质类型
  58. // enum: ["rotate", "ssd", "hybird"]
  59. // required: true
  60. // default: ssd
  61. MediumType string `json:"medium_type"`
  62. ZoneResourceInput
  63. // ceph认证主机, storage_type为 rbd 时,此参数为必传项
  64. // 单个ip或以逗号分隔的多个ip具体可查询 /etc/ceph/ceph.conf 文件
  65. // example: 192.168.222.3,192.168.222.4,192.168.222.99
  66. RbdMonHost string `json:"rbd_mon_host"`
  67. // enable ceph messenger v2
  68. EnableMessengerV2 *bool `json:"enable_messenger_v2"`
  69. // rbd storage auto cache glance images
  70. AutoCacheImages *bool `json:"auto_cache_images"`
  71. // swagger:ignore
  72. MonHost string `json:"mon_host"`
  73. // ceph使用的pool, storage_type为 rbd 时,此参数为必传项
  74. // example: rbd
  75. RbdPool string `json:"rbd_pool"`
  76. // swagger:ignore
  77. Pool string `json:"pool"`
  78. // ceph集群密码,若ceph集群开启cephx认证,此参数必传
  79. // 可在ceph集群主机的/etc/ceph/ceph.client.admin.keyring文件中找到
  80. // example: AQDigB9dtnDAKhAAxS6X4zi4BPR/lIle4nf4Dw==
  81. RbdKey string `json:"rbd_key"`
  82. // swagger:ignore
  83. Key string `json:"key"`
  84. RbdTimeoutInput
  85. // swagger:ignore
  86. ClientMountTimeout int `json:"client_mount_timeout"`
  87. // swagger:ignore
  88. StorageConf *jsonutils.JSONDict
  89. // 网络文件系统主机, storage_type 为 nfs 时,此参数必传
  90. // example: 192.168.222.2
  91. NfsHost string `json:"nfs_host"`
  92. // 网络文件系统共享目录, storage_type 为 nfs 时, 此参数必传
  93. // example: /nfs_root/
  94. NfsSharedDir string `json:"nfs_shared_dir"`
  95. // swagger:ignore
  96. HardwareInfo *StorageHardwareInfo `json:"hardware_info"`
  97. // CLVM VG Name
  98. CLVMVgName string `json:"clvm_vg_name"`
  99. // SLVM VG Name
  100. SLVMVgName string `json:"slvm_vg_name"`
  101. Lvmlockd bool `json:"lvmlockd"`
  102. }
  103. type RbdTimeoutInput struct {
  104. // ceph集群连接超时时间, 单位秒
  105. // default: 3
  106. RbdRadosMonOpTimeout int `json:"rbd_rados_mon_op_timeout"`
  107. // swagger:ignore
  108. RadosMonOpTimeout int `json:"rados_mon_op_timeout"`
  109. // ceph osd 操作超时时间, 单位秒
  110. // default: 1200
  111. RbdRadosOsdOpTimeout int `json:"rbd_rados_osd_op_timeout"`
  112. // swagger:ignore
  113. RadosOsdOpTimeout int `json:"rados_osd_op_timeout"`
  114. // ceph CephFS挂载超时时间, 单位秒
  115. // default: 120
  116. RbdClientMountTimeout int `json:"rbd_client_mount_timeout"`
  117. }
  118. type SStorageCapacityInfo struct {
  119. // 已使用容量大小
  120. UsedCapacity int64 `json:"used_capacity"`
  121. // 浪费容量大小(异常磁盘大小总和)
  122. WasteCapacity int64 `json:"waste_capacity"`
  123. // 虚拟容量大小
  124. VirtualCapacity int64 `json:"virtual_capacity"`
  125. // 超分率
  126. CommitRate float64 `json:"commit_rate"`
  127. // 可使用容量
  128. FreeCapacity int64 `json:"free_capacity"`
  129. }
  130. type StorageHost struct {
  131. Id string `json:"id"`
  132. Name string `json:"name"`
  133. Status string `json:"status"`
  134. HostStatus string `json:"host_status"`
  135. }
  136. type StorageDetails struct {
  137. apis.EnabledStatusInfrasResourceBaseDetails
  138. ManagedResourceInfo
  139. ZoneResourceInfo
  140. SStorage
  141. SStorageCapacityInfo
  142. ActualUsed int64 `json:"real_time_used_capacity,omitzero"`
  143. VCapacity int64 `json:"virtual_capacity,omitzero"`
  144. Hosts []StorageHost `json:"hosts"`
  145. Schedtags []SchedtagShortDescDetails `json:"schedtags"`
  146. StorageUsage `json:"storage_usage"`
  147. // 超分比
  148. CommitBound float32 `json:"commit_bound"`
  149. // master host name
  150. MasterHostName string `json:"master_host_name"`
  151. }
  152. func (self StorageDetails) GetMetricTags() map[string]string {
  153. ret := map[string]string{
  154. "id": self.Id,
  155. "storage_id": self.Id,
  156. "storage_name": self.Name,
  157. "brand": self.Brand,
  158. "domain_id": self.DomainId,
  159. "project_domain": self.ProjectDomain,
  160. "external_id": self.ExternalId,
  161. }
  162. return AppendMetricTags(ret, self.MetadataResourceInfo)
  163. }
  164. func (self StorageDetails) GetMetricPairs() map[string]string {
  165. usageActive := "0"
  166. if self.Capacity > 0 {
  167. usageActive = strconv.FormatFloat(float64(self.ActualCapacityUsed)/float64(self.Capacity)*100.0, 'f', -1, 64)
  168. }
  169. ret := map[string]string{
  170. "free": strconv.FormatFloat(float64(self.Capacity-self.ActualCapacityUsed), 'f', 2, 64),
  171. "usage_active": usageActive,
  172. }
  173. return ret
  174. }
  175. type StorageResourceInfo struct {
  176. // 归属云订阅ID
  177. ManagerId string `json:"manager_id"`
  178. ManagedResourceInfo
  179. // 归属可用区ID
  180. ZoneId string `json:"zone_id"`
  181. ZoneResourceInfo
  182. // 存储名称
  183. Storage string `json:"storage"`
  184. // 存储类型
  185. StorageType string `json:"storage_type"`
  186. // 存储介质类型
  187. MediumType string `json:"medium_type"`
  188. // 存储状态
  189. StorageStatus string `json:"storage_status"`
  190. }
  191. type StorageUpdateInput struct {
  192. apis.EnabledStatusInfrasResourceBaseUpdateInput
  193. // ceph集群密码,若ceph集群开启cephx认证,此参数必传
  194. // 可在ceph集群主机的/etc/ceph/ceph.client.admin.keyring文件中找到
  195. // example: AQDigB9dtnDAKhAAxS6X4zi4BPR/lIle4nf4Dw==
  196. RbdKey string `json:"rbd_key"`
  197. // enable ceph messenger v2
  198. EnableMessengerV2 *bool `json:"enable_messenger_v2"`
  199. // rbd storage auto cache glance images
  200. AutoCacheImages *bool `json:"auto_cache_images"`
  201. RbdTimeoutInput
  202. // swagger:ignore
  203. StorageConf *jsonutils.JSONDict `json:"storage_conf"`
  204. UpdateStorageConf bool `json:"update_storage_conf"`
  205. // swagger:ignore
  206. HardwareInfo *StorageHardwareInfo `json:"hardware_info"`
  207. MasterHost string `json:"master_host"`
  208. }
  209. type RbdStorageConf struct {
  210. RadosMonOpTimeout int `json:"rados_mon_op_timeout"`
  211. RadosOsdOpTimeout int `json:"rados_osd_op_timeout"`
  212. ClientMountTimeout int `json:"client_mount_timeout"`
  213. MonHost string `json:"mon_host"`
  214. Pool string `json:"pool"`
  215. Key string `json:"key"`
  216. EnableMessengerV2 bool `json:"enable_messenger_v2"`
  217. AutoCacheImages bool `json:"auto_cache_images"`
  218. }
  219. type StorageSetCmtBoundInput struct {
  220. Cmtbound *float32
  221. }