github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/networking/v2/extensions/elbaas/backendmember/requests.go (about)

     1  package backendmember
     2  
     3  import (
     4  	//"fmt"
     5  	"fmt"
     6  
     7  	"github.com/chnsz/golangsdk"
     8  	//"github.com/chnsz/golangsdk/pagination"
     9  )
    10  
    11  // CreateOptsBuilder is the interface options structs have to satisfy in order
    12  // to be used in the main Create operation in this package. Since many
    13  // extensions decorate or modify the common logic, it is useful for them to
    14  // satisfy a basic interface in order for them to be used.
    15  type AddOptsBuilder interface {
    16  	ToBackendAddMap() (map[string]interface{}, error)
    17  }
    18  
    19  // CreateOpts is the common options struct used in this package's Create
    20  // operation.
    21  type AddOpts struct {
    22  	// server_id
    23  	ServerId string `json:"server_id" required:"true"`
    24  	// The load balancer on which to provision this listener.
    25  	Address string `json:"address" required:"true"`
    26  }
    27  
    28  // ToBackendAddMap casts a CreateOpts struct to a map.
    29  func (opts AddOpts) ToBackendAddMap() (map[string]interface{}, error) {
    30  	return golangsdk.BuildRequestBody(opts, "")
    31  }
    32  
    33  // Add is an operation which provisions a new Listeners based on the
    34  // configuration defined in the AddOpts struct. Once the request is
    35  // validated and progress has started on the provisioning process, a
    36  // AddResult will be returned.
    37  //
    38  // Users with an admin role can create Listeners on behalf of other tenants by
    39  // specifying a TenantID attribute different than their own.
    40  func Add(c *golangsdk.ServiceClient, listener_id string, opts AddOptsBuilder) (r AddResult) {
    41  	b, err := opts.ToBackendAddMap()
    42  	// API takes an array of these...
    43  	a := make([]map[string]interface{}, 1)
    44  	a[0] = b
    45  	if err != nil {
    46  		r.Err = err
    47  		return
    48  	}
    49  	_, r.Err = c.Post(addURL(c, listener_id), a, &r.Body, &golangsdk.RequestOpts{
    50  		OkCodes: []int{200},
    51  	})
    52  	return
    53  }
    54  
    55  // RemoveOptsBuilder is the interface options structs have to satisfy in order
    56  // to be used in the main Remove operation in this package. Since many
    57  // extensions decorate or modify the common logic, it is useful for them to
    58  // satisfy a basic interface in order for them to be used.
    59  type RemoveOptsBuilder interface {
    60  	ToBackendRemoveMap() (map[string]interface{}, error)
    61  }
    62  
    63  type LoadBalancerID struct {
    64  	// backend member id to remove
    65  	ID string `json:"id" required:"true"`
    66  }
    67  
    68  // RemoveOpts is the common options struct used in this package's Remove
    69  // operation.
    70  type RemoveOpts struct {
    71  	RemoveMember []LoadBalancerID `json:"removeMember" required:"true"`
    72  }
    73  
    74  // ToBackendCreateMap casts a CreateOpts struct to a map.
    75  func (opts RemoveOpts) ToBackendRemoveMap() (map[string]interface{}, error) {
    76  	return golangsdk.BuildRequestBody(opts, "")
    77  }
    78  
    79  // Remove will permanently remove a particular backend based on its unique ID.
    80  func Remove(c *golangsdk.ServiceClient, listener_id string, id string) (r RemoveResult) {
    81  	/*lbid := LoadBalancerID{
    82  		ID: id,
    83  	}
    84  	lbids := []LoadBalancerID{lbid}
    85  	removeOpts := RemoveOpts{
    86  		removeMember: lbids,
    87  	}
    88  	fmt.Printf("removeOpts=%+v.\n", removeOpts)
    89  	b, err := removeOpts.ToBackendRemoveMap() */
    90  	lbid := make(map[string]interface{})
    91  	lbid["id"] = id
    92  	lbids := make([]map[string]interface{}, 1)
    93  	lbids[0] = lbid
    94  	b := make(map[string]interface{})
    95  	b["removeMember"] = lbids
    96  	//fmt.Printf("b=%+v.\n", b)
    97  	/* if err != nil {
    98  		r.Err = err
    99  		return
   100  	} */
   101  	_, r.Err = c.Post(removeURL(c, listener_id), b, &r.Body, &golangsdk.RequestOpts{
   102  		OkCodes: []int{200},
   103  	})
   104  	return
   105  }
   106  
   107  // Get retrieves a particular Health Monitor based on its unique ID.
   108  func Get(c *golangsdk.ServiceClient, listener_id, id string) (r GetResult) {
   109  	url := resourceURL(c, listener_id)
   110  	url += fmt.Sprintf("?id=%s", id)
   111  
   112  	_, r.Err = c.Get(url, &r.Body, nil)
   113  	return
   114  }