github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/elb/v3/loadbalancers/requests.go (about) 1 package loadbalancers 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 ) 6 7 // CreateOptsBuilder allows extensions to add additional parameters to the 8 // Create request. 9 type CreateOptsBuilder interface { 10 ToLoadBalancerCreateMap() (map[string]interface{}, error) 11 } 12 13 // CreateOpts is the common options struct used in this package's Create 14 // operation. 15 type CreateOpts struct { 16 // Human-readable name for the Loadbalancer. Does not have to be unique. 17 Name string `json:"name,omitempty"` 18 19 // Human-readable description for the Loadbalancer. 20 Description string `json:"description,omitempty"` 21 22 // The IP address of the Loadbalancer. 23 VipAddress string `json:"vip_address,omitempty"` 24 25 // The network on which to allocate the Loadbalancer's address. 26 VipSubnetID string `json:"vip_subnet_cidr_id,omitempty"` 27 28 // The V6 network on which to allocate the Loadbalancer's address. 29 IpV6VipSubnetID string `json:"ipv6_vip_virsubnet_id,omitempty"` 30 31 // The UUID of a l4 flavor. 32 L4Flavor string `json:"l4_flavor_id,omitempty"` 33 34 // Guaranteed. 35 Guaranteed *bool `json:"guaranteed,omitempty"` 36 37 // The VPC ID. 38 VpcID string `json:"vpc_id,omitempty"` 39 40 // Availability Zone List. 41 AvailabilityZoneList []string `json:"availability_zone_list" required:"true"` 42 43 // The UUID of the enterprise project who owns the Loadbalancer. 44 EnterpriseProjectID string `json:"enterprise_project_id,omitempty"` 45 46 // The tags of the Loadbalancer. 47 Tags []Tag `json:"tags,omitempty"` 48 49 // The administrative state of the Loadbalancer. A valid value is true (UP) 50 // or false (DOWN). 51 AdminStateUp *bool `json:"admin_state_up,omitempty"` 52 53 // The UUID of a l7 flavor. 54 L7Flavor string `json:"l7_flavor_id,omitempty"` 55 56 // IPv6 Bandwidth. 57 IPV6Bandwidth *BandwidthRef `json:"ipv6_bandwidth,omitempty"` 58 59 // Public IP IDs. 60 PublicIPIds []string `json:"publicip_ids,omitempty"` 61 62 // Public IP. 63 PublicIP *PublicIP `json:"publicip,omitempty"` 64 65 // ELB VirSubnet IDs. 66 ElbSubnetIds []string `json:"elb_virsubnet_ids,omitempty"` 67 68 // IP Target Enable. 69 IPTargetEnable *bool `json:"ip_target_enable,omitempty"` 70 71 // Deletion Protection Enable. 72 DeletionProtectionEnable *bool `json:"deletion_protection_enable,omitempty"` 73 } 74 75 // BandwidthRef 76 type BandwidthRef struct { 77 // Share Bandwidth ID 78 ID string `json:"id" required:"true"` 79 } 80 81 // UBandwidthRef 82 type UBandwidthRef struct { 83 // Share Bandwidth ID 84 ID *string `json:"id"` 85 } 86 87 // PublicIP 88 type PublicIP struct { 89 // IP Version. 90 IPVersion int `json:"ip_version,omitempty"` 91 92 // Network Type 93 NetworkType string `json:"network_type" required:"true"` 94 95 // Billing Info. 96 BillingInfo string `json:"billing_info,omitempty"` 97 98 // Description. 99 Description string `json:"description,omitempty"` 100 101 // Bandwidth 102 Bandwidth Bandwidth `json:"bandwidth" required:"true"` 103 } 104 105 // Bandwidth 106 type Bandwidth struct { 107 // Name 108 Name string `json:"name" required:"true"` 109 110 // Size 111 Size int `json:"size" required:"true"` 112 113 // Charge Mode 114 ChargeMode string `json:"charge_mode" required:"true"` 115 116 // Share Type 117 ShareType string `json:"share_type" required:"true"` 118 119 // Billing Info. 120 BillingInfo string `json:"billing_info,omitempty"` 121 } 122 123 // Tag 124 type Tag struct { 125 // Tag Key 126 Key string `json:"key,omitempty"` 127 // Tag Value 128 Value string `json:"value,omitempty"` 129 } 130 131 // ToLoadBalancerCreateMap builds a request body from CreateOpts. 132 func (opts CreateOpts) ToLoadBalancerCreateMap() (map[string]interface{}, error) { 133 return golangsdk.BuildRequestBody(opts, "loadbalancer") 134 } 135 136 // Create is an operation which provisions a new loadbalancer based on the 137 // configuration defined in the CreateOpts struct. Once the request is 138 // validated and progress has started on the provisioning process, a 139 // CreateResult will be returned. 140 func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 141 b, err := opts.ToLoadBalancerCreateMap() 142 if err != nil { 143 r.Err = err 144 return 145 } 146 _, r.Err = c.Post(rootURL(c), b, &r.Body, nil) 147 return 148 } 149 150 // Get retrieves a particular Loadbalancer based on its unique ID. 151 func Get(c *golangsdk.ServiceClient, id string) (r GetResult) { 152 _, r.Err = c.Get(resourceURL(c, id), &r.Body, nil) 153 return 154 } 155 156 // UpdateOptsBuilder allows extensions to add additional parameters to the 157 // Update request. 158 type UpdateOptsBuilder interface { 159 ToLoadBalancerUpdateMap() (map[string]interface{}, error) 160 } 161 162 // UpdateOpts is the common options struct used in this package's Update 163 // operation. 164 type UpdateOpts struct { 165 // Human-readable name for the Loadbalancer. Does not have to be unique. 166 Name string `json:"name,omitempty"` 167 168 // Human-readable description for the Loadbalancer. 169 Description *string `json:"description,omitempty"` 170 171 // The administrative state of the Loadbalancer. A valid value is true (UP) 172 // or false (DOWN). 173 AdminStateUp *bool `json:"admin_state_up,omitempty"` 174 175 // The IP address of the Loadbalancer. 176 VipAddress string `json:"vip_address,omitempty"` 177 178 // The network on which to allocate the Loadbalancer's address. 179 VipSubnetID *string `json:"vip_subnet_cidr_id"` 180 181 // The V6 network on which to allocate the Loadbalancer's address. 182 IpV6VipSubnetID *string `json:"ipv6_vip_virsubnet_id"` 183 184 // The UUID of a l4 flavor. 185 L4Flavor string `json:"l4_flavor_id,omitempty"` 186 187 // The UUID of a l7 flavor. 188 L7Flavor string `json:"l7_flavor_id,omitempty"` 189 190 // IPv6 Bandwidth. 191 IPV6Bandwidth *UBandwidthRef `json:"ipv6_bandwidth,omitempty"` 192 193 // ELB VirSubnet IDs. 194 ElbSubnetIds []string `json:"elb_virsubnet_ids,omitempty"` 195 196 // IP Target Enable. 197 IPTargetEnable *bool `json:"ip_target_enable,omitempty"` 198 199 // Deletion Protection Enable. 200 DeletionProtectionEnable *bool `json:"deletion_protection_enable,omitempty"` 201 } 202 203 // ToLoadBalancerUpdateMap builds a request body from UpdateOpts. 204 func (opts UpdateOpts) ToLoadBalancerUpdateMap() (map[string]interface{}, error) { 205 return golangsdk.BuildRequestBody(opts, "loadbalancer") 206 } 207 208 // Update is an operation which modifies the attributes of the specified 209 // LoadBalancer. 210 func Update(c *golangsdk.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) { 211 b, err := opts.ToLoadBalancerUpdateMap() 212 if err != nil { 213 r.Err = err 214 return 215 } 216 _, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &golangsdk.RequestOpts{ 217 OkCodes: []int{200, 202}, 218 }) 219 return 220 } 221 222 // Delete will permanently delete a particular LoadBalancer based on its 223 // unique ID. 224 func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) { 225 _, r.Err = c.Delete(resourceURL(c, id), nil) 226 return 227 } 228 229 // GetStatuses will return the status of a particular LoadBalancer. 230 func GetStatuses(c *golangsdk.ServiceClient, id string) (r GetStatusesResult) { 231 _, r.Err = c.Get(statusRootURL(c, id), &r.Body, nil) 232 return 233 }