Elastic network interface
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 network product VPC section in Region Selection Guide.
Note: API supports both HTTP and HTTPS calling methods. To enhance data security, it is recommended to call via HTTPS.
Retrieve AK/SK
To use Baidu AI Cloud VPC, you need a valid AK (Access Key ID) and SK (Secret Access Key) for signature authentication. AK/SK are system-generated strings used to identify users and authenticate service access requests. You can retrieve your AK/SK information by following these steps:
Create elastic network interface
- IPv4 and IPv6 private IPs can be assigned. The specified private IP must fall within the subnet of the elastic network interface and must not be in use.
- Among the specified IPv4 addresses, only one can be defined as the primary IP address, while all others must be secondary IP addresses.
- When assigning an IPv6 IP address, the subnet associated with the elastic network interface must have an allocated IPv6 segment. All assigned IPv6 addresses are secondary IP addresses.
- A privateIpAddress value of "" indicates that an IP address will be allocated automatically.
- When creating an elastic network interface, you can bind it to an existing regular security group or an alternative enterprise security group. The VPC of the security group must match the VPC of the network interface card.
Function declaration
1def create_eni(self, name, subnet_id, security_group_ids=None, enterprise_security_group_ids=None,
2 eni_ip_address_list=None, eni_ipv6_address_list=None, description=None,
3 client_token=None, config=None)
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/pkknfara0
Response value
Operation succeeded:
1{
2 "eni_id":"eni-2dn7v328tegp"
3}
Operation failed:
Throw an exception. For the exception list, refer to: https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7
Code example
For specific code examples, refer to example_create_eni.py
Update elastic network interface
- Modify the name and description of the elastic network interface.
- Name, which supports uppercase and lowercase letters, numbers, and special characters such as -, _, / and ., starting with a letter and a length of 1-65
- Name and description cannot both be empty
Function declaration
1def update_eni(self, eni_id, name=None, description=None, client_token=None, config=None)
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/pkknfara0
Response value
Operation succeeded:
1There are no special response parameters
Operation failed:
Throw an exception. For the exception list, refer to: https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7
Code example
For specific code examples, refer to example_update_eni.py
Delete elastic network interface
- Elastic network interfaces that are mounted, in the process of being mounted, or unmounted cannot be deleted.
- Upon deletion, all private intranet IPs associated with the elastic network interface will be released.
Function declaration
1def delete_eni(self, eni_id, client_token=None, config=None)
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/ikknfinx7
Response value
Operation succeeded:
1There are no special response parameters
Operation failed:
An exception is thrown; for the exception list, refer to https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7#Elastic network interface service error codes
Code example
For specific code examples, refer to example_delete_eni.py
Query elastic network interface list
Function declaration
1def list_eni(self, vpc_id, instance_id=None, name=None, private_ip_address_list=None,
2 marker=None, max_keys=None, client_token=None, config=None)
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Okknfjt6o
Response value
Operation succeeded:
1{
2 "enis":[
3 {
4 "eniId":"eni-tnj00he350fh",
5 "name":"eni-1",
6 "zoneName":"cn-bj-d",
7 "description":"",
8 "instanceId":"",
9 "macAddress":"fa:20:20:2f:c6:30",
10 "vpcId":"vpc-jm7h2j497ut7",
11 "subnetId":"sbn-d63m7t0bbwt5",
12 "status":"available",
13 "privateIpSet":[
14 {
15 "publicIpAddress":"",
16 "primary":true,
17 "privateIpAddress":"10.0.1.115"
18 },
19 {
20 "publicIpAddress":"",
21 "primary":false,
22 "privateIpAddress":"10.0.1.6"
23 }],
24 "ipv6PrivateIpSet":[],
25 "securityGroupIds":null,
26 "enterpriseSecurityGroupIds":null,
27 "createdTime":"2023-12-06T06:32:46Z"
28 },
29 {
30 "eniId":"eni-2dn7v328tegp",
31 "name":"eni-1",
32 "zoneName":"cn-bj-d",
33 "description":"",
34 "instanceId":"",
35 "macAddress":"fa:20:20:30:08:08",
36 "vpcId":"vpc-jm7h2j497ut7",
37 "subnetId":"sbn-d63m7t0bbwt5",
38 "status":"available",
39 "privateIpSet":[
40 {
41 "publicIpAddress":"",
42 "primary":true,
43 "privateIpAddress":"10.0.1.116"
44 },
45 {
46 "publicIpAddress":"",
47 "primary":false,
48 "privateIpAddress":"10.0.1.7"
49 }],
50 "ipv6PrivateIpSet":[],
51 "securityGroupIds":null,
52 "enterpriseSecurityGroupIds":null,
53 "createdTime":"2023-12-06T07:07:10Z"
54 }],
55 "marker":"eni-tnj00he350fh",
56 "is_truncated":true,
57 "next_marker":"eni-ziqsx63b3nfq",
58 "max_keys":2
59}
Operation failed:
An exception is thrown; for the exception list, refer to https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7#Elastic network interface service error codes
Code example
For specific code examples, refer to example_list_eni.py
Add Intranet IP to elastic network interface
- When isIpv6 is set to true, it signifies the addition of an IPv6 private intranet IP. The subnet linked with the elastic network interface must have an assigned IPv6 segment.
- The privateIpAddress of "" indicates automatic IP address allocation.
- If a privateIpAddress is specified, it must correspond to an IP address within the subnet.
- Any additional private intranet IPs assigned will serve as secondary IP addresses.
Function declaration
1def add_private_ip(self, eni_id, private_ip_address, is_ipv6=None, client_token=None, config=None)
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Hkknfl4q3
Response value
Operation succeeded:
1{
2 "private_ip_address":"10.0.1.108"
3}
Operation failed:
An exception is thrown; for the exception list, refer to https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7#Elastic network interface service error codes
Code example
For specific code examples, refer to example_add_private_ip.py
Delete Intranet IP from elastic network interface
- The primary IP address is not deletable; only secondary IP addresses can be removed.
- You can specify IPv4 or IPv6 intranet IPs for deletion.
Function declaration
1def delete_private_ip(self, eni_id, private_ip_address, client_token=None, config=None)
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/jkknfm534
Response value
Operation succeeded:
1There are no special response parameters
Operation failed:
An exception is thrown; for the exception list, refer to https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7#Elastic network interface service error codes
Code example
For specific code examples, refer to example_delete_private_ip.py
Query the specified elastic network interface
Function declaration
1def get_eni_details(self, eni_id, client_token=None, config=None)
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/6kknfn5m8
Response value
Operation succeeded:
1{
2 "eni-id":"eni-477g9akswgjv",
3 "name":"PYTHON_SDK_TEST_UPDATE",
4 "zone_name":"cn-bj-d",
5 "description":"PYTHON sdk update",
6 "instance_id":"",
7 "mac_address":"fa:20:20:2f:b2:ae",
8 "vpc_id":"vpc-jm7h2j497ut7",
9 "subnet_id":"sbn-d63m7t0bbwt5",
10 "status":"available",
11 "private_ip_set":[
12 {
13 "public_ip_address":"",
14 "primary":true,
15 "private_ip_address":"10.0.1.100"
16 }],
17 "ipv6Private_ip_set":[
18 {
19 "public_ip_address":"",
20 "primary":false,
21 "private_ip_address":"240c:4081:8005:5e04::2"
22 }],
23 "security_group_ids":[],
24 "enterprise_security_group_ids":["esg-1atxb1iqd1e2"],
25 "created_time":"2023-11-24T11:39:54Z"
26}
Operation failed:
An exception is thrown; for the exception list, refer to https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7#Elastic network interface service error codes
Code example
For specific code examples, refer to example_get_specific_eni.py
Attach elastic network interface to cloud host
- A cloud host can have multiple elastic network interfaces attached, but only one primary network interface card.
- An elastic network interface can be attached to only one cloud host.
- Elastic network interfaces can only be attached to cloud hosts that are in running or stopped states.
- The elastic network interface and its attached cloud host must belong to the same virtual private cloud, and their respective subnets must be in the same availability zone.
Function declaration
1def attach_eni_instance(self, eni_id, instance_id, client_token=None, config=None)
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/qkknfp44w
Response value
Operation succeeded:
1There are no special response parameters
Operation failed:
An exception is thrown; for the exception list, refer to https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7#Elastic network interface service error codes
Code example
For specific code examples, refer to example_attach_eni_instance.py
Detach elastic network interface from cloud host
- Only elastic network interfaces in the mounted state can be detached from a cloud host.
Function declaration
1def detach_eni_instance(self, eni_id, instance_id, client_token=None, config=None)
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/jkknfq87r
Response value
Operation succeeded:
1There are no special response parameters
Operation failed:
An exception is thrown; for the exception list, refer to https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7#Elastic network interface service error codes
Code example
For specific code examples, refer to example_detach_eni_instance.py
Elastic network interface binds to EIP
- Network interface cards that are in attaching or detaching states cannot be associated with an EIP.
- Network interface cards within NAT-dedicated subnets cannot be associated with an EIP.
Function declaration
1def bind_eni_public_ip(self, eni_id, privat_ip_address, public_ip_address, client_token=None, config=None)
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/vkknfr857
Response value
Operation succeeded:
1There are no special response parameters
Operation failed:
An exception is thrown; for the exception list, refer to https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7#Elastic network interface service error codes
Code example
For specific code examples, refer to example_bind_eni_public_ip.py
Elastic network interface unbinds from EIP
- Network interface cards in attaching or detaching states cannot be disassociated from an EIP.
Function declaration
1def unbind_eni_public_ip(self, eni_id, public_ip_address, client_token=None, config=None)
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Hkknfs7ee
Response value
Operation succeeded:
1There are no special response parameters
Operation failed:
An exception is thrown; for the exception list, refer to https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7#Elastic network interface service error codes
Code example
For specific code examples, refer to example_unbind_eni_public_ip.py
Update elastic network interface with regular security group
- An elastic network interface must be associated with at least one security group, either a regular security group or an enterprise security group.
- This operation associates the elastic network interface with a final regular security group while removing it from any existing regular or enterprise security groups.
Function declaration
1def update_eni_security_group(self, eni_id, security_group_ids, client_token=None, config=None)
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Nkknft2l0
Response value
Operation succeeded:
1There are no special response parameters
Operation failed:
An exception is thrown; for the exception list, refer to https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7#Elastic network interface service error codes
Code example
For specific code examples, refer to example_update_eni_sg.py
Update elastic network interface with enterprise security group
- An elastic network interface must be associated with at least one security group, either a regular security group or an enterprise security group.
- This operation associates the elastic network interface with an enterprise security group while removing it from any existing regular or enterprise security groups.
Function declaration
1def update_eni_enterprise_security_group(self, eni_id, enterprise_security_group_ids,
2 client_token=None, config=None)
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Jl5kp9uyw
Response value
Operation succeeded:
1There are no special response parameters
Operation failed:
An exception is thrown; for the exception list, refer to https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7#Elastic network interface service error codes
Code example
For specific code examples, refer to example_update_eni_esg.py
Delete Intranet IP from elastic network interface in batches
- The primary IP address is not deletable; only secondary IP addresses can be removed.
- You can specify IPv4 or IPv6 intranet IPs for deletion.
Function declaration
1def batch_delete_private_ip(self, eni_id, private_ip_address_list, client_token=None, config=None)
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Akw4yd4ht
Response value
Operation succeeded:
1There are no special response parameters
Operation failed:
An exception is thrown; for the exception list, refer to https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7#Elastic network interface service error codes
Code example
For specific code examples, refer to example_batch_delete_private_ip.py
Add intranet IP to elastic network interface in batches
- Any additional private intranet IPs assigned will serve as secondary IP addresses.
- When isIpv6 is set to true, it signifies the addition of an IPv6 private intranet IP. The subnet linked with the elastic network interface must have an assigned IPv6 segment.
Function declaration
1def batch_add_private_ip(self, eni_id, is_ipv6=None, private_ip_address_list=None,
2 private_ip_address_count=None, client_token=None, config=None)
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/9kw4xi713
Response value
Operation succeeded:
1{
2 "private_ip_addresses": ["10.0.1.201","10.0.1.202"]
3}
Operation failed:
An exception is thrown; for the exception list, refer to https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7#Elastic network interface service error codes
Code example
For specific code examples, refer to example_batch_add_private_ip.py
Query elastic network interface status
Function declaration
1def get_eni_status(self, eni_id, client_token=None, config=None)
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/alk0j86xp
Response value
Operation succeeded:
1{
2 "status": "available"
3}
Operation failed:
An exception is thrown; for the exception list, refer to https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7#Elastic network interface service error codes
Code example
For specific code examples, refer to example_get_eni_status.py
