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

     1  package dnats
     2  
     3  import "github.com/chnsz/golangsdk"
     4  
     5  // CreateOpts is the structure used to create a new DNAT rule.
     6  type CreateOpts struct {
     7  	// The ID of the gateway to which the DNAT rule belongs.
     8  	GatewayId string `json:"nat_gateway_id" required:"true"`
     9  	// The IDs of floating IP connected by DNAT rule.
    10  	FloatingIpId string `json:"floating_ip_id,omitempty"`
    11  	// The ID of the global EIP connected by the DNAT rule.
    12  	GlobalEipId string `json:"global_eip_id,omitempty"`
    13  	// The protocol type. The valid values are 'udp', 'tcp' and 'any'.
    14  	Protocol string `json:"protocol" required:"true"`
    15  	// The port used by Floating IP provide services for external systems.
    16  	InternalServicePort *int `json:"internal_service_port" required:"true"`
    17  	// The port used by ECSs or BMSs to provide services for external systems.
    18  	ExternalServicePort *int `json:"external_service_port" required:"true"`
    19  	// The port range used by Floating IP provide services for external systems.
    20  	InternalServicePortRange string `json:"internal_service_port_range,omitempty"`
    21  	// The port range used by ECSs or BMSs to provide services for external systems.
    22  	EXternalServicePortRange string `json:"external_service_port_range,omitempty"`
    23  	// The description of the DNAT rule.
    24  	Description string `json:"description,omitempty"`
    25  	// The port ID of network.
    26  	PortId string `json:"port_id,omitempty"`
    27  	// The private IP address of a user.
    28  	PrivateIp string `json:"private_ip,omitempty"`
    29  }
    30  
    31  var requestOpts = golangsdk.RequestOpts{
    32  	MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"},
    33  }
    34  
    35  // Create is a method used to create a DNAT rule using given parameters.
    36  func Create(c *golangsdk.ServiceClient, opts CreateOpts) (*Rule, error) {
    37  	b, err := golangsdk.BuildRequestBody(opts, "dnat_rule")
    38  	if err != nil {
    39  		return nil, err
    40  	}
    41  
    42  	var r createResp
    43  	_, err = c.Post(rootURL(c), b, &r, &golangsdk.RequestOpts{
    44  		MoreHeaders: requestOpts.MoreHeaders,
    45  	})
    46  	return &r.Rule, err
    47  }
    48  
    49  // Get is a method used to obtain the DNAT rule detail by its ID.
    50  func Get(c *golangsdk.ServiceClient, gatewayId string) (*Rule, error) {
    51  	var r queryResp
    52  	_, err := c.Get(resourceURL(c, gatewayId), &r, &golangsdk.RequestOpts{
    53  		MoreHeaders: requestOpts.MoreHeaders,
    54  	})
    55  	return &r.Rule, err
    56  }
    57  
    58  // UpdateOpts is the structure used to modify an existing DNAT rule.
    59  type UpdateOpts struct {
    60  	// The ID of the gateway to which the DNAT rule belongs.
    61  	GatewayId string `json:"nat_gateway_id" required:"true"`
    62  	// The description of the DNAT rule.
    63  	Description *string `json:"description,omitempty"`
    64  	// The port ID of network.
    65  	PortId string `json:"port_id,omitempty"`
    66  	// The private IP address of a user.
    67  	PrivateIp string `json:"private_ip,omitempty"`
    68  	// The protocol type. The valid values are 'udp', 'tcp' and 'any'.
    69  	Protocol string `json:"protocol,omitempty"`
    70  	// The IDs of floating IP connected by DNAT rule.
    71  	FloatingIpId string `json:"floating_ip_id,omitempty"`
    72  	// The ID of the global EIP connected by the DNAT rule.
    73  	GlobalEipId string `json:"global_eip_id,omitempty"`
    74  	// The port used by Floating IP provide services for external systems.
    75  	InternalServicePort *int `json:"internal_service_port,omitempty"`
    76  	// The port used by ECSs or BMSs to provide services for external systems.
    77  	ExternalServicePort *int `json:"external_service_port,omitempty"`
    78  	// The port range used by Floating IP provide services for external systems.
    79  	InternalServicePortRange string `json:"internal_service_port_range,omitempty"`
    80  	// The port range used by ECSs or BMSs to provide services for external systems.
    81  	ExternalServicePortRange string `json:"external_service_port_range,omitempty"`
    82  }
    83  
    84  // Update is a method used to modify an existing DNAT rule using given parameters.
    85  func Update(c *golangsdk.ServiceClient, gatewayId string, opts UpdateOpts) (*Rule, error) {
    86  	b, err := golangsdk.BuildRequestBody(opts, "dnat_rule")
    87  	if err != nil {
    88  		return nil, err
    89  	}
    90  
    91  	var r updateResp
    92  	_, err = c.Put(resourceURL(c, gatewayId), b, &r, &golangsdk.RequestOpts{
    93  		MoreHeaders: requestOpts.MoreHeaders,
    94  	})
    95  	return &r.Rule, err
    96  }
    97  
    98  // Delete is a method to remove the specified DNAT rule using its ID.
    99  func Delete(c *golangsdk.ServiceClient, gatewayId, ruleId string) error {
   100  	_, err := c.Delete(deleteURL(c, gatewayId, ruleId), &golangsdk.RequestOpts{
   101  		MoreHeaders: requestOpts.MoreHeaders,
   102  	})
   103  	return err
   104  }