loadbalancerbackend.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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/pkg/utils"
  17. "yunion.io/x/onecloud/pkg/apis"
  18. "yunion.io/x/onecloud/pkg/httperrors"
  19. )
  20. type LoadbalancerBackendDetails struct {
  21. apis.StatusStandaloneResourceDetails
  22. LoadbalancerBackendGroupResourceInfo
  23. SLoadbalancerBackend
  24. ProjectId string `json:"tenant_id"`
  25. }
  26. type LoadbalancerBackendListInput struct {
  27. apis.StatusStandaloneResourceListInput
  28. apis.ExternalizedResourceBaseListInput
  29. LoadbalancerBackendGroupFilterListInput
  30. // filter by backend server
  31. Backend string `json:"backend"`
  32. // filter by backend group
  33. // BackendGroup string `json:"backend_group"`
  34. BackendType []string `json:"backend_type"`
  35. BackendRole []string `json:"backend_role"`
  36. Address []string `json:"address"`
  37. SendProxy []string `json:"send_proxy"`
  38. Ssl []string `json:"ssl"`
  39. }
  40. type LoadbalancerBackendCreateInput struct {
  41. apis.StatusStandaloneResourceCreateInput
  42. //swagger:ignore
  43. BackendGroup string `json:"backend_group" yunion-deprecated-by:"backend_group_id"`
  44. BackendGroupId string `json:"backend_group_id"`
  45. //swagger:ignore
  46. Backend string `json:"backend" yunion-deprecated-by:"backend_id"`
  47. BackendId string `json:"backend_id"`
  48. BackendType string `json:"backend_type"`
  49. Weight int `json:"weight"`
  50. Port int `json:"port"`
  51. SendProxy string `json:"send_proxy"`
  52. Address string `json:"address"`
  53. Ssl string `json:"ssl"`
  54. }
  55. type LoadbalancerBackendUpdateInput struct {
  56. apis.StatusStandaloneResourceBaseUpdateInput
  57. Weight *int `json:"weight"`
  58. Port *int `json:"port"`
  59. SendPorxy *string `json:"send_proxy"`
  60. Ssl *string `json:"ssl"`
  61. }
  62. func (self *LoadbalancerBackendUpdateInput) Validate() error {
  63. if self.Weight != nil {
  64. if *self.Weight < 1 || *self.Weight > 100 {
  65. return httperrors.NewOutOfRangeError("weight out of range 1-100")
  66. }
  67. }
  68. if self.Port != nil {
  69. if *self.Port < 1 || *self.Port > 65535 {
  70. return httperrors.NewOutOfRangeError("port out of range 1-65535")
  71. }
  72. }
  73. if self.SendPorxy != nil {
  74. if !utils.IsInStringArray(*self.SendPorxy, LB_SENDPROXY_CHOICES) {
  75. return httperrors.NewInputParameterError("invalid send_proxy %v", self.SendPorxy)
  76. }
  77. }
  78. if self.Ssl != nil {
  79. if !utils.IsInStringArray(*self.Ssl, []string{LB_BOOL_ON, LB_BOOL_OFF}) {
  80. return httperrors.NewInputParameterError("invalid ssl %v", self.Ssl)
  81. }
  82. }
  83. return nil
  84. }