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

     1  package snats
     2  
     3  import "github.com/chnsz/golangsdk"
     4  
     5  // CreateOpts is the structure used to create a new private SNAT rule.
     6  type CreateOpts struct {
     7  	// The ID of the gateway to which the private SNAT rule belongs.
     8  	GatewayId string `json:"gateway_id" required:"true"`
     9  	// The ID list of the transit IPs for private NAT.
    10  	TransitIpIds []string `json:"transit_ip_ids" required:"true"`
    11  	// The CIDR block of the match rule.
    12  	// Exactly one of cidr and virsubnet_id must be set.
    13  	Cidr string `json:"cidr,omitempty"`
    14  	// The subnet ID of the match rule.
    15  	// Exactly one of cidr and virsubnet_id must be set.
    16  	SubnetId string `json:"virsubnet_id,omitempty"`
    17  	// The description of the private SNAT rule, which contain maximum of `255` characters, and angle brackets (< and >)
    18  	// are not allowed.
    19  	Description string `json:"description,omitempty"`
    20  }
    21  
    22  var requestOpts = golangsdk.RequestOpts{
    23  	MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"},
    24  }
    25  
    26  // Create is a method used to create a private SNAT rule using given parameters.
    27  func Create(c *golangsdk.ServiceClient, opts CreateOpts) (*Rule, error) {
    28  	b, err := golangsdk.BuildRequestBody(opts, "snat_rule")
    29  	if err != nil {
    30  		return nil, err
    31  	}
    32  
    33  	var r createResp
    34  	_, err = c.Post(rootURL(c), b, &r, &golangsdk.RequestOpts{
    35  		MoreHeaders: requestOpts.MoreHeaders,
    36  	})
    37  	return &r.Rule, err
    38  }
    39  
    40  // Get is a method used to obtain the private SNAT rule detail by its ID.
    41  func Get(c *golangsdk.ServiceClient, ruleId string) (*Rule, error) {
    42  	var r queryResp
    43  	_, err := c.Get(resourceURL(c, ruleId), &r, &golangsdk.RequestOpts{
    44  		MoreHeaders: requestOpts.MoreHeaders,
    45  	})
    46  	return &r.Rule, err
    47  }
    48  
    49  // UpdateOpts is the structure used to modify an existing private SNAT rule.
    50  type UpdateOpts struct {
    51  	// The ID list of the transit IPs for private NAT.
    52  	TransitIpIds []string `json:"transit_ip_ids,omitempty"`
    53  	// The description of the private SNAT rule, which contain maximum of `255` characters, and angle brackets (< and >)
    54  	// are not allowed.
    55  	Description *string `json:"description,omitempty"`
    56  }
    57  
    58  // Update is a method used to modify an existing SNAT rule using given parameters.
    59  func Update(c *golangsdk.ServiceClient, ruleId string, opts UpdateOpts) (*Rule, error) {
    60  	b, err := golangsdk.BuildRequestBody(opts, "snat_rule")
    61  	if err != nil {
    62  		return nil, err
    63  	}
    64  
    65  	var r updateResp
    66  	_, err = c.Put(resourceURL(c, ruleId), b, &r, &golangsdk.RequestOpts{
    67  		MoreHeaders: requestOpts.MoreHeaders,
    68  	})
    69  	return &r.Rule, err
    70  }
    71  
    72  // Delete is a method to remove the specified SNAT rule using its ID.
    73  func Delete(c *golangsdk.ServiceClient, ruleId string) error {
    74  	_, err := c.Delete(resourceURL(c, ruleId), &golangsdk.RequestOpts{
    75  		MoreHeaders: requestOpts.MoreHeaders,
    76  	})
    77  	return err
    78  }