github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/elb/v3/loadbalancers/requests.go (about)

     1  package loadbalancers
     2  
     3  import (
     4  	"github.com/chnsz/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  	// Prepaid configuration
    75  	PrepaidOpts *PrepaidOpts `json:"prepaid_options,omitempty"`
    76  
    77  	// Autoscaling configuration
    78  	AutoScaling *AutoScaling `json:"autoscaling,omitempty"`
    79  
    80  	// Protection status
    81  	ProtectionStatus string `json:"protection_status,omitempty"`
    82  
    83  	// Protection reason
    84  	ProtectionReason string `json:"protection_reason,omitempty"`
    85  
    86  	// Waf failure action
    87  	WafFailureAction string `json:"waf_failure_action,omitempty"`
    88  
    89  	// IpV6 Vip Address
    90  	Ipv6VipAddress string `json:"ipv6_vip_address,omitempty"`
    91  }
    92  
    93  // BandwidthRef
    94  type BandwidthRef struct {
    95  	// Share Bandwidth ID
    96  	ID string `json:"id" required:"true"`
    97  }
    98  
    99  // UBandwidthRef
   100  type UBandwidthRef struct {
   101  	// Share Bandwidth ID
   102  	ID *string `json:"id"`
   103  }
   104  
   105  // PublicIP
   106  type PublicIP struct {
   107  	// IP Version.
   108  	IPVersion int `json:"ip_version,omitempty"`
   109  
   110  	// Network Type
   111  	NetworkType string `json:"network_type" required:"true"`
   112  
   113  	// Billing Info.
   114  	BillingInfo string `json:"billing_info,omitempty"`
   115  
   116  	// Description.
   117  	Description string `json:"description,omitempty"`
   118  
   119  	// Bandwidth
   120  	Bandwidth Bandwidth `json:"bandwidth" required:"true"`
   121  }
   122  
   123  // Bandwidth
   124  type Bandwidth struct {
   125  	// ID
   126  	Id string `json:"id,omitempty"`
   127  
   128  	// Name
   129  	Name string `json:"name,omitempty"`
   130  
   131  	// Size
   132  	Size int `json:"size,omitempty"`
   133  
   134  	// Charge Mode
   135  	ChargeMode string `json:"charge_mode,omitempty"`
   136  
   137  	// Share Type
   138  	ShareType string `json:"share_type,omitempty"`
   139  
   140  	// Billing Info.
   141  	BillingInfo string `json:"billing_info,omitempty"`
   142  }
   143  
   144  // Tag
   145  type Tag struct {
   146  	// Tag Key
   147  	Key string `json:"key,omitempty"`
   148  	// Tag Value
   149  	Value string `json:"value,omitempty"`
   150  }
   151  
   152  // Prepaid configuration
   153  type PrepaidOpts struct {
   154  	PeriodType string `json:"period_type,omitempty"`
   155  	PeriodNum  int    `json:"period_num,omitempty"`
   156  	AutoRenew  bool   `json:"auto_renew,omitempty"`
   157  	AutoPay    bool   `json:"auto_pay,omitempty"`
   158  }
   159  
   160  // AutoScaling configuration
   161  type AutoScaling struct {
   162  	Enable      bool   `json:"enable"`
   163  	MinL7Flavor string `json:"min_l7_flavor_id,omitempty"`
   164  }
   165  
   166  // ToLoadBalancerCreateMap builds a request body from CreateOpts.
   167  func (opts CreateOpts) ToLoadBalancerCreateMap() (map[string]interface{}, error) {
   168  	return golangsdk.BuildRequestBody(opts, "loadbalancer")
   169  }
   170  
   171  // Create is an operation which provisions a new loadbalancer based on the
   172  // configuration defined in the CreateOpts struct. Once the request is
   173  // validated and progress has started on the provisioning process, a
   174  // CreateResult will be returned.
   175  func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
   176  	b, err := opts.ToLoadBalancerCreateMap()
   177  	if err != nil {
   178  		r.Err = err
   179  		return
   180  	}
   181  	_, r.Err = c.Post(rootURL(c), b, &r.Body, nil)
   182  	return
   183  }
   184  
   185  // Get retrieves a particular Loadbalancer based on its unique ID.
   186  func Get(c *golangsdk.ServiceClient, id string) (r GetResult) {
   187  	_, r.Err = c.Get(resourceURL(c, id), &r.Body, nil)
   188  	return
   189  }
   190  
   191  // UpdateOptsBuilder allows extensions to add additional parameters to the
   192  // Update request.
   193  type UpdateOptsBuilder interface {
   194  	ToLoadBalancerUpdateMap() (map[string]interface{}, error)
   195  }
   196  
   197  // UpdateOpts is the common options struct used in this package's Update
   198  // operation.
   199  type UpdateOpts struct {
   200  	// Human-readable name for the Loadbalancer. Does not have to be unique.
   201  	Name string `json:"name,omitempty"`
   202  
   203  	// Human-readable description for the Loadbalancer.
   204  	Description *string `json:"description,omitempty"`
   205  
   206  	// The administrative state of the Loadbalancer. A valid value is true (UP)
   207  	// or false (DOWN).
   208  	AdminStateUp *bool `json:"admin_state_up,omitempty"`
   209  
   210  	// The IP address of the Loadbalancer.
   211  	VipAddress string `json:"vip_address,omitempty"`
   212  
   213  	// The network on which to allocate the Loadbalancer's address.
   214  	VipSubnetID *string `json:"vip_subnet_cidr_id"`
   215  
   216  	// The V6 network on which to allocate the Loadbalancer's address.
   217  	IpV6VipSubnetID *string `json:"ipv6_vip_virsubnet_id"`
   218  
   219  	// The UUID of a l4 flavor.
   220  	L4Flavor string `json:"l4_flavor_id,omitempty"`
   221  
   222  	// The UUID of a l7 flavor.
   223  	L7Flavor string `json:"l7_flavor_id,omitempty"`
   224  
   225  	// IPv6 Bandwidth.
   226  	IPV6Bandwidth *UBandwidthRef `json:"ipv6_bandwidth,omitempty"`
   227  
   228  	// ELB VirSubnet IDs.
   229  	ElbSubnetIds []string `json:"elb_virsubnet_ids,omitempty"`
   230  
   231  	// IP Target Enable.
   232  	IPTargetEnable *bool `json:"ip_target_enable,omitempty"`
   233  
   234  	// Deletion Protection Enable.
   235  	DeletionProtectionEnable *bool `json:"deletion_protection_enable,omitempty"`
   236  
   237  	// Prepaid configuration
   238  	PrepaidOpts *PrepaidOpts `json:"prepaid_options,omitempty"`
   239  
   240  	// Autoscaling configuration
   241  	AutoScaling *AutoScaling `json:"autoscaling,omitempty"`
   242  
   243  	// Update protection status
   244  	ProtectionStatus string `json:"protection_status,omitempty"`
   245  
   246  	// Update protection reason
   247  	ProtectionReason *string `json:"protection_reason,omitempty"`
   248  
   249  	// Waf failure action
   250  	WafFailureAction string `json:"waf_failure_action,omitempty"`
   251  
   252  	// IpV6 Vip Address
   253  	Ipv6VipAddress string `json:"ipv6_vip_address,omitempty"`
   254  }
   255  
   256  // ToLoadBalancerUpdateMap builds a request body from UpdateOpts.
   257  func (opts UpdateOpts) ToLoadBalancerUpdateMap() (map[string]interface{}, error) {
   258  	return golangsdk.BuildRequestBody(opts, "loadbalancer")
   259  }
   260  
   261  // Update is an operation which modifies the attributes of the specified
   262  // LoadBalancer.
   263  func Update(c *golangsdk.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) {
   264  	b, err := opts.ToLoadBalancerUpdateMap()
   265  	if err != nil {
   266  		r.Err = err
   267  		return
   268  	}
   269  	_, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &golangsdk.RequestOpts{
   270  		OkCodes: []int{200, 202},
   271  	})
   272  	return
   273  }
   274  
   275  // Delete will permanently delete a particular LoadBalancer based on its
   276  // unique ID.
   277  func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) {
   278  	_, r.Err = c.Delete(resourceURL(c, id), nil)
   279  	return
   280  }
   281  
   282  // ForceDelete will delete the LoadBalancer and the sub resource(LoadBalancer, listeners, unbind associated pools)
   283  func ForceDelete(c *golangsdk.ServiceClient, id string) (r DeleteResult) {
   284  	_, r.Err = c.Delete(resourceForceDeleteURL(c, id), nil)
   285  	return
   286  }
   287  
   288  // GetStatuses will return the status of a particular LoadBalancer.
   289  func GetStatuses(c *golangsdk.ServiceClient, id string) (r GetStatusesResult) {
   290  	_, r.Err = c.Get(statusRootURL(c, id), &r.Body, nil)
   291  	return
   292  }
   293  
   294  type UpdateAvailabilityZone interface {
   295  	ToAvailabilityZoneUpdateMap() (map[string]interface{}, error)
   296  }
   297  
   298  // Availability Zone List.
   299  type AvailabilityZoneOpts struct {
   300  	AvailabilityZoneList []string `json:"availability_zone_list" required:"true"`
   301  }
   302  
   303  // ToAvailabilityZoneUpdateMap builds a request body from AvailabilityZoneOpts.
   304  func (opts AvailabilityZoneOpts) ToAvailabilityZoneUpdateMap() (map[string]interface{}, error) {
   305  	return golangsdk.BuildRequestBody(opts, "")
   306  }
   307  
   308  // AddAvailabilityZone will add availability zone list
   309  func AddAvailabilityZone(c *golangsdk.ServiceClient, id string, opts AvailabilityZoneOpts) (r UpdateResult) {
   310  	b, err := opts.ToAvailabilityZoneUpdateMap()
   311  	if err != nil {
   312  		r.Err = err
   313  		return
   314  	}
   315  	_, r.Err = c.Post(updateAvailabilityZoneURL(c, id, "batch-add"), b, &r.Body, &golangsdk.RequestOpts{})
   316  	return
   317  }
   318  
   319  // RemoveAvailabilityZone will remove availability zone list
   320  func RemoveAvailabilityZone(c *golangsdk.ServiceClient, id string, opts AvailabilityZoneOpts) (r UpdateResult) {
   321  	b, err := opts.ToAvailabilityZoneUpdateMap()
   322  	if err != nil {
   323  		r.Err = err
   324  		return
   325  	}
   326  	_, r.Err = c.Post(updateAvailabilityZoneURL(c, id, "batch-remove"), b, &r.Body, &golangsdk.RequestOpts{})
   327  	return
   328  }
   329  
   330  // Charging info.
   331  type ChangeChargingModeOpts struct {
   332  	LoadBalancerIds []string       `json:"loadbalancer_ids" required:"true"`
   333  	ChargingMode    string         `json:"charge_mode" required:"true"`
   334  	PrepaidOptions  PrepaidOptions `json:"prepaid_options,omitempty"`
   335  }
   336  
   337  type PrepaidOptions struct {
   338  	IncludePublicIp *bool  `json:"include_publicip,omitempty"`
   339  	PeriodType      string `json:"period_type" required:"true"`
   340  	PeriodNum       int    `json:"period_num,omitempty"`
   341  	AutoRenew       string `json:"auto_renew,omitempty"`
   342  	AutoPay         bool   `json:"auto_pay,omitempty"`
   343  }
   344  
   345  // ChangeChargingMode will change the charging mode of the loadbalancer
   346  func ChangeChargingMode(c *golangsdk.ServiceClient, opts ChangeChargingModeOpts) (r ChangeResult) {
   347  	b, err := golangsdk.BuildRequestBody(opts, "")
   348  	if err != nil {
   349  		r.Err = err
   350  		return
   351  	}
   352  	_, r.Err = c.Post(changeChargingModeURL(c), b, &r.Body, &golangsdk.RequestOpts{})
   353  	return
   354  }