NAT
Acquire Endpoint
When confirming the Endpoint configured when you use the SDK, you can first read the section on VPC Service Domain Name in the Developer Guide to understand the Endpoint concept. Baidu AI Cloud currently opens the multi-region (Region) support. Please refer to the part of network product VPC in Region Selection Introduction. The NAT services are a part of VPC services, and use the VPC service domain name.
Get the Key
To use Baidu Cloud products, you need to have a Baidu Cloud account and a valid AK (Access Key ID) and SK (Secret Access Key) for signature verification. You can obtain and understand your AK/SK information through the following steps:
1.[Register Baidu Cloud Account](https://login.bce.baidu.com/reg.html? tpl=bceplat&from=portal)
2.[Create AK/SK](https://console.bce.baidu.com/iam/? _=1513940574695#/iam/accesslist)
nat_client
Nat_client is the Python client of NAT services, encapsulates the API of NAT services, and simplifies the interaction between developers and NAT services. The users can call the methods in nat_client to configure the NAT gateway. The method return parameter in nat_client is consistent with [API Method](https://console.bce.baidu.com/iam/? _=1513940574695#/iam/accesslist).
Create nat_client
When creating nat_client, you need to first use Endpoint, AK and SK to configure the BceClientConfiguration type config instance, and then use the config instance to configure the nat_client. The specific configuration method is as follows:
HOST = b''
AK = b''
SK = b''
config = BceClientConfiguration(
credentials=BceCredentials(AK, SK), endpoint=HOST)
self.client = nat_client.NatClient(config)
Create an NAT Gateway
The create_nat function can be used to create the gateway in the specified VPC, and is defined as below:
@required(name=(bytes, str),
vpc_id=(bytes, str),
spec=(bytes, str))
def create_nat(self, name, vpc_id, spec, billing=None, eips=None,
client_token=None, config=None)
The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
name | Bytes or str | Yes | The name of NAT gateway is composed by upper and lower case letters, numbers, and -_ /. special characters, and must start with letters, with a length of 1-65. |
vpc_id | Bytes or str | Yes | ID of VPC to which NAT gateway belongs |
spec | Bytes or str | Yes | The size of NAT gateway is divided into three kinds: small (supporting binding a maximum of 5 public network IPs), medium (supporting binding a maximum of 10 public network IPs) and large (supporting binding a maximum of 15 public network IPs). |
billing | Customized Billing type | No | The billing mode is postpaidt by default and supports the monthly repayment. Refer to Billing Description for details. |
eips | List | No | EIP bound to the NAT gateway |
client_token | Bytes or str | No | The idempotence Token is a ASCII string with a length not exceeding 64 bits. Refer to Idempotence Token for details. |
config | BceClientConfiguration | No | Config in initializing nat_client by default |
For the customized Billing type definition, refer to nat_model.py.
Query the NAT Gateway List
The list_nats function can be used to query the NAT gateway list. If the query condition is queried, the NAT gateways are screened according to the query condition. If no query condition is provided, all NAT gateways are queried by default. The function is defined as below:
@required(vpc_id=(bytes, str))
def list_nats(self, vpc_id, nat_id=None, name=None,
ip=None, marker=None, max_keys=None, config=None)
The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
vpc_id | Bytes or str | Yes | ID of VPC to which NAT gateway belongs |
nat_id | Bytes or str | No | ID of NAT gateway |
name | Bytes or str | No | Name of NAT gateway |
ip | Bytes or str | No | IP address bound to the gateway |
marker | Bytes or str | No | Starting location of query for batch acquisition of lists |
maxKeys | int | No | Maximum number contained in each page, generally not exceeding 1000. The default value is 1000. |
config | BceClientConfiguration | No | Config in initializing nat_client by default |
Query the NAT Gateway Details
The get_nat function can be used to query the NAT details, and is defined as below:
@required(nat_id=(bytes, str))
def get_nat(self, nat_id, config=None)
The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
nat_id | Bytes or str | Yes | ID of NAT gateway |
config | BceClientConfiguration | No | Config in initializing nat_client by default |
Update the NAT Gateway Name
The update_nat function can be used to update the NAT gateway name, and is defined as below:
@required(nat_id=(bytes, str), name=(bytes, str))
def update_nat(self, nat_id, name, client_token=None, config=None)
The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
nat_id | Bytes or str | Yes | ID of NAT gateway |
name | Bytes or str | Yes | New name of NAT gateway |
client_token | Bytes or str | No | The idempotence Token is a ASCII string with a length not exceeding 64 bits. Refer to Idempotence Token for details. |
config | BceClientConfiguration | No | Config in initializing nat_client by default |
Bind EIP
The bind_eip function can be used to bind EIP to the NAT gateway, and is defined as below:
@required(nat_id=(bytes, str), eips=list)
def bind_eip(self, nat_id, eips, client_token=None, config=None)
The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
nat_id | Bytes or str | Yes | ID of NAT gateway |
eips | List | Yes | EIP to be bound to the NAT gateway |
client_token | Bytes or str | No | The idempotence Token is a ASCII string with a length not exceeding 64 bits. Refer to Idempotence Token for details. |
config | BceClientConfiguration | No | Config in initializing nat_client by default |
Unbind EIP
The unbind_eip function can be used to unbind EIP from the NAT gateway, and is defined as below:
@required(nat_id=(bytes, str), eips=list)
def unbind_eip(self, nat_id, eips, client_token=None, config=None)
The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
nat_id | Bytes or str | Yes | ID of NAT gateway |
eips | List | Yes | EIP to be unbound from the NAT gateway |
client_token | Bytes or str | No | The idempotence Token is a ASCII string with a length not exceeding 64 bits. Refer to Idempotence Token for details. |
config | BceClientConfiguration | No | Config in initializing nat_client by default |
Release the NAT Gateway
The delete_nat function can be used to release the NAT gateway, and is defined as below:
@required(nat_id=(bytes, str))
def delete_nat(self, nat_id, client_token=None, config=None)
The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
nat_id | Bytes or str | Yes | ID of NAT gateway |
client_token | Bytes or str | No | The idempotence Token is a ASCII string with a length not exceeding 64 bits. Refer to Idempotence Token for details. |
config | BceClientConfiguration | No | Config in initializing nat_client by default |
NAT Gateway Renewal
The purchase_reserved_nat function can be used to renew the NAT gateway, and only the prepaid type supports the renewal operation. The function is defined as below:
@required(nat_id=(bytes, str))
def purchase_reserved_nat(self, nat_id, billing, client_token=None,
config=None)
The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
nat_id | Bytes or str | Yes | ID of NAT gateway |
billing | Customized Billing type | No | For the billion mode, the renewal period is 1 month by default if you don't fill in anything Billing Description for details. |
client_token | Bytes or str | No | The idempotence Token is a ASCII string with a length not exceeding 64 bits. Refer to Idempotence Token for details. |
config | BceClientConfiguration | No | Config in initializing nat_client by default |