github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/loadbalancer/v2/pools/requests.go (about)

     1  package pools
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/vnpaycloud-console/gophercloud/v2"
     7  	"github.com/vnpaycloud-console/gophercloud/v2/openstack/loadbalancer/v2/monitors"
     8  	"github.com/vnpaycloud-console/gophercloud/v2/pagination"
     9  )
    10  
    11  // Type TLSVersion represents a tls version
    12  type TLSVersion string
    13  
    14  const (
    15  	TLSVersionSSLv3   TLSVersion = "SSLv3"
    16  	TLSVersionTLSv1   TLSVersion = "TLSv1"
    17  	TLSVersionTLSv1_1 TLSVersion = "TLSv1.1"
    18  	TLSVersionTLSv1_2 TLSVersion = "TLSv1.2"
    19  	TLSVersionTLSv1_3 TLSVersion = "TLSv1.3"
    20  )
    21  
    22  // ListOptsBuilder allows extensions to add additional parameters to the
    23  // List request.
    24  type ListOptsBuilder interface {
    25  	ToPoolListQuery() (string, error)
    26  }
    27  
    28  // ListOpts allows the filtering and sorting of paginated collections through
    29  // the API. Filtering is achieved by passing in struct field values that map to
    30  // the Pool attributes you want to see returned. SortKey allows you to
    31  // sort by a particular Pool attribute. SortDir sets the direction, and is
    32  // either `asc' or `desc'. Marker and Limit are used for pagination.
    33  type ListOpts struct {
    34  	LBMethod       string   `q:"lb_algorithm"`
    35  	Protocol       string   `q:"protocol"`
    36  	ProjectID      string   `q:"project_id"`
    37  	AdminStateUp   *bool    `q:"admin_state_up"`
    38  	Name           string   `q:"name"`
    39  	ID             string   `q:"id"`
    40  	LoadbalancerID string   `q:"loadbalancer_id"`
    41  	Limit          int      `q:"limit"`
    42  	Marker         string   `q:"marker"`
    43  	SortKey        string   `q:"sort_key"`
    44  	SortDir        string   `q:"sort_dir"`
    45  	Tags           []string `q:"tags"`
    46  }
    47  
    48  // ToPoolListQuery formats a ListOpts into a query string.
    49  func (opts ListOpts) ToPoolListQuery() (string, error) {
    50  	q, err := gophercloud.BuildQueryString(opts)
    51  	return q.String(), err
    52  }
    53  
    54  // List returns a Pager which allows you to iterate over a collection of
    55  // pools. It accepts a ListOpts struct, which allows you to filter and sort
    56  // the returned collection for greater efficiency.
    57  //
    58  // Default policy settings return only those pools that are owned by the
    59  // project who submits the request, unless an admin user submits the request.
    60  func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
    61  	url := rootURL(c)
    62  	if opts != nil {
    63  		query, err := opts.ToPoolListQuery()
    64  		if err != nil {
    65  			return pagination.Pager{Err: err}
    66  		}
    67  		url += query
    68  	}
    69  	return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
    70  		return PoolPage{pagination.LinkedPageBase{PageResult: r}}
    71  	})
    72  }
    73  
    74  type LBMethod string
    75  type Protocol string
    76  
    77  // Supported attributes for create/update operations.
    78  const (
    79  	LBMethodRoundRobin       LBMethod = "ROUND_ROBIN"
    80  	LBMethodLeastConnections LBMethod = "LEAST_CONNECTIONS"
    81  	LBMethodSourceIp         LBMethod = "SOURCE_IP"
    82  	LBMethodSourceIpPort     LBMethod = "SOURCE_IP_PORT"
    83  
    84  	ProtocolTCP   Protocol = "TCP"
    85  	ProtocolUDP   Protocol = "UDP"
    86  	ProtocolPROXY Protocol = "PROXY"
    87  	ProtocolHTTP  Protocol = "HTTP"
    88  	ProtocolHTTPS Protocol = "HTTPS"
    89  	// Protocol PROXYV2 requires octavia microversion 2.22
    90  	ProtocolPROXYV2 Protocol = "PROXYV2"
    91  	// Protocol SCTP requires octavia microversion 2.23
    92  	ProtocolSCTP Protocol = "SCTP"
    93  )
    94  
    95  // CreateOptsBuilder allows extensions to add additional parameters to the
    96  // Create request.
    97  type CreateOptsBuilder interface {
    98  	ToPoolCreateMap() (map[string]any, error)
    99  }
   100  
   101  // CreateOpts is the common options struct used in this package's Create
   102  // operation.
   103  type CreateOpts struct {
   104  	// The algorithm used to distribute load between the members of the pool. The
   105  	// current specification supports LBMethodRoundRobin, LBMethodLeastConnections,
   106  	// LBMethodSourceIp and LBMethodSourceIpPort as valid values for this attribute.
   107  	LBMethod LBMethod `json:"lb_algorithm" required:"true"`
   108  
   109  	// The protocol used by the pool members, you can use either
   110  	// ProtocolTCP, ProtocolUDP, ProtocolPROXY, ProtocolHTTP, ProtocolHTTPS,
   111  	// ProtocolSCTP or ProtocolPROXYV2.
   112  	Protocol Protocol `json:"protocol" required:"true"`
   113  
   114  	// The Loadbalancer on which the members of the pool will be associated with.
   115  	// Note: one of LoadbalancerID or ListenerID must be provided.
   116  	LoadbalancerID string `json:"loadbalancer_id,omitempty"`
   117  
   118  	// The Listener on which the members of the pool will be associated with.
   119  	// Note: one of LoadbalancerID or ListenerID must be provided.
   120  	ListenerID string `json:"listener_id,omitempty"`
   121  
   122  	// ProjectID is the UUID of the project who owns the Pool.
   123  	// Only administrative users can specify a project UUID other than their own.
   124  	ProjectID string `json:"project_id,omitempty"`
   125  
   126  	// Name of the pool.
   127  	Name string `json:"name,omitempty"`
   128  
   129  	// Human-readable description for the pool.
   130  	Description string `json:"description,omitempty"`
   131  
   132  	// Persistence is the session persistence of the pool.
   133  	// Omit this field to prevent session persistence.
   134  	Persistence *SessionPersistence `json:"session_persistence,omitempty"`
   135  
   136  	// A list of ALPN protocols. Available protocols: http/1.0, http/1.1,
   137  	// h2. Available from microversion 2.24.
   138  	ALPNProtocols []string `json:"alpn_protocols,omitempty"`
   139  
   140  	// The reference of the key manager service secret containing a PEM
   141  	// format CA certificate bundle for tls_enabled pools. Available from
   142  	// microversion 2.8.
   143  	CATLSContainerRef string `json:"ca_tls_container_ref,omitempty"`
   144  
   145  	// The reference of the key manager service secret containing a PEM
   146  	// format CA revocation list file for tls_enabled pools. Available from
   147  	// microversion 2.8.
   148  	CRLContainerRef string `json:"crl_container_ref,omitempty"`
   149  
   150  	// When true connections to backend member servers will use TLS
   151  	// encryption. Default is false. Available from microversion 2.8.
   152  	TLSEnabled bool `json:"tls_enabled,omitempty"`
   153  
   154  	// List of ciphers in OpenSSL format (colon-separated). Available from
   155  	// microversion 2.15.
   156  	TLSCiphers string `json:"tls_ciphers,omitempty"`
   157  
   158  	// The reference to the key manager service secret containing a PKCS12
   159  	// format certificate/key bundle for tls_enabled pools for TLS client
   160  	// authentication to the member servers. Available from microversion 2.8.
   161  	TLSContainerRef string `json:"tls_container_ref,omitempty"`
   162  
   163  	// A list of TLS protocol versions. Available versions: SSLv3, TLSv1,
   164  	// TLSv1.1, TLSv1.2, TLSv1.3. Available from microversion 2.17.
   165  	TLSVersions []TLSVersion `json:"tls_versions,omitempty"`
   166  
   167  	// The administrative state of the Pool. A valid value is true (UP)
   168  	// or false (DOWN).
   169  	AdminStateUp *bool `json:"admin_state_up,omitempty"`
   170  
   171  	// Members is a slice of CreateMemberOpts which allows a set of
   172  	// members to be created at the same time the pool is created.
   173  	//
   174  	// This is only possible to use when creating a fully populated
   175  	// Loadbalancer.
   176  	Members []CreateMemberOpts `json:"members,omitempty"`
   177  
   178  	// Monitor is an instance of monitors.CreateOpts which allows a monitor
   179  	// to be created at the same time the pool is created.
   180  	//
   181  	// This is only possible to use when creating a fully populated
   182  	// Loadbalancer.
   183  	Monitor monitors.CreateOptsBuilder `json:"healthmonitor,omitempty"`
   184  
   185  	// Tags is a set of resource tags. New in version 2.5
   186  	Tags []string `json:"tags,omitempty"`
   187  }
   188  
   189  // ToPoolCreateMap builds a request body from CreateOpts.
   190  func (opts CreateOpts) ToPoolCreateMap() (map[string]any, error) {
   191  	return gophercloud.BuildRequestBody(opts, "pool")
   192  }
   193  
   194  // Create accepts a CreateOpts struct and uses the values to create a new
   195  // load balancer pool.
   196  func Create(ctx context.Context, c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
   197  	b, err := opts.ToPoolCreateMap()
   198  	if err != nil {
   199  		r.Err = err
   200  		return
   201  	}
   202  	resp, err := c.Post(ctx, rootURL(c), b, &r.Body, nil)
   203  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   204  	return
   205  }
   206  
   207  // Get retrieves a particular pool based on its unique ID.
   208  func Get(ctx context.Context, c *gophercloud.ServiceClient, id string) (r GetResult) {
   209  	resp, err := c.Get(ctx, resourceURL(c, id), &r.Body, nil)
   210  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   211  	return
   212  }
   213  
   214  // UpdateOptsBuilder allows extensions to add additional parameters to the
   215  // Update request.
   216  type UpdateOptsBuilder interface {
   217  	ToPoolUpdateMap() (map[string]any, error)
   218  }
   219  
   220  // UpdateOpts is the common options struct used in this package's Update
   221  // operation.
   222  type UpdateOpts struct {
   223  	// Name of the pool.
   224  	Name *string `json:"name,omitempty"`
   225  
   226  	// Human-readable description for the pool.
   227  	Description *string `json:"description,omitempty"`
   228  
   229  	// The algorithm used to distribute load between the members of the pool. The
   230  	// current specification supports LBMethodRoundRobin, LBMethodLeastConnections,
   231  	// LBMethodSourceIp and LBMethodSourceIpPort as valid values for this attribute.
   232  	LBMethod LBMethod `json:"lb_algorithm,omitempty"`
   233  
   234  	// The administrative state of the Pool. A valid value is true (UP)
   235  	// or false (DOWN).
   236  	AdminStateUp *bool `json:"admin_state_up,omitempty"`
   237  
   238  	// Persistence is the session persistence of the pool.
   239  	Persistence *SessionPersistence `json:"session_persistence,omitempty"`
   240  
   241  	// A list of ALPN protocols. Available protocols: http/1.0, http/1.1,
   242  	// h2. Available from microversion 2.24.
   243  	ALPNProtocols *[]string `json:"alpn_protocols,omitempty"`
   244  
   245  	// The reference of the key manager service secret containing a PEM
   246  	// format CA certificate bundle for tls_enabled pools. Available from
   247  	// microversion 2.8.
   248  	CATLSContainerRef *string `json:"ca_tls_container_ref,omitempty"`
   249  
   250  	// The reference of the key manager service secret containing a PEM
   251  	// format CA revocation list file for tls_enabled pools. Available from
   252  	// microversion 2.8.
   253  	CRLContainerRef *string `json:"crl_container_ref,omitempty"`
   254  
   255  	// When true connections to backend member servers will use TLS
   256  	// encryption. Default is false. Available from microversion 2.8.
   257  	TLSEnabled *bool `json:"tls_enabled,omitempty"`
   258  
   259  	// List of ciphers in OpenSSL format (colon-separated). Available from
   260  	// microversion 2.15.
   261  	TLSCiphers *string `json:"tls_ciphers,omitempty"`
   262  
   263  	// The reference to the key manager service secret containing a PKCS12
   264  	// format certificate/key bundle for tls_enabled pools for TLS client
   265  	// authentication to the member servers. Available from microversion 2.8.
   266  	TLSContainerRef *string `json:"tls_container_ref,omitempty"`
   267  
   268  	// A list of TLS protocol versions. Available versions: SSLv3, TLSv1,
   269  	// TLSv1.1, TLSv1.2, TLSv1.3. Available from microversion 2.17.
   270  	TLSVersions *[]TLSVersion `json:"tls_versions,omitempty"`
   271  
   272  	// Tags is a set of resource tags. New in version 2.5
   273  	Tags *[]string `json:"tags,omitempty"`
   274  }
   275  
   276  // ToPoolUpdateMap builds a request body from UpdateOpts.
   277  func (opts UpdateOpts) ToPoolUpdateMap() (map[string]any, error) {
   278  	b, err := gophercloud.BuildRequestBody(opts, "pool")
   279  	if err != nil {
   280  		return nil, err
   281  	}
   282  
   283  	m := b["pool"].(map[string]any)
   284  
   285  	// allow to unset session_persistence on empty SessionPersistence struct
   286  	if opts.Persistence != nil && *opts.Persistence == (SessionPersistence{}) {
   287  		m["session_persistence"] = nil
   288  	}
   289  
   290  	// allow to unset alpn_protocols on empty slice
   291  	if opts.ALPNProtocols != nil && len(*opts.ALPNProtocols) == 0 {
   292  		m["alpn_protocols"] = nil
   293  	}
   294  
   295  	// allow to unset tls_versions on empty slice
   296  	if opts.TLSVersions != nil && len(*opts.TLSVersions) == 0 {
   297  		m["tls_versions"] = nil
   298  	}
   299  
   300  	return b, nil
   301  }
   302  
   303  // Update allows pools to be updated.
   304  func Update(ctx context.Context, c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
   305  	b, err := opts.ToPoolUpdateMap()
   306  	if err != nil {
   307  		r.Err = err
   308  		return
   309  	}
   310  	resp, err := c.Put(ctx, resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{
   311  		OkCodes: []int{200},
   312  	})
   313  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   314  	return
   315  }
   316  
   317  // Delete will permanently delete a particular pool based on its unique ID.
   318  func Delete(ctx context.Context, c *gophercloud.ServiceClient, id string) (r DeleteResult) {
   319  	resp, err := c.Delete(ctx, resourceURL(c, id), nil)
   320  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   321  	return
   322  }
   323  
   324  // ListMemberOptsBuilder allows extensions to add additional parameters to the
   325  // ListMembers request.
   326  type ListMembersOptsBuilder interface {
   327  	ToMembersListQuery() (string, error)
   328  }
   329  
   330  // ListMembersOpts allows the filtering and sorting of paginated collections
   331  // through the API. Filtering is achieved by passing in struct field values
   332  // that map to the Member attributes you want to see returned. SortKey allows
   333  // you to sort by a particular Member attribute. SortDir sets the direction,
   334  // and is either `asc' or `desc'. Marker and Limit are used for pagination.
   335  type ListMembersOpts struct {
   336  	Name         string `q:"name"`
   337  	Weight       int    `q:"weight"`
   338  	AdminStateUp *bool  `q:"admin_state_up"`
   339  	ProjectID    string `q:"project_id"`
   340  	Address      string `q:"address"`
   341  	ProtocolPort int    `q:"protocol_port"`
   342  	ID           string `q:"id"`
   343  	Limit        int    `q:"limit"`
   344  	Marker       string `q:"marker"`
   345  	SortKey      string `q:"sort_key"`
   346  	SortDir      string `q:"sort_dir"`
   347  }
   348  
   349  // ToMemberListQuery formats a ListOpts into a query string.
   350  func (opts ListMembersOpts) ToMembersListQuery() (string, error) {
   351  	q, err := gophercloud.BuildQueryString(opts)
   352  	return q.String(), err
   353  }
   354  
   355  // ListMembers returns a Pager which allows you to iterate over a collection of
   356  // members. It accepts a ListMembersOptsBuilder, which allows you to filter and
   357  // sort the returned collection for greater efficiency.
   358  //
   359  // Default policy settings return only those members that are owned by the
   360  // project who submits the request, unless an admin user submits the request.
   361  func ListMembers(c *gophercloud.ServiceClient, poolID string, opts ListMembersOptsBuilder) pagination.Pager {
   362  	url := memberRootURL(c, poolID)
   363  	if opts != nil {
   364  		query, err := opts.ToMembersListQuery()
   365  		if err != nil {
   366  			return pagination.Pager{Err: err}
   367  		}
   368  		url += query
   369  	}
   370  	return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
   371  		return MemberPage{pagination.LinkedPageBase{PageResult: r}}
   372  	})
   373  }
   374  
   375  // CreateMemberOptsBuilder allows extensions to add additional parameters to the
   376  // CreateMember request.
   377  type CreateMemberOptsBuilder interface {
   378  	ToMemberCreateMap() (map[string]any, error)
   379  }
   380  
   381  // CreateMemberOpts is the common options struct used in this package's CreateMember
   382  // operation.
   383  type CreateMemberOpts struct {
   384  	// The IP address of the member to receive traffic from the load balancer.
   385  	Address string `json:"address" required:"true"`
   386  
   387  	// The port on which to listen for client traffic.
   388  	ProtocolPort int `json:"protocol_port" required:"true"`
   389  
   390  	// Name of the Member.
   391  	Name string `json:"name,omitempty"`
   392  
   393  	// ProjectID is the UUID of the project who owns the Member.
   394  	// Only administrative users can specify a project UUID other than their own.
   395  	ProjectID string `json:"project_id,omitempty"`
   396  
   397  	// A positive integer value that indicates the relative portion of traffic
   398  	// that this member should receive from the pool. For example, a member with
   399  	// a weight of 10 receives five times as much traffic as a member with a
   400  	// weight of 2.
   401  	Weight *int `json:"weight,omitempty"`
   402  
   403  	// If you omit this parameter, LBaaS uses the vip_subnet_id parameter value
   404  	// for the subnet UUID.
   405  	SubnetID string `json:"subnet_id,omitempty"`
   406  
   407  	// The administrative state of the Pool. A valid value is true (UP)
   408  	// or false (DOWN).
   409  	AdminStateUp *bool `json:"admin_state_up,omitempty"`
   410  
   411  	// Is the member a backup? Backup members only receive traffic when all
   412  	// non-backup members are down.
   413  	// Requires microversion 2.1 or later.
   414  	Backup *bool `json:"backup,omitempty"`
   415  
   416  	// An alternate IP address used for health monitoring a backend member.
   417  	MonitorAddress string `json:"monitor_address,omitempty"`
   418  
   419  	// An alternate protocol port used for health monitoring a backend member.
   420  	MonitorPort *int `json:"monitor_port,omitempty"`
   421  
   422  	// A list of simple strings assigned to the resource.
   423  	// Requires microversion 2.5 or later.
   424  	Tags []string `json:"tags,omitempty"`
   425  }
   426  
   427  // ToMemberCreateMap builds a request body from CreateMemberOpts.
   428  func (opts CreateMemberOpts) ToMemberCreateMap() (map[string]any, error) {
   429  	return gophercloud.BuildRequestBody(opts, "member")
   430  }
   431  
   432  // CreateMember will create and associate a Member with a particular Pool.
   433  func CreateMember(ctx context.Context, c *gophercloud.ServiceClient, poolID string, opts CreateMemberOptsBuilder) (r CreateMemberResult) {
   434  	b, err := opts.ToMemberCreateMap()
   435  	if err != nil {
   436  		r.Err = err
   437  		return
   438  	}
   439  	resp, err := c.Post(ctx, memberRootURL(c, poolID), b, &r.Body, nil)
   440  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   441  	return
   442  }
   443  
   444  // GetMember retrieves a particular Pool Member based on its unique ID.
   445  func GetMember(ctx context.Context, c *gophercloud.ServiceClient, poolID string, memberID string) (r GetMemberResult) {
   446  	resp, err := c.Get(ctx, memberResourceURL(c, poolID, memberID), &r.Body, nil)
   447  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   448  	return
   449  }
   450  
   451  // UpdateMemberOptsBuilder allows extensions to add additional parameters to the
   452  // List request.
   453  type UpdateMemberOptsBuilder interface {
   454  	ToMemberUpdateMap() (map[string]any, error)
   455  }
   456  
   457  // UpdateMemberOpts is the common options struct used in this package's Update
   458  // operation.
   459  type UpdateMemberOpts struct {
   460  	// Name of the Member.
   461  	Name *string `json:"name,omitempty"`
   462  
   463  	// A positive integer value that indicates the relative portion of traffic
   464  	// that this member should receive from the pool. For example, a member with
   465  	// a weight of 10 receives five times as much traffic as a member with a
   466  	// weight of 2.
   467  	Weight *int `json:"weight,omitempty"`
   468  
   469  	// The administrative state of the Pool. A valid value is true (UP)
   470  	// or false (DOWN).
   471  	AdminStateUp *bool `json:"admin_state_up,omitempty"`
   472  
   473  	// Is the member a backup? Backup members only receive traffic when all
   474  	// non-backup members are down.
   475  	// Requires microversion 2.1 or later.
   476  	Backup *bool `json:"backup,omitempty"`
   477  
   478  	// An alternate IP address used for health monitoring a backend member.
   479  	MonitorAddress *string `json:"monitor_address,omitempty"`
   480  
   481  	// An alternate protocol port used for health monitoring a backend member.
   482  	MonitorPort *int `json:"monitor_port,omitempty"`
   483  
   484  	// A list of simple strings assigned to the resource.
   485  	// Requires microversion 2.5 or later.
   486  	Tags []string `json:"tags,omitempty"`
   487  }
   488  
   489  // ToMemberUpdateMap builds a request body from UpdateMemberOpts.
   490  func (opts UpdateMemberOpts) ToMemberUpdateMap() (map[string]any, error) {
   491  	return gophercloud.BuildRequestBody(opts, "member")
   492  }
   493  
   494  // Update allows Member to be updated.
   495  func UpdateMember(ctx context.Context, c *gophercloud.ServiceClient, poolID string, memberID string, opts UpdateMemberOptsBuilder) (r UpdateMemberResult) {
   496  	b, err := opts.ToMemberUpdateMap()
   497  	if err != nil {
   498  		r.Err = err
   499  		return
   500  	}
   501  	resp, err := c.Put(ctx, memberResourceURL(c, poolID, memberID), b, &r.Body, &gophercloud.RequestOpts{
   502  		OkCodes: []int{200, 201, 202},
   503  	})
   504  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   505  	return
   506  }
   507  
   508  // BatchUpdateMemberOptsBuilder allows extensions to add additional parameters to the BatchUpdateMembers request.
   509  type BatchUpdateMemberOptsBuilder interface {
   510  	ToBatchMemberUpdateMap() (map[string]any, error)
   511  }
   512  
   513  // BatchUpdateMemberOpts is the common options struct used in this package's BatchUpdateMembers
   514  // operation.
   515  type BatchUpdateMemberOpts struct {
   516  	// The IP address of the member to receive traffic from the load balancer.
   517  	Address string `json:"address" required:"true"`
   518  
   519  	// The port on which to listen for client traffic.
   520  	ProtocolPort int `json:"protocol_port" required:"true"`
   521  
   522  	// Name of the Member.
   523  	Name *string `json:"name,omitempty"`
   524  
   525  	// ProjectID is the UUID of the project who owns the Member.
   526  	// Only administrative users can specify a project UUID other than their own.
   527  	ProjectID string `json:"project_id,omitempty"`
   528  
   529  	// A positive integer value that indicates the relative portion of traffic
   530  	// that this member should receive from the pool. For example, a member with
   531  	// a weight of 10 receives five times as much traffic as a member with a
   532  	// weight of 2.
   533  	Weight *int `json:"weight,omitempty"`
   534  
   535  	// If you omit this parameter, LBaaS uses the vip_subnet_id parameter value
   536  	// for the subnet UUID.
   537  	SubnetID *string `json:"subnet_id,omitempty"`
   538  
   539  	// The administrative state of the Pool. A valid value is true (UP)
   540  	// or false (DOWN).
   541  	AdminStateUp *bool `json:"admin_state_up,omitempty"`
   542  
   543  	// Is the member a backup? Backup members only receive traffic when all
   544  	// non-backup members are down.
   545  	// Requires microversion 2.1 or later.
   546  	Backup *bool `json:"backup,omitempty"`
   547  
   548  	// An alternate IP address used for health monitoring a backend member.
   549  	MonitorAddress *string `json:"monitor_address,omitempty"`
   550  
   551  	// An alternate protocol port used for health monitoring a backend member.
   552  	MonitorPort *int `json:"monitor_port,omitempty"`
   553  
   554  	// A list of simple strings assigned to the resource.
   555  	// Requires microversion 2.5 or later.
   556  	Tags []string `json:"tags,omitempty"`
   557  }
   558  
   559  // ToBatchMemberUpdateMap builds a request body from BatchUpdateMemberOpts.
   560  func (opts BatchUpdateMemberOpts) ToBatchMemberUpdateMap() (map[string]any, error) {
   561  	b, err := gophercloud.BuildRequestBody(opts, "")
   562  	if err != nil {
   563  		return nil, err
   564  	}
   565  
   566  	if b["subnet_id"] == "" {
   567  		b["subnet_id"] = nil
   568  	}
   569  
   570  	return b, nil
   571  }
   572  
   573  // BatchUpdateMembers updates the pool members in batch
   574  func BatchUpdateMembers[T BatchUpdateMemberOptsBuilder](ctx context.Context, c *gophercloud.ServiceClient, poolID string, opts []T) (r UpdateMembersResult) {
   575  	members := []map[string]any{}
   576  	for _, opt := range opts {
   577  		b, err := opt.ToBatchMemberUpdateMap()
   578  		if err != nil {
   579  			r.Err = err
   580  			return
   581  		}
   582  		members = append(members, b)
   583  	}
   584  
   585  	b := map[string]any{"members": members}
   586  
   587  	resp, err := c.Put(ctx, memberRootURL(c, poolID), b, nil, &gophercloud.RequestOpts{OkCodes: []int{202}})
   588  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   589  	return
   590  }
   591  
   592  // DeleteMember will remove and disassociate a Member from a particular Pool.
   593  func DeleteMember(ctx context.Context, c *gophercloud.ServiceClient, poolID string, memberID string) (r DeleteMemberResult) {
   594  	resp, err := c.Delete(ctx, memberResourceURL(c, poolID, memberID), nil)
   595  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   596  	return
   597  }