github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/elb/v3/ipgroups/requests.go (about)

     1  package ipgroups
     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  	ToIpGroupCreateMap() (map[string]interface{}, error)
    11  }
    12  
    13  // CreateOpts represents options for creating a ipgroup.
    14  type CreateOpts struct {
    15  	// Human-readable name for the IpGroup. Does not have to be unique.
    16  	Name string `json:"name,omitempty"`
    17  
    18  	// Human-readable description for the IpGroup.
    19  	Description *string `json:"description,omitempty"`
    20  
    21  	// A list of IP addresses.
    22  	IpList *[]IpListOpt `json:"ip_list" required:"true"`
    23  
    24  	// Specifies the enterprise project id.
    25  	EnterpriseProjectID string `json:"enterprise_project_id,omitempty"`
    26  }
    27  
    28  type IpListOpt struct {
    29  	Ip          string `json:"ip" required:"true"`
    30  	Description string `json:"description,omitempty"`
    31  }
    32  
    33  // ToIpGroupCreateMap builds a request body from CreateOpts.
    34  func (opts CreateOpts) ToIpGroupCreateMap() (map[string]interface{}, error) {
    35  	return golangsdk.BuildRequestBody(opts, "ipgroup")
    36  }
    37  
    38  // Create is an operation which provisions a new IpGroups based on the
    39  // configuration defined in the CreateOpts struct. Once the request is
    40  // validated and progress has started on the provisioning process, a
    41  // CreateResult will be returned.
    42  //
    43  // Users with an admin role can create IpGroups on behalf of other tenants by
    44  // specifying a TenantID attribute different than their own.
    45  func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
    46  	b, err := opts.ToIpGroupCreateMap()
    47  	if err != nil {
    48  		r.Err = err
    49  		return
    50  	}
    51  	_, r.Err = c.Post(rootURL(c), b, &r.Body, nil)
    52  	return
    53  }
    54  
    55  // Get retrieves a particular Ipgroups based on its unique ID.
    56  func Get(c *golangsdk.ServiceClient, id string) (r GetResult) {
    57  	_, r.Err = c.Get(resourceURL(c, id), &r.Body, nil)
    58  	return
    59  }
    60  
    61  // UpdateOptsBuilder allows extensions to add additional parameters to the
    62  // Update request.
    63  type UpdateOptsBuilder interface {
    64  	ToIpGroupUpdateMap() (map[string]interface{}, error)
    65  }
    66  
    67  // UpdateOpts represents options for updating a IpGroup.
    68  type UpdateOpts struct {
    69  	// Human-readable name for the IpGroup. Does not have to be unique.
    70  	Name string `json:"name,omitempty"`
    71  
    72  	// Human-readable description for the IpGroup.
    73  	Description *string `json:"description,omitempty"`
    74  
    75  	// A list of IP addresses.
    76  	IpList *[]IpListOpt `json:"ip_list,omitempty"`
    77  }
    78  
    79  // ToIpGroupUpdateMap builds a request body from UpdateOpts.
    80  func (opts UpdateOpts) ToIpGroupUpdateMap() (map[string]interface{}, error) {
    81  	return golangsdk.BuildRequestBody(opts, "ipgroup")
    82  }
    83  
    84  // Update is an operation which modifies the attributes of the specified
    85  // IpGroup.
    86  func Update(c *golangsdk.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) {
    87  	b, err := opts.ToIpGroupUpdateMap()
    88  	if err != nil {
    89  		r.Err = err
    90  		return
    91  	}
    92  	_, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &golangsdk.RequestOpts{
    93  		OkCodes: []int{200, 202},
    94  	})
    95  	return
    96  }
    97  
    98  // Delete will permanently delete a particular Ipgroups based on its unique ID.
    99  func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) {
   100  	_, r.Err = c.Delete(resourceURL(c, id), nil)
   101  	return
   102  }