NAT
Retrieve Endpoint
Before configuring the endpoint for SDK usage, please refer to the developer guide section on VPC Service Domain Name to understand endpoint-related concepts. Baidu AI Cloud currently supports multiple regions. Please refer to the VPC section in the Region Selection Guide. NAT service is part of the VPC service and adopts the VPC service domain name.
Retrieve access key
To use the Baidu AI Cloud products, you need a Baidu AI Cloud account, a valid AK (Access Key ID) and SK (Secret Access Key) for signature certification. Your AK/SK information can be obtained and understood through the following steps:
NatClient
NatClient is the PHP client for NAT services. It encapsulates the NAT service APIs, simplifying developer interaction with NAT services. Users can call methods in NatClient to configure NAT gateways. The return parameters of NatClient methods are consistent with API methods.
Create NatClient
When creating a new NatClient, first configure AclConfigs using endpoint, AK, and SK, then use the AclConfigs to configure the NatClient. The specific configuration method is as follows:
1$g_NatConfigs = array(
2 'credentials' => array(
3 'ak' => '',
4 'sk' => '',
5 ),
6 'endpoint' => '',
7);
8public $client;
9client = new NatClient($g_NatConfigs);
Create NAT gateway
The createNat function can be used to create a gateway within a specified VPC. The function is defined as follows:
1public function createNat($name, $vpcId, $spec, $eips = null, $billing = null, $clientToken = null, $options = array())
The parameter description is as follows:
| Parameter name | Types | Whether required | Description |
|---|---|---|---|
| name | string | Yes | NAT gateway name, which supports uppercase and lowercase letters, numbers, and special characters such as -, _, / and ., starting with a letter, with a length of 1-65. |
| vpcId | string | Yes | ID of VPC to which the NAT gateway belongs |
| spec | string | Yes | NAT gateway sizes include small (supporting up to 5 public IPs), medium (supporting up to 10 public IPs), and large (supporting up to 15 public IPs). Applicable only to standard NAT gateways |
| billing | Custom billing type | No | Billing method, defaulted as postpaid, supporting monthly prepaid purchase. For details, refer to Billing description |
| eips | array | No | EIP bound to NAT gateway |
| clientToken | string | No | Idempotence Token, which is an ASCII string with a length not exceeding 64 bits. For details, see the Idempotence Token. |
| options | array | No | Additional configuration, where parameters in the option can be used to temporarily override the default parameters (AK, SK, endpoint) in NatClient |
The custom billing type definition can be found in Billing.php
Query NAT gateway list
The listNats function can be used to query the NAT gateway list. If query conditions are specified, filtering is performed accordingly. If no conditions are provided, all NAT gateways are queried by default. The function is defined as follows:
1public function listNats($vpcId, $natId = null, $name = null, $ip = null, $marker = null, $maxKeys = 1000,$options = array())
The parameter description is as follows: | Parameter Name | Type | Required | Description | | --- | --- | --- | --- | | vpcId | string | Yes | ID of VPC to which the NAT gateway belongs | | natId | string | No | ID of the NAT gateway | | |name | string | No | New name of the NAT gateway | | ip | string | No | IP address bound to the gateway | |marker | string | No | Starting position for batch querying the list | |maxKeys | int | No |Maximum number of items per page, with a maximum not exceeding 1000. The default is 1,000| |options | array | No |Additional configuration, where parameters in the option can be used to temporarily override the default parameters (AK, SK, endpoint) in NatClient|
Query NAT gateway details
The detailNats function can be used to query NAT details. The function is defined as follows:
1public function detailNats($natId, $options = array())
The parameter description is as follows: | Parameter Name | Type | Required | Description | | --- | --- | --- | --- | | natId | string | Yes | ID of the NAT gateway | | |options | array | No |Additional configuration, where parameters in the option can be used to temporarily override the default parameters (AK, SK, endpoint) in NatClient|
Update NAT gateway name
The renameNat function can be used to update the NAT gateway name. The function is defined as follows:
1public function renameNat($natId, $name, $clientToken = null, $options = array())
The parameter description is as follows: | Parameter Name | Type | Required | Description | | --- | --- | --- | --- | | natId | string | Yes | ID of the NAT gateway | |name | string | Yes | New name of the NAT gateway | |clientToken | string | No | idempotence token, which is an ASCII string with a length not exceeding 64 characters. For details, refer to idempotence token | |options | array | No |Additional configuration, where parameters in the option can be used to temporarily override the default parameters (AK, SK, endpoint) in NatClient|
Bind EIP
The bindNat function can be used to bind an EIP to a NAT gateway. The function is defined as follows:
1public function bindNat($eips, $natId, $clientToken = null, $options = array())
The parameter description is as follows: | Parameter Name | Type | Required | Description | | --- | --- | --- | --- | | natId | string | Yes | ID of the NAT gateway | |eips | array | Required | EIPs to be bound to the NAT gateway | |clientToken | string | No | idempotence token, which is an ASCII string with a length not exceeding 64 characters. For details, refer to idempotence token | |options | array | No |Additional configuration, where parameters in the option can be used to temporarily override the default parameters (AK, SK, endpoint) in NatClient|
Unbind EIP
The unbindNat function can be used to unbind an EIP from a NAT gateway. The function is defined as follows:
1public function unbindNat($eips, $natId, $clientToken = null, $options = array())
The parameter description is as follows: | Parameter Name | Type | Required | Description | | --- | --- | --- | --- | | natId | string | Yes | ID of the NAT gateway | |eips | array | Required | EIPs to be unbound from the NAT gateway | |clientToken | string | No | idempotence token, which is an ASCII string with a length not exceeding 64 characters. For details, refer to Idempotence Token | |options | array | No |Additional configuration, where parameters in the option can be used to temporarily override the default parameters (AK, SK, endpoint) in NatClient|
Release NAT gateway
The releaseNat function can be used to release the NAT gateway. The function is defined as follows:
1public function releaseNat($natId, $clientToken = null, $options = array())
The parameter description is as follows: | Parameter Name | Type | Required | Description | | --- | --- | --- | --- | | natId | string | Yes | ID of the NAT gateway | |clientToken | string | No | idempotence token, which is an ASCII string with a length not exceeding 64 characters. For details, refer to Idempotence Token | |options | array | No |Additional configuration, where parameters in the option can be used to temporarily override the default parameters (AK, SK, endpoint) in NatClient|
NAT gateway renewal
The purchaseReservedNat function can be used to renew the NAT gateway. Renew operations are only supported by prepay types. The function is defined as follows:
1public function purchaseReservedNat($natId, $billing = null, $clientToken = null, $options = array())
The parameter description is as follows: | Parameter Name | Type | Required | Description | | --- | --- | --- | --- | | natId | string | Yes | ID of the NAT gateway | |billing |Custom billing type |No |Charge type. If left blank, it will be defaulted to renew for 1 month. For details, please refer to the Billing Instructions | |clientToken | string | No | idempotence token, which is an ASCII string with a length not exceeding 64 characters. For details, refer to idempotence token | |options | array | No |Additional configuration, where parameters in the option can be used to temporarily override the default parameters (AK, SK, endpoint) in NatClient|
