output.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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 apis
  15. import (
  16. "strings"
  17. "time"
  18. "yunion.io/x/onecloud/pkg/httperrors"
  19. )
  20. const (
  21. EXTERNAL_RESOURCE_SOURCE_LOCAL = "local"
  22. EXTERNAL_RESOURCE_SOURCE_CLOUD = "cloud"
  23. )
  24. type ModelBaseDetails struct {
  25. Meta
  26. // 资源是否可以删除, 若为flase, delete_fail_reason会返回不能删除的原因
  27. // example: true
  28. CanDelete bool `json:"can_delete"`
  29. // 资源不能删除的原因
  30. DeleteFailReason httperrors.Error `json:"delete_fail_reason"`
  31. // 资源是否可以更新, 若为false,update_fail_reason会返回资源不能删除的原因
  32. // example: true
  33. CanUpdate bool `json:"can_update"`
  34. // 资源不能更新的原因
  35. UpdateFailReason httperrors.Error `json:"update_fail_reason"`
  36. }
  37. type ModelBaseShortDescDetail struct {
  38. ResName string `json:"res_name"`
  39. }
  40. type SharedProject struct {
  41. Id string `json:"id"`
  42. Name string `json:"name"`
  43. DomainId string `json:"domain_id"`
  44. Domain string `json:"domain"`
  45. }
  46. type SharedDomain struct {
  47. Id string `json:"id"`
  48. Name string `json:"name"`
  49. }
  50. type SharableResourceBaseInfo struct {
  51. // 共享的项目列表
  52. SharedProjects []SharedProject `json:"shared_projects"`
  53. // 共享的域列表
  54. SharedDomains []SharedDomain `json:"shared_domains"`
  55. }
  56. type SharableVirtualResourceDetails struct {
  57. VirtualResourceDetails
  58. SharableResourceBaseInfo
  59. }
  60. type AdminSharableVirtualResourceDetails struct {
  61. SharableVirtualResourceDetails
  62. }
  63. type StandaloneAnonResourceShortDescDetail struct {
  64. ModelBaseShortDescDetail
  65. Id string `json:"id"`
  66. }
  67. type StandaloneResourceShortDescDetail struct {
  68. StandaloneAnonResourceShortDescDetail
  69. Name string `json:"name"`
  70. }
  71. type EnabledStatusDomainLevelResourceDetails struct {
  72. StatusDomainLevelResourceDetails
  73. }
  74. type StatusDomainLevelResourceDetails struct {
  75. DomainLevelResourceDetails
  76. }
  77. type DomainLevelResourceDetails struct {
  78. StandaloneResourceDetails
  79. DomainizedResourceInfo
  80. }
  81. type VirtualResourceDetails struct {
  82. StatusStandaloneResourceDetails
  83. ProjectizedResourceInfo
  84. }
  85. type VirtualJointResourceBaseDetails struct {
  86. JointResourceBaseDetails
  87. }
  88. type JointResourceBaseDetails struct {
  89. ResourceBaseDetails
  90. }
  91. type ResourceBaseDetails struct {
  92. ModelBaseDetails
  93. }
  94. type EnabledStatusStandaloneResourceDetails struct {
  95. StatusStandaloneResourceDetails
  96. }
  97. type StatusStandaloneResourceDetails struct {
  98. StandaloneResourceDetails
  99. }
  100. type MetadataResourceInfo struct {
  101. // 标签
  102. Metadata map[string]string `json:"metadata"`
  103. }
  104. func (self MetadataResourceInfo) GetMetricTags() map[string]string {
  105. ret := map[string]string{}
  106. for k, v := range self.Metadata {
  107. if strings.HasPrefix(k, "user:") {
  108. if strings.Contains(k, "login_key") || strings.Contains(v, "=") {
  109. continue
  110. }
  111. ret[k] = v
  112. }
  113. }
  114. return ret
  115. }
  116. type StatusDomainLevelUserResourceDetails struct {
  117. StatusDomainLevelResourceDetails
  118. // 用户名称
  119. OwnerName string `json:"owner_name"`
  120. }
  121. type UserResourceDetails struct {
  122. StandaloneResourceDetails
  123. // 用户名称
  124. OwnerName string `json:"owner_name"`
  125. }
  126. type StandaloneAnonResourceDetails struct {
  127. ResourceBaseDetails
  128. MetadataResourceInfo
  129. }
  130. type StandaloneResourceDetails struct {
  131. StandaloneAnonResourceDetails
  132. }
  133. type DomainizedResourceInfo struct {
  134. // 资源归属项目的域名称
  135. ProjectDomain string `json:"project_domain"`
  136. }
  137. type ProjectizedResourceInfo struct {
  138. DomainizedResourceInfo
  139. // 资源归属项目的名称
  140. // alias:project
  141. Project string `json:"tenant"`
  142. // 资源归属项目的ID(向后兼容别名)
  143. // Deprecated
  144. TenantId string `json:"project_id" yunion-deprecated-by:"tenant_id"`
  145. // 资源归属项目的名称(向后兼容别名)
  146. // Deprecated
  147. Tenant string `json:"project" yunion-deprecated-by:"tenant"`
  148. ProjectMetadata map[string]string `json:"project_metadata"`
  149. }
  150. func (self ProjectizedResourceInfo) GetMetricTags() map[string]string {
  151. ret := map[string]string{}
  152. for k, v := range self.ProjectMetadata {
  153. if strings.HasPrefix(k, "user:") || strings.HasPrefix(k, "org:") {
  154. if strings.Contains(v, "=") {
  155. continue
  156. }
  157. ret["project:"+k] = v
  158. }
  159. }
  160. return ret
  161. }
  162. type ScopedResourceBaseInfo struct {
  163. ProjectizedResourceInfo
  164. Scope string `json:"scope"`
  165. }
  166. type InfrasResourceBaseDetails struct {
  167. DomainLevelResourceDetails
  168. SharableResourceBaseInfo
  169. }
  170. type StatusInfrasResourceBaseDetails struct {
  171. InfrasResourceBaseDetails
  172. }
  173. type EnabledStatusInfrasResourceBaseDetails struct {
  174. StatusInfrasResourceBaseDetails
  175. }
  176. type ChangeOwnerCandidateDomainsOutput struct {
  177. Candidates []SharedDomain `json:"candidates"`
  178. }
  179. type OpsLogDetails struct {
  180. ModelBaseDetails
  181. Id int64 `json:"id"`
  182. ObjType string `json:"obj_type"`
  183. ObjId string `json:"obj_id"`
  184. ObjName string `json:"obj_name"`
  185. Action string `json:"action"`
  186. Notes string `json:"notes"`
  187. ProjectId string `json:"tenant_id"`
  188. Project string `json:"tenant"`
  189. ProjectDomainId string `json:"project_domain_id"`
  190. ProjectDomain string `json:"project_domain"`
  191. UserId string `json:"user_id"`
  192. User string `json:"user"`
  193. DomainId string `json:"domain_id"`
  194. Domain string `json:"domain"`
  195. Roles string `json:"roles"`
  196. OpsTime time.Time `json:"ops_time"`
  197. OwnerDomainId string `json:"owner_domain_id"`
  198. OwnerProjectId string `json:"owner_project_id"`
  199. OwnerDomain string `json:"owner_domain"`
  200. OwnerProject string `json:"owner_tenant"`
  201. }
  202. type StatusStatisticStatusInfo struct {
  203. Status string `json:"status"`
  204. // 资源总数
  205. TotalCount int64 `json:"total_count"`
  206. // 回收站数量
  207. // 需要指定pending_delete=all
  208. PendingDeletedCount int64 `json:"pending_deleted_count"`
  209. }
  210. type StatusStatistic struct {
  211. StatusInfo []StatusStatisticStatusInfo `json:"status_info,allowempty"`
  212. // CPU总量
  213. TotalCpuCount int `json:"total_cpu_count"`
  214. // 内存总量
  215. TotalMemSizeMb int `json:"total_mem_size_mb"`
  216. // 存储总量
  217. TotalDiskSizeMb int `json:"total_disk_size_mb"`
  218. }
  219. type ProjectStatistic struct {
  220. Count int `json:"count"`
  221. Id string `json:"id"`
  222. Name string `json:"name"`
  223. }