Updated on 2023-12-14 GMT+08:00

Creating an SNAT Rule

Function

This API is used to create an SNAT rule.

You can create a DNAT rule only when status of the NAT gateway is ACTIVE and admin_state_up of the NAT gateway administrator is True.

URI

POST /v2.0/snat_rules

Request

Table 1 lists the request parameter.

Table 1 Request parameter

Parameter

Mandatory

Type

Description

snat_rule

Yes

Object

Specifies the SNAT rule object. For details, see Table 2.

Table 2 Description of the snat_rule field

Parameter

Mandatory

Type

Description

nat_gateway_id

Yes

String

Specifies the public NAT gateway ID.

network_id

No

String

Specifies the network ID used by the SNAT rule. Configure either network_id or cidr.

cidr

No

String

Specifies a CIDR block, which can be in the format of a network segment or a host IP address. Configure either cidr or network_id.

If you set source_type to 0, set cidr to a subset of the VPC subnet.

If you set source_type to 1, set cidr to a CIDR block of your on-premises servers connected to the VPC through Direct Connect or Cloud Connect.

source_type

No

Integer

0: VPC. Either network_id or cidr can be specified.

1: Direct Connect/Cloud Connect. Only cidr can be specified.

If no value is entered, the default value 0 (VPC) is used.

floating_ip_id

Yes

String

Specifies the EIP ID. Use commas (,) to separate EIP IDs.

The maximum length is 4,096 bytes.

The number of EIP IDs cannot exceed 20.

Response

Table 3 lists response parameter.

Table 3 Response parameter

Parameter

Type

Description

snat_rule

Object

Specifies the SNAT rule object. For details, see Table 4.

Table 4 Description of the snat_rule field

Parameter

Type

Description

id

String

Specifies the SNAT rule ID.

tenant_id

String

Specifies the project ID.

nat_gateway_id

String

Specifies the public NAT gateway ID.

network_id

String

Specifies the network ID used by the SNAT rule.

cidr

String

Specifies a subset of the VPC subnet CIDR block or a CIDR block of a Direct Connect connection.

source_type

Integer

0: VPC. Either network_id or cidr can be specified.

1: Direct Connect/Cloud Connect. Only cidr can be specified.

If no value is entered, the default value 0 (VPC) is used.

floating_ip_id

String

  • Specifies the EIP ID. Use commas (,) to separate EIP IDs.
  • The maximum length is 4,096 bytes.

floating_ip_address

String

  • Specifies the EIP. Use commas (,) to separate EIPs.
  • The maximum length is 1,024 bytes.

status

String

  • Specifies the status of the SNAT rule.
  • For details about all its values, see Table 1.

admin_state_up

Boolean

  • Specifies whether the SNAT rule is frozen.
  • The value can be:
    • true: The SNAT rule is unfrozen.
    • false: The SNAT rule is frozen.

created_at

String

Specifies when the SNAT rule was created (UTC time). Its value rounds to 6 decimal places for seconds. The format is yyyy-mm-dd hh:mm:ss.

Examples

  • Example request
    1. Configure parameter network_id in a VPC.
      POST https://{Endpoint}/v2.0/snat_rules 
      {
          "snat_rule": {
              "nat_gateway_id": "a78fb3eb-1654-4710-8742-3fc49d5f04f8",
              "network_id": "eaad9cd6-2372-4be1-9535-9bd37210ae7b",
              "source_type":0,
              "floating_ip_id": "bdc10a4c-d81a-41ec-adf7-de857f7c812a"
          }
      }
    1. Configure parameter cidr in a VPC.
      POST https://{Endpoint}/v2.0/snat_rules
      {      
         "snat_rule": {
               "nat_gateway_id": "a78fb3eb-1654-4710-8742-3fc49d5f04f8",
               "cidr": "192.168.1.10/32",
               "source_type":0,
               "floating_ip_id": "bdc10a4c-d81a-41ec-adf7-de857f7c812a"
            }
        }
    1. Configure parameter cidr over a Direct Connect connection.
      POST https://{Endpoint}/v2.0/snat_rules 
       {
            "snat_rule": { 
               "nat_gateway_id": "a78fb3eb-1654-4710-8742-3fc49d5f04f8",
               "cidr": "172.30.0.0/24",
               "source_type":1,
               "floating_ip_id": "bdc10a4c-d81a-41ec-adf7-de857f7c812a"
            }
        }
  • Example response
    1. Response to the request for specifying the network_id for a VPC
      { 
           "snat_rule": { 
               "floating_ip_id": "bdc10a4c-d81a-41ec-adf7-de857f7c812a", 
               "status": "PENDING_CREATE", 
               "nat_gateway_id": "a78fb3eb-1654-4710-8742-3fc49d5f04f8", 
               "admin_state_up": true, 
               "network_id": "eaad9cd6-2372-4be1-9535-9bd37210ae7b", 
               "cidr": null, 
               "source_type":0, 
               "tenant_id": "27e25061336f4af590faeabeb7fcd9a3", 
               "created_at": "2017-11-18 07:54:21.665430", 
               "id": "5b95c675-69c2-4656-ba06-58ff72e1d338", 
               "floating_ip_address": "5.21.11.226"
           } 
       }
    2. Response to the request for specifying the CIDR block in a VPC
      { 
           "snat_rule": { 
               "floating_ip_id": "bdc10a4c-d81a-41ec-adf7-de857f7c812a", 
               "status": "PENDING_CREATE", 
               "nat_gateway_id": "a78fb3eb-1654-4710-8742-3fc49d5f04f8", 
               "admin_state_up": true, 
               "cidr": "192.168.1.10/32", 
               "source_type":0, 
               "tenant_id": "27e25061336f4af590faeabeb7fcd9a3", 
               "created_at": "2017-11-18 07:54:21.665430", 
               "id": "5b95c675-69c2-4656-ba06-58ff72e1d338", 
               "floating_ip_address": "5.21.11.226"
           } 
       }
    3. Response to the request for specifying the CIDR block in a VPC
      { 
           "snat_rule": { 
               "floating_ip_id": "bdc10a4c-d81a-41ec-adf7-de857f7c812a", 
               "status": "PENDING_CREATE", 
               "nat_gateway_id": "a78fb3eb-1654-4710-8742-3fc49d5f04f8", 
               "admin_state_up": true, 
               "cidr": "172.30.0.0/24", 
               "source_type":1, 
               "tenant_id": "27e25061336f4af590faeabeb7fcd9a3", 
               "created_at": "2017-11-18 07:54:21.665430", 
               "id": "5b95c675-69c2-4656-ba06-58ff72e1d338", 
               "floating_ip_address": "5.21.11.226"
           } 
       }

Status Codes

See Status Codes.