github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/networking/v2/extensions/dnatrules/Create.go (about)

     1  package dnatrules
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     7  )
     8  
     9  // CreateOpts contains all the values needed to create a new dnat rule
    10  // resource.
    11  type CreateOpts struct {
    12  	NatGatewayID        string `json:"nat_gateway_id" required:"true"`
    13  	PortID              string `json:"port_id,omitempty"`
    14  	PrivateIp           string `json:"private_ip,omitempty"`
    15  	InternalServicePort *int   `json:"internal_service_port" required:"true"`
    16  	FloatingIpID        string `json:"floating_ip_id" required:"true"`
    17  	ExternalServicePort *int   `json:"external_service_port" required:"true"`
    18  	Protocol            string `json:"protocol" required:"true"`
    19  }
    20  
    21  // Create will create a new Waf Certificate on the values in CreateOpts.
    22  func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*DnatRule, error) {
    23  	b, err := build.RequestBody(opts, "dnat_rule")
    24  	if err != nil {
    25  		return nil, err
    26  	}
    27  
    28  	// POST /v2.0/dnat_rules
    29  	raw, err := client.Post(client.ServiceURL("dnat_rules"), b,
    30  		nil, &golangsdk.RequestOpts{
    31  			OkCodes: []int{201},
    32  		})
    33  	if err != nil {
    34  		return nil, err
    35  	}
    36  
    37  	var res DnatRule
    38  	err = extract.IntoStructPtr(raw.Body, &res, "dnat_rule")
    39  	return &res, err
    40  }
    41  
    42  type DnatRule struct {
    43  	// Specifies the DNAT rule ID.
    44  	ID string `json:"id"`
    45  	// Specifies the project ID.
    46  	ProjectId string `json:"tenant_id"`
    47  	// Specifies the NAT gateway ID.
    48  	NatGatewayId string `json:"nat_gateway_id"`
    49  	// Specifies the port ID of the cloud server (ECS or BMS).
    50  	// This parameter is used in the VPC scenario, where this parameter or private_ip must be specified.
    51  	PortId string `json:"port_id"`
    52  	// Specifies the IP address of an on-premises network connected by a Direct Connect connection.
    53  	// This parameter is used in the Direct Connect scenario. This parameter and port_id are alternative.
    54  	PrivateIp string `json:"private_ip"`
    55  	// Specifies the port number used by the cloud server (ECS or BMS) to provide services for external systems.
    56  	InternalServicePort int `json:"internal_service_port"`
    57  	// Specifies the EIP ID.
    58  	FloatingIpId string `json:"floating_ip_id"`
    59  	// Specifies the EIP address.
    60  	FloatingIpAddress string `json:"floating_ip_address"`
    61  	// Specifies the port for providing services for external systems.
    62  	ExternalServicePort int `json:"external_service_port"`
    63  	// Specifies the protocol. TCP, UDP, and ANY are supported.
    64  	// The protocol number of TCP, UDP, and ANY are 6, 17, and 0, respectively.
    65  	Protocol string `json:"protocol"`
    66  	// Provides supplementary information about the DNAT rule.
    67  	Description string `json:"description"`
    68  	// Specifies the status of the DNAT rule.
    69  	Status string `json:"status"`
    70  	// Specifies whether the NAT gateway is up or down.
    71  	// The value can be:
    72  	// true: The DNAT rule is enabled.
    73  	// false: The DNAT rule is disabled.
    74  	AdminStateUp *bool `json:"admin_state_up"`
    75  	// Specifies when the DNAT rule was created (UTC time).
    76  	// Its value rounds to 6 decimal places for seconds. The format is yyyy-mm-dd hh:mm:ss.
    77  	CreatedAt string `json:"created_at"`
    78  }