cloudprovider.go 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. "yunion.io/x/cloudmux/pkg/cloudprovider"
  17. "yunion.io/x/pkg/utils"
  18. "yunion.io/x/onecloud/pkg/apis"
  19. proxyapi "yunion.io/x/onecloud/pkg/apis/cloudcommon/proxy"
  20. )
  21. type ManagedResourceInfo struct {
  22. CloudaccountResourceInfo
  23. // 云账号Id
  24. // example: 4d3c8979-9dd0-439b-8d78-36fe1ab1666c
  25. AccountId string `json:"account_id,omitempty"`
  26. // 云订阅名称
  27. // example: google-account
  28. Manager string `json:"manager,omitempty"`
  29. // 子订阅所在项目名称
  30. // example: system
  31. ManagerProject string `json:"manager_project,omitempty"`
  32. // 子订阅所在项目Id
  33. // example: 4d3c8979-9dd0-439b-8d78-36fe1ab1666c
  34. ManagerProjectId string `json:"manager_project_id,omitempty"`
  35. // 子订阅所在域名称
  36. // example: Default
  37. ManagerDomain string `json:"manager_domain,omitempty"`
  38. // 子订阅所在域Id
  39. // example: default
  40. ManagerDomainId string `json:"manager_domain_id,omitempty"`
  41. }
  42. type SCloudproviderUsage struct {
  43. // 云主机数量
  44. // example: 1
  45. GuestCount int `json:"guest_count"`
  46. // 宿主机数量
  47. // example: 2
  48. HostCount int `json:"host_count"`
  49. // 虚拟私有网络数量
  50. // example: 4
  51. VpcCount int `json:"vpc_count"`
  52. // 块存储梳理
  53. // example: 4
  54. StorageCount int `json:"storage_count"`
  55. // 存储缓存数量
  56. // example: 1
  57. StorageCacheCount int `json:"storagecache_count"`
  58. // 弹性公网IP数量
  59. // example: 12
  60. EipCount int `json:"eip_count"`
  61. // 快照数量
  62. // example: 0
  63. SnapshotCount int `json:"snapshot_count"`
  64. // 负载均衡器数量
  65. // example: 2
  66. LoadbalancerCount int `json:"loadbalancer_count"`
  67. // 数据库实例数量
  68. // example: 2
  69. DBInstanceCount int `json:"dbinstance_count"`
  70. // 弹性缓存实例数量
  71. // example: 2
  72. ElasticcacheCount int `json:"elasticcache_count"`
  73. // 项目数量
  74. ProjectCount int `json:"project_count"`
  75. // 同步区域数量
  76. SyncRegionCount int `json:"sync_region_count"`
  77. }
  78. func (usage *SCloudproviderUsage) IsEmpty() bool {
  79. if usage.HostCount > 0 {
  80. return false
  81. }
  82. if usage.VpcCount > 0 {
  83. return false
  84. }
  85. if usage.StorageCount > 0 {
  86. return false
  87. }
  88. if usage.StorageCacheCount > 0 {
  89. return false
  90. }
  91. if usage.EipCount > 0 {
  92. return false
  93. }
  94. if usage.SnapshotCount > 0 {
  95. return false
  96. }
  97. if usage.LoadbalancerCount > 0 {
  98. return false
  99. }
  100. /*if usage.ProjectCount > 0 {
  101. return false
  102. }
  103. if usage.SyncRegionCount > 0 {
  104. return false
  105. }*/
  106. return true
  107. }
  108. type CloudproviderDetails struct {
  109. apis.EnabledStatusStandaloneResourceDetails
  110. apis.ProjectizedResourceInfo
  111. ProxySetting proxyapi.SProxySetting `json:"proxy_setting"`
  112. SCloudprovider
  113. // 云账号名称
  114. // example: google-account
  115. Cloudaccount string `json:"cloudaccount"`
  116. // 子订阅同步状态
  117. SyncStatus2 string `json:"sync_status2"`
  118. // 支持服务列表
  119. Capabilities []string `json:"capabilities"`
  120. SCloudproviderUsage
  121. // 子订阅品牌信息
  122. Brand string `json:"brand"`
  123. ReadOnly bool `json:"read_only"`
  124. ProjectMappingResourceInfo
  125. // 上次同步耗时
  126. LastSyncCost string `json:"last_sync_cost"`
  127. }
  128. // 云订阅输入参数
  129. type CloudproviderResourceInput struct {
  130. // 列出关联指定云订阅(ID或Name)的资源
  131. CloudproviderId string `json:"cloudprovider_id"`
  132. // List objects belonging to the cloud provider
  133. // swagger:ignore
  134. // Deprecated
  135. // description: this param will be deprecate at 3.0
  136. Manager string `json:"manager" yunion-deprecated-by:"cloudprovider_id"`
  137. // swagger:ignore
  138. // Deprecated
  139. // description: this param will be deprecate at 3.0
  140. ManagerId string `json:"manager_id" yunion-deprecated-by:"cloudprovider_id"`
  141. // swagger:ignore
  142. // Deprecated
  143. // description: this param will be deprecate at 3.0
  144. Cloudprovider string `json:"cloudprovider" yunion-deprecated-by:"cloudprovider_id"`
  145. }
  146. type CloudproviderResourceListInput struct {
  147. // 列出关联指定云订阅(ID或Name)的资源
  148. CloudproviderId []string `json:"cloudprovider_id"`
  149. // List objects belonging to the cloud provider
  150. // swagger:ignore
  151. // Deprecated
  152. // description: this param will be deprecate at 3.0
  153. Manager string `json:"manager" yunion-deprecated-by:"cloudprovider_id"`
  154. // swagger:ignore
  155. // Deprecated
  156. // description: this param will be deprecate at 3.0
  157. ManagerId string `json:"manager_id" yunion-deprecated-by:"cloudprovider_id"`
  158. // swagger:ignore
  159. // Deprecated
  160. // description: this param will be deprecate at 3.0
  161. Cloudprovider string `json:"cloudprovider" yunion-deprecated-by:"cloudprovider_id"`
  162. }
  163. type ManagedResourceListInput struct {
  164. apis.DomainizedResourceListInput
  165. CloudenvResourceListInput
  166. CloudproviderResourceListInput
  167. // 列出关联指定云账号(ID或Name)的资源
  168. CloudaccountId []string `json:"cloudaccount_id"`
  169. // swagger:ignore
  170. // Deprecated
  171. // description: this param will be deprecate at 3.0
  172. Cloudaccount []string `json:"cloudaccount" yunion-deprecated-by:"cloudaccount_id"`
  173. // swagger:ignore
  174. // Deprecated
  175. // description: this param will be deprecate at 3.0
  176. Account []string `json:"account" yunion-deprecated-by:"cloudaccount_id"`
  177. // swagger:ignore
  178. // Deprecated
  179. // description: this param will be deprecate at 3.0
  180. AccountId []string `json:"account_id" yunion-deprecated-by:"cloudaccount_id"`
  181. // 过滤资源,是否为非OneCloud内置私有云管理的资源
  182. // default: false
  183. IsManaged *bool `json:"is_managed"`
  184. // 以云账号名称排序
  185. // pattern:asc|desc
  186. OrderByAccount string `json:"order_by_account"`
  187. // 以云订阅名称排序
  188. // pattern:asc|desc
  189. OrderByManager string `json:"order_by_manager"`
  190. }
  191. func (input *ManagedResourceListInput) AfterUnmarshal() {
  192. if len(input.CloudEnv) > 0 {
  193. return
  194. }
  195. if (input.PublicCloud != nil && *input.PublicCloud) || (input.IsPublic != nil && *input.IsPublic) {
  196. input.CloudEnv = CLOUD_ENV_PUBLIC_CLOUD
  197. } else if (input.PrivateCloud != nil && *input.PrivateCloud) || (input.IsPrivate != nil && *input.IsPrivate) {
  198. input.CloudEnv = CLOUD_ENV_PRIVATE_CLOUD
  199. } else if input.IsOnPremise != nil && *input.IsOnPremise {
  200. input.CloudEnv = CLOUD_ENV_ON_PREMISE
  201. }
  202. }
  203. type CapabilityListInput struct {
  204. // 根据该云平台的功能对云账号或云订阅进行过滤
  205. Capability []string `json:"capability"`
  206. // swagger:ignore
  207. // Deprecated
  208. // filter by HasObjectStorage
  209. HasObjectStorage *bool `json:"has_object_storage"`
  210. }
  211. type CloudproviderListInput struct {
  212. apis.EnabledStatusStandaloneResourceListInput
  213. ManagedResourceListInput
  214. apis.ProjectizedResourceListInput
  215. apis.ExternalizedResourceBaseListInput
  216. UsableResourceListInput
  217. CloudregionResourceInput
  218. ZoneResourceInput
  219. CapabilityListInput
  220. SyncableBaseResourceListInput
  221. ReadOnly *bool `json:"read_only"`
  222. // 账号健康状态
  223. HealthStatus []string `json:"health_status"`
  224. // filter by host schedtag
  225. HostSchedtagId string `json:"host_schedtag_id"`
  226. }
  227. func (input *CapabilityListInput) AfterUnmarshal() {
  228. if input.HasObjectStorage != nil && *input.HasObjectStorage && !utils.IsInStringArray(cloudprovider.CLOUD_CAPABILITY_OBJECTSTORE, input.Capability) {
  229. input.Capability = append(input.Capability, cloudprovider.CLOUD_CAPABILITY_OBJECTSTORE)
  230. }
  231. }
  232. type SyncableBaseResourceListInput struct {
  233. // 同步状态
  234. SyncStatus []string `json:"sync_status"`
  235. }
  236. type CloudproviderUpdateInput struct {
  237. apis.EnabledStatusStandaloneResourceBaseUpdateInput
  238. }
  239. type CloudproviderCreateInput struct {
  240. }
  241. type CloudproviderGetStorageClassInput struct {
  242. CloudregionResourceInput
  243. }
  244. type CloudproviderGetStorageClassOutput struct {
  245. // 对象存储存储类型
  246. StorageClasses []string `json:"storage_classes"`
  247. }
  248. type CloudproviderGetCannedAclInput struct {
  249. CloudregionResourceInput
  250. }
  251. type CloudproviderGetCannedAclOutput struct {
  252. // Bucket支持的预置ACL列表
  253. BucketCannedAcls []string `json:"bucket_canned_acls"`
  254. // Object支持的预置ACL列表
  255. ObjectCannedAcls []string `json:"object_canned_acls"`
  256. }
  257. type CloudproviderSync struct {
  258. // 指定区域启用或禁用同步
  259. // default: false
  260. Enabled bool `json:"enabled"`
  261. // 指定区域信息
  262. CloudregionIds []string `json:"cloudregion_ids"`
  263. }