input.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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. "time"
  17. "yunion.io/x/pkg/util/billing"
  18. "yunion.io/x/onecloud/pkg/httperrors"
  19. )
  20. type DomainizedResourceInput struct {
  21. // 指定项目归属域名称或ID
  22. // required: false
  23. ProjectDomainId string `json:"project_domain_id" help:"name or id of the belonging domain"`
  24. // swagger:ignore
  25. // Deprecated
  26. Domain string `json:"domain" yunion-deprecated-by:"project_domain_id"`
  27. // swagger:ignore
  28. // Deprecated
  29. // Project domain Id filter, alias for project_domain
  30. ProjectDomain string `json:"project_domain" yunion-deprecated-by:"project_domain_id"`
  31. // swagger:ignore
  32. // Deprecated
  33. // Domain Id filter, alias for project_domain
  34. DomainId string `json:"domain_id" yunion-deprecated-by:"project_domain_id"`
  35. }
  36. type ProjectizedResourceInput struct {
  37. // 指定项目的名称或ID
  38. // required: false
  39. ProjectId string `json:"project_id"`
  40. // swagger:ignore
  41. // Deprecated
  42. // Filter by project_id, alias for project
  43. Project string `json:"project" yunion-deprecated-by:"project_id"`
  44. // swagger:ignore
  45. // Deprecated
  46. // Filter by tenant ID or Name, alias for project
  47. Tenant string `json:"tenant" yunion-deprecated-by:"project_id"`
  48. // swagger:ignore
  49. // Deprecated
  50. // Filter by tenant_id, alias for project
  51. TenantId string `json:"tenant_id" yunion-deprecated-by:"project_id"`
  52. }
  53. type DomainizedResourceCreateInput struct {
  54. DomainizedResourceInput
  55. }
  56. type ProjectizedResourceCreateInput struct {
  57. DomainizedResourceInput
  58. ProjectizedResourceInput
  59. }
  60. type SharableResourceBaseCreateInput struct {
  61. // 是否共享
  62. // required: false
  63. IsPublic *bool `json:"is_public" token:"public" negative:"private" help:"Turn on/off public/private"`
  64. // 共享范围
  65. // required: false
  66. PublicScope string `json:"public_scope" help:"set public_scope, either project, domain or system" choices:"project|domain|system"`
  67. }
  68. type SharableVirtualResourceCreateInput struct {
  69. VirtualResourceCreateInput
  70. SharableResourceBaseCreateInput
  71. }
  72. type AdminSharableVirtualResourceBaseCreateInput struct {
  73. SharableVirtualResourceCreateInput
  74. // 记录
  75. Records string `json:"records"`
  76. }
  77. type StatusDomainLevelUserResourceCreateInput struct {
  78. StatusDomainLevelResourceCreateInput
  79. // 本地用户Id,若为空则使用当前用户Id作为此参数值
  80. OwnerId string `json:"owner_id"`
  81. }
  82. type UserResourceCreateInput struct {
  83. StandaloneResourceCreateInput
  84. // 本地用户Id,若为空则使用当前用户Id作为此参数值
  85. OwnerId string `json:"owner_id"`
  86. }
  87. type VirtualResourceCreateInput struct {
  88. StatusStandaloneResourceCreateInput
  89. ProjectizedResourceCreateInput
  90. // description: indicate the resource is a system resource, which is not visible to user
  91. // required: false
  92. IsSystem *bool `json:"is_system"`
  93. }
  94. type EnabledBaseResourceCreateInput struct {
  95. // 该资源是否被管理员*人为*启用或者禁用
  96. // required: false
  97. Enabled *bool `json:"enabled" help:"turn on enabled flag"`
  98. // 该资源是否被管理员*人为*禁用, 和enabled互斥
  99. // required: false
  100. Disabled *bool `json:"disabled" help:"turn off enabled flag"`
  101. }
  102. func (self *EnabledBaseResourceCreateInput) SetEnabled() {
  103. enabled := true
  104. self.Enabled = &enabled
  105. self.Disabled = nil
  106. }
  107. func (self *EnabledBaseResourceCreateInput) SetDisabled() {
  108. disabled := true
  109. self.Disabled = &disabled
  110. self.Enabled = nil
  111. }
  112. func (input *EnabledBaseResourceCreateInput) AfterUnmarshal() {
  113. if input.Disabled != nil && input.Enabled == nil {
  114. enabled := !(*input.Disabled)
  115. input.Enabled = &enabled
  116. }
  117. }
  118. type StatusBaseResourceCreateInput struct {
  119. // 用来存储资源的状态
  120. // required: false
  121. Status string `json:"status" help:"set initial status"`
  122. }
  123. type EnabledStatusDomainLevelResourceCreateInput struct {
  124. StatusDomainLevelResourceCreateInput
  125. EnabledBaseResourceCreateInput
  126. }
  127. type StatusDomainLevelResourceCreateInput struct {
  128. DomainLevelResourceCreateInput
  129. StatusBaseResourceCreateInput
  130. }
  131. type DomainLevelResourceCreateInput struct {
  132. StandaloneResourceCreateInput
  133. DomainizedResourceCreateInput
  134. }
  135. type EnabledStatusStandaloneResourceCreateInput struct {
  136. StatusStandaloneResourceCreateInput
  137. EnabledBaseResourceCreateInput
  138. }
  139. type StatusStandaloneResourceCreateInput struct {
  140. StandaloneResourceCreateInput
  141. StatusBaseResourceCreateInput
  142. }
  143. type StandaloneAnonResourceCreateInput struct {
  144. ResourceBaseCreateInput
  145. // 资源描述
  146. // required: false
  147. // example: test create network
  148. Description string `json:"description" token:"desc" help:"description"`
  149. // 资源是否为模拟资源
  150. // description: the resource is an emulated resource
  151. // required: false
  152. IsEmulated *bool `json:"is_emulated" token:"emulated" negative:"no_emulated" help:"set is_emulated flag"`
  153. // 标签列表,最多支持20个
  154. // example: { "user:rd": "op" }
  155. Metadata map[string]string `json:"__meta__" token:"tag" help:"tags in the form of key=value"`
  156. // 预检验参数,若为true则仅检查参数,并不真正创建变更
  157. // default: false
  158. DryRun bool `json:"dry_run"`
  159. }
  160. type StandaloneResourceCreateInput struct {
  161. StandaloneAnonResourceCreateInput
  162. // 资源名称,如果generate_name为空,则为必填项
  163. // description: resource name, required if generated_name is not given
  164. // unique: true
  165. // required: true
  166. // example: test-network
  167. Name string `json:"name" help:"name of newly created resource" positional:"true" required:"true"`
  168. // 生成资源名称的模板,如果name为空,则为必填项
  169. // description: generated resource name, given a pattern to generate name, required if name is not given
  170. // unique: false
  171. // required: false
  172. // example: test###
  173. GenerateName string `json:"generate_name" help:"pattern for generating name if no name is given"`
  174. }
  175. type JoinResourceBaseCreateInput struct {
  176. ResourceBaseCreateInput
  177. }
  178. type ResourceBaseCreateInput struct {
  179. ModelBaseCreateInput
  180. }
  181. type ModelBaseCreateInput struct {
  182. Meta
  183. }
  184. type PerformStatusInput struct {
  185. // 更改的目标状态值
  186. // required:true
  187. Status string `json:"status"`
  188. // swagger:ignore
  189. BlockJobsCount int `json:"block_jobs_count"`
  190. // 电源状态
  191. PowerStates string `json:"power_states"`
  192. // call from host id
  193. HostId string `json:"host_id"`
  194. // 更改状态的原因描述
  195. // required:false
  196. Reason string `json:"reason"`
  197. }
  198. type GetDetailsStatusOutput struct {
  199. // 状态
  200. Status string `json:"status"`
  201. }
  202. type PerformPublicDomainInput struct {
  203. // 共享项目资源的共享范围,可能的值为:project, domain和system
  204. // pattern: project|domain|system
  205. Scope string `json:"scope"`
  206. // 如果共享范围为域,则在此列表中指定共享的目标域
  207. SharedDomainIds []string `json:"shared_domain_ids"`
  208. // Deprecated
  209. // swagger:ignore
  210. SharedDomains []string `json:"shared_domains" yunion-deprecated-by:"shared_domain_ids"`
  211. }
  212. type PerformPublicProjectInput struct {
  213. PerformPublicDomainInput
  214. // 如果共享范围为项目,则在此列表中指定共享的目标项目
  215. SharedProjectIds []string `json:"shared_project_ids"`
  216. // Deprecated
  217. // swagger:ignore
  218. SharedProjects []string `json:"shared_projects" yunion-deprecated-by:"shared_project_ids"`
  219. }
  220. type PerformPrivateInput struct {
  221. }
  222. type PerformChangeProjectOwnerInput struct {
  223. DomainizedResourceInput
  224. ProjectizedResourceInput
  225. }
  226. type PerformFreezeInput struct {
  227. }
  228. type PerformUnfreezeInput struct {
  229. }
  230. type PerformChangeDomainOwnerInput struct {
  231. DomainizedResourceInput
  232. }
  233. type PerformEnableInput struct {
  234. }
  235. type PerformDisableInput struct {
  236. }
  237. type StorageForceDetachHostInput struct {
  238. // Host id or name
  239. HostId string `json:"host_id"`
  240. // Deprecated
  241. // swagger:ignore
  242. Host string `json:"host" yunion-deprecated-by:"host_id"`
  243. }
  244. type InfrasResourceBaseCreateInput struct {
  245. DomainLevelResourceCreateInput
  246. SharableResourceBaseCreateInput
  247. }
  248. type StatusInfrasResourceBaseCreateInput struct {
  249. InfrasResourceBaseCreateInput
  250. StatusBaseResourceCreateInput
  251. }
  252. type EnabledStatusInfrasResourceBaseCreateInput struct {
  253. StatusInfrasResourceBaseCreateInput
  254. EnabledBaseResourceCreateInput
  255. }
  256. type ScopedResourceCreateInput struct {
  257. ProjectizedResourceCreateInput
  258. Scope string `json:"scope"`
  259. }
  260. type OpsLogCreateInput struct {
  261. ModelBaseCreateInput
  262. ObjType string `json:"obj_type"`
  263. ObjId string `json:"obj_id"`
  264. ObjName string `json:"obj_name"`
  265. Action string `json:"action"`
  266. Notes string `json:"notes"`
  267. ProjectId string `json:"tenant_id"`
  268. Project string `json:"tenant"`
  269. ProjectDomainId string `json:"project_domain_id"`
  270. ProjectDomain string `json:"project_domain"`
  271. UserId string `json:"user_id"`
  272. User string `json:"user"`
  273. DomainId string `json:"domain_id"`
  274. Domain string `json:"domain"`
  275. Roles string `json:"roles"`
  276. OwnerDomainId string `json:"owner_domain_id"`
  277. OwnerProjectId string `json:"owner_tenant_id"`
  278. }
  279. // 设置资源的标签(元数据)输入
  280. type PerformMetadataInput map[string]string
  281. // 设置资源的用户标签(元数据)输入
  282. type PerformUserMetadataInput map[string]string
  283. // 全量替换资源的用户标签(元数据)输入
  284. type PerformSetUserMetadataInput map[string]string
  285. type PerformClassMetadataInput map[string]string
  286. type PerformSetClassMetadataInput map[string]string
  287. type GetClassMetadataInput struct {
  288. }
  289. type GetClassMetadataOutput map[string]string
  290. // 获取资源的元数据输入
  291. type GetMetadataInput struct {
  292. // 指定需要获取的所有标签的KEY列表,如果列表为空,则获取全部标签
  293. // 标签分为
  294. //
  295. // | 类型 | 说明 |
  296. // |----------|---------------------------------------------|
  297. // | 系统标签 | 平台定义的标签 |
  298. // | 用户标签 | key以user:为前缀,用户自定义标签 |
  299. // | 外部标签 | key以ext:为前缀,为从其他平台同步过来的标签 |
  300. //
  301. Field []string `json:"field"`
  302. // 按标签前缀过滤
  303. Prefix string `json:"prefix"`
  304. }
  305. // 获取资源标签(元数据)输出
  306. type GetMetadataOutput map[string]string
  307. type DistinctFieldInput struct {
  308. Field []string `json:"field"`
  309. ExtraField []string `json:"extra_field"`
  310. }
  311. type DistinctFieldsInput struct {
  312. Field []string `json:"field"`
  313. ExtraField []string `json:"extra_field"`
  314. ExtraResource string `json:"extra_resource"`
  315. }
  316. type PostpaidExpireInput struct {
  317. Duration string `json:"duration"`
  318. // swagger:ignore
  319. ExpireTime time.Time `json:"expire_time" yunion-deprecated-by:"release_at"`
  320. // 到期释放时间
  321. ReleaseAt time.Time `json:"release_at"`
  322. }
  323. func (input *PostpaidExpireInput) GetReleaseAt() (time.Time, error) {
  324. if !input.ReleaseAt.IsZero() {
  325. return input.ReleaseAt, nil
  326. }
  327. if len(input.Duration) == 0 {
  328. return time.Time{}, httperrors.NewInputParameterError("missing duration/expire_time")
  329. }
  330. bc, err := billing.ParseBillingCycle(input.Duration)
  331. if err != nil {
  332. return time.Time{}, httperrors.NewInputParameterError("invalid duration: %s", input.Duration)
  333. }
  334. return bc.EndAt(time.Now()), nil
  335. }
  336. type AutoRenewInput struct {
  337. // 是否自动续费
  338. AutoRenew bool `json:"auto_renew"`
  339. }
  340. type RenewInput struct {
  341. Duration string `json:"duration"`
  342. }
  343. type SyncstatusInput struct {
  344. }
  345. type PurgeSplitTableInput struct {
  346. Tables []string `json:"tables"`
  347. }
  348. const (
  349. MAX_SPLITABLE_EXPORT_LIMIT = 10000
  350. )
  351. type SplitTableExportInput struct {
  352. Table string `json:"table"`
  353. Offset int `json:"offset"`
  354. Limit int `json:"limit"`
  355. }