dbinstance.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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. "strings"
  17. "time"
  18. "yunion.io/x/onecloud/pkg/apis"
  19. billing_api "yunion.io/x/onecloud/pkg/apis/billing"
  20. )
  21. type DBInstanceCreateInput struct {
  22. apis.VirtualResourceCreateInput
  23. DeletePreventableCreateInput
  24. // Ip子网名称或Id,建议使用Id
  25. // 谷歌云并不实际使用Ip子网,仅仅通过Ip子网确定Vpc
  26. // required: true
  27. NetworkId string `json:"network_id"`
  28. // swagger:ignore
  29. Network string `json:"network" yunion-deprecated-by:"network_id"`
  30. // Ip子网内的地址,不填则按照ip子网的地址分配策略分配一个ip
  31. // required: false
  32. Address string `json:"address"`
  33. // rds实例名称或Id,建议使用Id
  34. // 创建只读实例时此参数必传
  35. MasterInstance string `json:"master_instance"`
  36. // swagger:ignore
  37. MasterInstanceId string `json:"master_instance_id"`
  38. // 安全组Id列表
  39. //
  40. //
  41. // | 云平台 | 最大支出安全组数量 |
  42. // |-------------|---------- |
  43. // | 腾讯云 | 5 |
  44. // | 华为云 | 1 |
  45. // | 阿里云 | 不支持 |
  46. SecgroupIds []string `json:"secgroup_ids"`
  47. // swagger:ignore
  48. Secgroup string `json:"secgroup" yunion-deprecated-by:"secgroup_ids"`
  49. // 主可用区名称或Id, 此参数从指定的套餐所在的可用区获取
  50. Zone1 string `json:"zone1"`
  51. // 次可用区名称或Id, 此参数从指定的套餐所在的可用区获取
  52. Zone2 string `json:"zone2"`
  53. // 三节点可用区名称或Id,, 此参数从指定的套餐所在的可用区获取
  54. Zone3 string `json:"zone3"`
  55. // swagger:ignore
  56. ZoneId string `json:"zone_id"`
  57. // swagger:ignore
  58. CloudregionId string `json:"cloudregion_id"`
  59. // swagger:ignore
  60. VpcId string `json:"vpc_id"`
  61. // swagger:ignore
  62. ManagerId string `json:"manager_id"`
  63. // 包年包月时间周期
  64. Duration string `json:"duration"`
  65. // 是否自动续费(仅包年包月时生效)
  66. // default: false
  67. AutoRenew bool `json:"auto_renew"`
  68. // 到期释放时间
  69. ReleaseAt time.Time `json:"release_at"`
  70. // 计费方式
  71. // enum: ["postpaid", "prepaid"]
  72. BillingType billing_api.TBillingType `json:"billing_type"`
  73. // swagger:ignore
  74. BillingCycle string `json:"billing_cycle"`
  75. // 套餐名称, 若此参数不填, 则必须有vmem_size_mb及vcpu_count参数
  76. // 套餐列表可以通过 dbinstancesku 获取
  77. InstanceType string `json:"instance_type"`
  78. // rds引擎
  79. // enum: ["MySQL", "SQLServer", "PostgreSQL", "MariaDB", "Oracle", "PPAS"]
  80. // required: true
  81. Engine string `json:"engine"`
  82. // rds引擎版本
  83. // 根据各个引擎版本各不相同
  84. // required: true
  85. EngineVersion string `json:"engine_version"`
  86. // rds类型
  87. //
  88. //
  89. //
  90. // | 平台 | 支持类型 | 说明 |
  91. // | ----- | ------ | --- |
  92. // | 华为云 |ha, single, replica| ha: 高可用, single: 单机, replica: 只读|
  93. // | 阿里云 |basic, high_availability, always_on, finance|basic: 基础版, high_availability: 高可用, always_on: 集群版, finance: 金融版, 三节点|
  94. // | Google |Zonal, Regional | Zonal: 单区域, Regional: 区域级|
  95. // | 腾讯云 |fe, ha, basic | ha: 高可用, basic: 基础版, fe: 金融版|
  96. // required: true
  97. Category string `json:"category"`
  98. // rds存储类型
  99. //
  100. //
  101. //
  102. // | 平台 | 支持类型 | 说明 |
  103. // | ----- | ------ | --- |
  104. // | 华为云 |SSD, SAS, SATA| |
  105. // | 阿里云 |local_ssd, cloud_essd, cloud_ssd| |
  106. // | Google |PD_SSD, PD_HDD| PD_SSD: SSD, PD_HDD: HDD|
  107. // | 腾讯云 |cloud_ssd, local_ssd| |
  108. // required: true
  109. StorageType string `json:"storage_type"`
  110. // rds存储大小
  111. // 可参考rds套餐的大小范围和步长情况
  112. // required: true
  113. DiskSizeGB int `json:"disk_size_gb"`
  114. // 指定连接端口
  115. Port int `json:"port"`
  116. // rds初始化密码
  117. // 阿里云不需要此参数
  118. // 华为云会默认创建一个用户,若不传此参数, 则为随机密码
  119. // 谷歌云会默认创建一个用户,若不传此参数, 则为随机密码
  120. // 腾讯云会默认创建一个用户,若不传此参数, 则为随机密码
  121. Password string `json:"password"`
  122. // 是否不设置初始密码
  123. // 华为云不支持此参数
  124. // 谷歌云仅mysql支持此参数
  125. ResetPassword *bool `json:"reset_password"`
  126. // rds实例cpu大小
  127. // 若指定实例套餐,此参数将根据套餐设置
  128. VcpuCount int `json:"vcpu_count"`
  129. // rds实例内存大小
  130. // 若指定实例套餐,此参数将根据套餐设置
  131. VmemSizeMb int `json:"vmem_size_mb"`
  132. // 从备份中创建新实例
  133. DBInstancebackupId string `json:"dbinstancebackup_id"`
  134. // 多可用区部署
  135. MultiAZ bool `json:"multi_az"`
  136. }
  137. type SDBInstanceChangeConfigInput struct {
  138. apis.Meta
  139. InstanceType string `json:"instance_type"`
  140. DiskSizeGB int `json:"disk_size_gb"`
  141. }
  142. type SDBInstanceRecoveryConfigInput struct {
  143. apis.Meta
  144. // swagger:ignore
  145. DBInstancebackup string `json:"dbinstancebackup" yunion-deprecated-by:"dbinstancebackup_id"`
  146. // 备份Id
  147. //
  148. //
  149. // | 平台 | 支持引擎 | 说明 |
  150. // | ----- | ------ | --- |
  151. // | 华为云 |MySQL, SQL Server | 仅SQL Server支持恢复到当前实例 |
  152. // | 阿里云 |MySQL, SQL Server | MySQL要求必须开启单库单表恢复功能 并且只能是MySQL 8.0 高可用版(本地SSD盘)MySQL 5.7 高可用版(本地SSD盘)或MySQL 5.6 高可用版, MySQL仅支持恢复到当前实例|
  153. // | Google |MySQL, PostgreSQL, SQL Server | PostgreSQL备份恢复时,要求实例不能有副本 |
  154. DBInstancebackupId string `json:"dbinstancebackup_id"`
  155. // 数据库信息, 例如 {"src":"dest"} 是将备份中的src数据库恢复到目标实例的dest数据库中, 阿里云此参数为必传
  156. // example: {"sdb1":"ddb1"}
  157. Databases map[string]string `json:"databases,allowempty"`
  158. }
  159. type DBInstanceListInput struct {
  160. apis.VirtualResourceListInput
  161. apis.ExternalizedResourceBaseListInput
  162. apis.DeletePreventableResourceBaseListInput
  163. VpcFilterListInput
  164. ZoneResourceInput
  165. MasterInstance string `json:"master_instance"`
  166. VcpuCount int `json:"vcpu_count"`
  167. VmemSizeMb int `json:"vmem_size_mb"`
  168. StorageType string `json:"storage_type"`
  169. Category string `json:"category"`
  170. Engine string `json:"engine"`
  171. EngineVersion string `json:"engine_version"`
  172. InstanceType string `json:"instance_type"`
  173. // 通过IP搜索RDS实例
  174. IpAddr []string `json:"ip_addr"`
  175. // 通过安全组Id过滤RDS实例
  176. SecgroupId string `json:"secgroup_id"`
  177. }
  178. type DBInstanceBackupListInput struct {
  179. apis.VirtualResourceListInput
  180. apis.ExternalizedResourceBaseListInput
  181. ManagedResourceListInput
  182. RegionalFilterListInput
  183. DBInstanceFilterListInputBase
  184. // RDS引擎
  185. // example: MySQL
  186. Engine []string `json:"engine"`
  187. // RDS引擎版本
  188. // example: 5.7
  189. EngineVersion []string `json:"engine_version"`
  190. // 备份模式
  191. BackupMode []string `json:"backup_mode"`
  192. // 数据库名称
  193. DBNames string `json:"db_names"`
  194. }
  195. type DBInstancePrivilegeListInput struct {
  196. apis.ResourceBaseListInput
  197. apis.ExternalizedResourceBaseListInput
  198. // filter by dbinstanceaccount
  199. Dbinstanceaccount string `json:"dbinstanceaccount"`
  200. // filter by dbinstancedatabase
  201. Dbinstancedatabase string `json:"dbinstancedatabase"`
  202. // 权限
  203. Privilege []string `json:"privilege"`
  204. }
  205. type DBInstanceParameterListInput struct {
  206. apis.StandaloneResourceListInput
  207. apis.ExternalizedResourceBaseListInput
  208. DBInstanceFilterListInput
  209. // 参数名称
  210. Key []string `json:"key"`
  211. // 参数值
  212. Value []string `json:"value"`
  213. }
  214. type DBInstanceDatabaseListInput struct {
  215. apis.StatusStandaloneResourceListInput
  216. apis.ExternalizedResourceBaseListInput
  217. DBInstanceFilterListInput
  218. // 数据库字符集
  219. CharacterSet []string `json:"character_set"`
  220. }
  221. type DBInstanceAccountListInput struct {
  222. apis.StatusStandaloneResourceListInput
  223. apis.ExternalizedResourceBaseListInput
  224. DBInstanceFilterListInput
  225. }
  226. type DBInstanceDetails struct {
  227. apis.VirtualResourceDetails
  228. CloudregionResourceInfo
  229. ManagedResourceInfo
  230. VpcResourceInfoBase
  231. SDBInstance
  232. Secgroups []apis.StandaloneShortDesc `json:"secgroups"`
  233. // 安全组名称
  234. // example: Default
  235. Secgroup string `json:"secgroup"`
  236. // iops
  237. // example: 0
  238. Iops int `json:"iops"`
  239. // IP子网名称, 若有多个以 ',' 分隔
  240. // example: test-network
  241. Network string `json:"network"`
  242. // 内网IP地址, 若有多个以 ',' 分隔
  243. IpAddrs string `json:"ip_addrs"`
  244. // Zone1名称
  245. Zone1Name string `json:"zone1_name"`
  246. // Zone2名称
  247. Zone2Name string `json:"zone2_name"`
  248. // Zone3名称
  249. Zone3Name string `json:"zone3_name"`
  250. Databases []apis.IdNameDetails `json:"databases"`
  251. }
  252. func (self DBInstanceDetails) GetMetricTags() map[string]string {
  253. ret := map[string]string{
  254. "id": self.Id,
  255. "rds_id": self.Id,
  256. "rds_name": self.Name,
  257. "zone": self.Zone1Name,
  258. "zone_id": self.Zone1,
  259. "status": self.Status,
  260. "engine": self.Engine,
  261. "server_type": strings.ToLower(self.Engine),
  262. "cloudregion": self.Cloudregion,
  263. "cloudregion_id": self.CloudregionId,
  264. "region_ext_id": self.RegionExtId,
  265. "tenant": self.Project,
  266. "tenant_id": self.ProjectId,
  267. "brand": self.Brand,
  268. "domain_id": self.DomainId,
  269. "account": self.Account,
  270. "account_id": self.AccountId,
  271. "project_domain": self.ProjectDomain,
  272. "external_id": self.ExternalId,
  273. }
  274. if len(self.IpAddrs) > 0 {
  275. ret["rds_ip"] = strings.ReplaceAll(self.IpAddrs, ",", "|")
  276. }
  277. return AppendMetricTags(ret, self.MetadataResourceInfo, self.ProjectizedResourceInfo)
  278. }
  279. func (self DBInstanceDetails) GetMetricPairs() map[string]string {
  280. ret := map[string]string{}
  281. return ret
  282. }
  283. type DBInstanceResourceInfoBase struct {
  284. // RDS实例名称
  285. DBInstance string `json:"dbinstance"`
  286. }
  287. type DBInstanceResourceInfo struct {
  288. DBInstanceResourceInfoBase
  289. // 归属VPC ID
  290. VpcId string `json:"vpc_id"`
  291. VpcResourceInfo
  292. }
  293. type DBInstanceResourceInput struct {
  294. // RDS实例(ID or Name)
  295. DBInstanceId string `json:"dbinstance_id"`
  296. // swagger:ignore
  297. // Deprecated
  298. DBInstance string `json:"dbinstance" yunion-deprecated-by:"dbinstance_id"`
  299. }
  300. type DBInstanceFilterListInputBase struct {
  301. DBInstanceResourceInput
  302. // 以RDS实例名字排序
  303. OrderByDBInstance string `json:"order_by_dbinstance"`
  304. }
  305. type DBInstanceFilterListInput struct {
  306. DBInstanceFilterListInputBase
  307. VpcFilterListInput
  308. }
  309. type DBInstanceJoinListInput struct {
  310. apis.VirtualJointResourceBaseListInput
  311. DBInstanceFilterListInput
  312. }
  313. type DBInstanceRemoteUpdateInput struct {
  314. // 是否覆盖替换所有标签
  315. ReplaceTags *bool `json:"replace_tags" help:"replace all remote tags"`
  316. }
  317. type DBInstanceNetworkListInput struct {
  318. DBInstanceJoinListInput
  319. NetworkFilterListInput
  320. }
  321. type DBInstanceAutoRenewInput struct {
  322. // 是否自动续费
  323. AutoRenew bool `json:"auto_renew"`
  324. }
  325. type DBInstanceSetSecgroupInput struct {
  326. SecgroupIds []string `json:"secgroup_ids"`
  327. }