loadbalancer.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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/jsonutils"
  17. "yunion.io/x/onecloud/pkg/apis"
  18. "yunion.io/x/onecloud/pkg/apis/billing"
  19. billing_api "yunion.io/x/onecloud/pkg/apis/billing"
  20. "yunion.io/x/onecloud/pkg/util/ansible"
  21. )
  22. type LoadbalancerAgentDeployInput struct {
  23. apis.Meta
  24. Host ansible.Host `json:"host"`
  25. DeployMethod string `json:"deploy_method"`
  26. }
  27. const (
  28. DeployMethodYum = "yum"
  29. DeployMethodCopy = "copy"
  30. )
  31. type LoadbalancerListInput struct {
  32. apis.VirtualResourceListInput
  33. apis.ExternalizedResourceBaseListInput
  34. apis.DeletePreventableResourceBaseListInput
  35. billing.BillingResourceListInput
  36. VpcFilterListInput
  37. ZonalFilterListBase
  38. NetworkFilterListBase
  39. // filter by cluster
  40. Cluster string `json:"cluster"`
  41. Address []string `json:"address"`
  42. // 地址类型
  43. AddressType []string `json:"address_type"`
  44. // 网络类型
  45. NetworkType []string `json:"network_type"`
  46. // 计费类型
  47. ChargeType []string `json:"charge_type"`
  48. // 套餐名称
  49. LoadbalancerSpec []string `json:"loadbalancer_spec"`
  50. // filter by security group
  51. SecgroupId string `json:"secgroup_id"`
  52. // filter for EIP
  53. WithEip *bool `json:"with_eip"`
  54. WithoutEip *bool `json:"without_eip"`
  55. EipAssociable *bool `json:"eip_associable"`
  56. UsableLoadbalancerForEip string `json:"usable_loadbalancer_for_eip"`
  57. }
  58. type LbEip struct {
  59. // 公网IP地址
  60. Eip string `json:"eip"`
  61. EipId string `json:"eip_id"`
  62. // 公网IP地址类型: 弹性、非弹性
  63. // example: public_ip
  64. EipMode string `json:"eip_mode"`
  65. }
  66. type LoadbalancerDetails struct {
  67. apis.VirtualResourceDetails
  68. ManagedResourceInfo
  69. LoadbalancerClusterResourceInfo
  70. VpcResourceInfoBase
  71. CloudregionResourceInfo
  72. ZoneResourceInfoBase
  73. Zone1ResourceInfoBase
  74. NetworkResourceInfoBase
  75. SLoadbalancer
  76. LbEip
  77. Eips []LbEip `json:"eips"`
  78. // 后端服务器组名称
  79. BackendGroup string `json:"backend_group"`
  80. // 关联安全组列表
  81. Secgroups []SimpleSecurityGroup `json:"secgroups"`
  82. LoadbalancerUsage
  83. }
  84. type LoadbalancerUsage struct {
  85. BackendGroupCount int `json:"backend_group_count"`
  86. ListenerCount int `json:"listener_count"`
  87. }
  88. type SimpleSecurityGroup struct {
  89. Id string `json:"id"`
  90. Name string `json:"name"`
  91. }
  92. type LoadbalancerResourceInfo struct {
  93. // 负载均衡名称
  94. Loadbalancer string `json:"loadbalancer"`
  95. // VPC ID
  96. VpcId string `json:"vpc_id"`
  97. VpcResourceInfo
  98. // 可用区ID
  99. ZoneId string `json:"zone_id"`
  100. ZoneResourceInfo
  101. // cloud provider info
  102. ManagedResourceInfo
  103. }
  104. type LoadbalancerResourceInput struct {
  105. // 负载均衡名称
  106. LoadbalancerId string `json:"loadbalancer_id"`
  107. // swagger:ignore
  108. // Deprecated
  109. Loadbalancer string `json:"loadbalancer" yunion-deprecated-by:"loadbalancer_id"`
  110. }
  111. type LoadbalancerFilterListInput struct {
  112. VpcFilterListInput
  113. ZonalFilterListBase
  114. LoadbalancerResourceInput
  115. // 以负载均衡名称排序
  116. OrderByLoadbalancer string `json:"order_by_loadbalancer"`
  117. }
  118. type LoadbalancerCreateInput struct {
  119. apis.VirtualResourceCreateInput
  120. // IP地址
  121. Address string `json:"address"`
  122. // 地址类型
  123. AddressType string `json:"address_type"`
  124. // 网络类型
  125. NetworkType string `json:"network_type"`
  126. // 负载均衡集群Id
  127. ClusterId string `json:"cluster_id"`
  128. // 计费类型
  129. ChargeType string `json:"charge_type"`
  130. // 出口带宽
  131. EgressMbps int `json:"egress_mbps"`
  132. // 套餐名称
  133. LoadbalancerSpec string `json:"loadbalancer_spec"`
  134. // 弹性公网IP带宽
  135. // 指定此参数后会创建新的弹性公网IP并绑定到新建的负载均衡
  136. EipBw int `json:"eip_bw,omitzero"`
  137. // 弹性公网IP线路类型
  138. EipBgpType string `json:"eip_bgp_type,omitzero"`
  139. // 弹性公网IP计费类型
  140. EipChargeType billing_api.TNetChargeType `json:"eip_charge_type,omitempty"`
  141. // 是否跟随主机删除而自动释放
  142. EipAutoDellocate bool `json:"eip_auto_dellocate,omitempty"`
  143. // swagger:ignore
  144. Eip string `json:"eip" yunion-deprecated-by:"eip_id"`
  145. // EIP Id
  146. EipId string `json:"eip_id"`
  147. // LB的其他配置信息
  148. LBInfo jsonutils.JSONObject `json:"lb_info"`
  149. // 从可用区1
  150. // required: false
  151. Zone1 string `json:"zone_1"`
  152. // 包年包月时长
  153. Duration string `json:"duration"`
  154. // swagger:ignore
  155. BillingType billing_api.TBillingType `json:"billing_type"`
  156. // swagger:ignore
  157. BillingCycle string `json:"billing_cycle"`
  158. VpcResourceInput
  159. // Vpc string `json:"vpc"`
  160. ZoneResourceInput
  161. // Zone string `json:"zone"`
  162. CloudregionResourceInput
  163. // Cloudregion string `json:"cloudregion"`
  164. NetworkResourceInput
  165. // 多子网
  166. // swagger:ignore
  167. Networks []string `json:"networks"`
  168. // Network string `json:"network"`
  169. CloudproviderResourceInput
  170. // Manager string `json:"manager"`
  171. }
  172. type LoadbalancerRemoteUpdateInput struct {
  173. // 是否覆盖替换所有标签
  174. ReplaceTags *bool `json:"replace_tags" help:"replace all remote tags"`
  175. }
  176. type LoadbalancerAssociateEipInput struct {
  177. // 弹性公网IP的ID
  178. EipId string `json:"eip_id"`
  179. // 弹性IP映射的内网IP地址,可选
  180. IpAddr string `json:"ip_addr"`
  181. }
  182. type LoadbalancerCreateEipInput struct {
  183. // 计费方式,traffic or bandwidth
  184. ChargeType billing_api.TNetChargeType `json:"charge_type"`
  185. // Bandwidth
  186. Bandwidth int64 `json:"bandwidth"`
  187. // bgp_type
  188. BgpType string `json:"bgp_type"`
  189. // auto_dellocate
  190. AutoDellocate *bool `json:"auto_dellocate"`
  191. // 弹性IP映射的内网IP地址,可选
  192. // IpAddr string `json:"ip_addr"`
  193. }
  194. type LoadbalancerDissociateEipInput struct {
  195. // 是否自动释放
  196. AudoDelete *bool `json:"auto_delete"`
  197. }
  198. func (self LoadbalancerDetails) GetMetricTags() map[string]string {
  199. ret := map[string]string{
  200. "id": self.Id,
  201. "elb_id": self.Id,
  202. "brand": self.Brand,
  203. "backend_group": self.BackendGroup,
  204. "cloudregion": self.Cloudregion,
  205. "domain_id": self.DomainId,
  206. "project_domain": self.ProjectDomain,
  207. "region_ext_id": self.RegionExtId,
  208. "status": self.Status,
  209. "tenant": self.Project,
  210. "tenant_id": self.ProjectId,
  211. "account": self.Account,
  212. "account_id": self.AccountId,
  213. "external_id": self.ExternalId,
  214. }
  215. return AppendMetricTags(ret, self.MetadataResourceInfo, self.ProjectizedResourceInfo)
  216. }