Elastic network interface
Initialization
Confirm 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 Region Selection Guide.
Currently supported regions are: "North China-Beijing," "South China-Guangzhou," "East China-Suzhou," "Hong Kong," "Central Finance-Wuhan," and "North China-Baoding." Corresponding details:
| Access region | Endpoint | Protocol |
|---|---|---|
| BJ | bcc.bj.baidubce.com | HTTP and HTTPS |
| GZ | bcc.gz.baidubce.com | HTTP and HTTPS |
| SU | bcc.su.baidubce.com | HTTP and HTTPS |
| HKG | bcc.hkg.baidubce.com | HTTP and HTTPS |
| FWH | bcc.fwh.baidubce.com | HTTP and HTTPS |
| BD | bcc.bd.baidubce.com | HTTP and HTTPS |
Retrieve access key
To use Baidu AI Cloud's route feature, users need an AK (Access Key ID) and SK (Secret Access Key) for signature authentication. These keys are system-assigned strings used to identify users and verify signatures.
Your AK/SK information can be obtained and understood through the following steps:
Register a Baidu AI Cloud account
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
1type PrivateIp struct {
2 PublicIpAddress string `json:"publicIpAddress"`
3 Primary bool `json:"primary"`
4 PrivateIpAddress string `json:"privateIpAddress"`
5}
6type CreateEniArgs struct {
7 ClientToken string `json:"-"`
8 Name string `json:"name"`
9 SubnetId string `json:"subnetId"`
10 InstanceId string `json:"instanceId,omitempty"`
11 SecurityGroupIds []string `json:"securityGroupIds"`
12 EnterpriseSecurityGroupIds []string `json:"enterpriseSecurityGroupIds"`
13 PrivateIpSet []PrivateIp `json:"privateIpSet"`
14 Ipv6PrivateIpSet []PrivateIp `json:"ipv6PrivateIpSet,omitempty"`
15 Description string `json:"description,omitempty"`
16}
17type CreateEniResult struct {
18 EniId string `json:"eniId"`
19}
20func (c *Client) CreateEni(args *CreateEniArgs) (*CreateEniResult, error)
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/pkknfara0
Response value
Operation succeeded:
1{
2 "eniId":"eni-2dn7v328tegp"
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_create_eni.go
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
1type UpdateEniArgs struct {
2 EniId string `json:"-"`
3 ClientToken string `json:"-"`
4 Name string `json:"name"`
5 Description string `json:"description"`
6}
7func (c *Client) UpdateEni(args *UpdateEniArgs) error
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Zkknfh5h8
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.go
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
1type DeleteEniArgs struct {
2 EniId string
3 ClientToken string
4}
5func (c *Client) DeleteEni(args *DeleteEniArgs) error
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.go
Query elastic network interface list
Function declaration
1type ListEniArgs struct {
2 VpcId string
3 InstanceId string
4 Name string
5 Marker string
6 MaxKeys int
7 PrivateIpAddress []string `json:"privateIpAddress,omitempty"`
8}
9type ListEniResult struct {
10 Eni []Eni `json:"enis"`
11 Marker string `json:"marker"`
12 IsTruncated bool `json:"isTruncated"`
13 NextMarker string `json:"nextMarker"`
14 MaxKeys int `json:"maxKeys"`
15}
16func (c *Client) ListEni(args *ListEniArgs) (*ListEniResult, error)
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 "isTruncated":true,
57 "nextMarker":"eni-ziqsx63b3nfq",
58 "maxKeys":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.go
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.
- A privateIpAddress value of "" indicates automatic allocation of an IP address.
- 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
1type EniPrivateIpArgs struct {
2 EniId string `json:"-"`
3 ClientToken string `json:"-"`
4 IsIpv6 bool `json:"isIpv6,omitempty"`
5 PrivateIpAddress string `json:"privateIpAddress"`
6}
7type AddPrivateIpResult struct {
8 PrivateIpAddress string `json:"privateIpAddress"`
9}
10func (c *Client) AddPrivateIp(args *EniPrivateIpArgs) (*AddPrivateIpResult, error)
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Hkknfl4q3
Response value
Operation succeeded:
1{
2 "privateIpAddress":"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.go
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
1type EniPrivateIpArgs struct {
2 EniId string `json:"-"`
3 ClientToken string `json:"-"`
4 IsIpv6 bool `json:"isIpv6,omitempty"`
5 PrivateIpAddress string `json:"privateIpAddress"`
6}
7func (c *Client) DeletePrivateIp(args *EniPrivateIpArgs) error
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.go
Query the specified elastic network interface
Function declaration
1type Eni struct {
2 EniId string `json:"eniId"`
3 Name string `json:"name"`
4 ZoneName string `json:"zoneName"`
5 Description string `json:"description"`
6 InstanceId string `json:"instanceId"`
7 MacAddress string `json:"macAddress"`
8 VpcId string `json:"vpcId"`
9 SubnetId string `json:"subnetId"`
10 Status string `json:"status"`
11 PrivateIpSet []PrivateIp `json:"privateIpSet"`
12 Ipv6PrivateIpSet []PrivateIp `json:"ipv6PrivateIpSet"`
13 SecurityGroupIds []string `json:"securityGroupIds"`
14 EnterpriseSecurityGroupIds []string `json:"enterpriseSecurityGroupIds"`
15 CreatedTime string `json:"createdTime"`
16}
17func (c *Client) GetEniDetail(eniId string) (*Eni, error)
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/6kknfn5m8
Response value
Operation succeeded:
1{
2 "eniId":"eni-477g9akswgjv",
3 "name":"GO_SDK_TEST_UPDATE",
4 "zoneName":"cn-bj-d",
5 "description":"go sdk update",
6 "instanceId":"",
7 "macAddress":"fa:20:20:2f:b2:ae",
8 "vpcId":"vpc-jm7h2j497ut7",
9 "subnetId":"sbn-d63m7t0bbwt5",
10 "status":"available",
11 "privateIpSet":[
12 {
13 "publicIpAddress":"",
14 "primary":true,
15 "privateIpAddress":"10.0.1.100"
16 }],
17 "ipv6PrivateIpSet":[
18 {
19 "publicIpAddress":"",
20 "primary":false,
21 "privateIpAddress":"240c:4081:8005:5e04::2"
22 }],
23 "securityGroupIds":[],
24 "enterpriseSecurityGroupIds":["esg-1atxb1iqd1e2"],
25 "createdTime":"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_eni_detail.go
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
1type EniInstance struct {
2 EniId string `json:"-"`
3 InstanceId string `json:"instanceId"`
4 ClientToken string `json:"-"`
5}
6func (c *Client) AttachEniInstance(args *EniInstance) error
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.go
Detach elastic network interface from cloud host
- Only elastic network interfaces in the mounted state can be detached from a cloud host.
Function declaration
1type EniInstance struct {
2 EniId string `json:"-"`
3 InstanceId string `json:"instanceId"`
4 ClientToken string `json:"-"`
5}
6func (c *Client) DetachEniInstance(args *EniInstance) error
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.go
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
1type BindEniPublicIpArgs struct {
2 EniId string `json:"-"`
3 ClientToken string `json:"-"`
4 PrivateIpAddress string `json:"privateIpAddress"`
5 PublicIpAddress string `json:"publicIpAddress"`
6}
7func (c *Client) BindEniPublicIp(args *BindEniPublicIpArgs) error
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.go
Elastic network interface unbinds from EIP
- Network interface cards in attaching or detaching states cannot be disassociated from an EIP.
Function declaration
1type UnBindEniPublicIpArgs struct {
2 EniId string `json:"-"`
3 ClientToken string `json:"-"`
4 PublicIpAddress string `json:"publicIpAddress"`
5}
6func (c *Client) UnBindEniPublicIp(args *UnBindEniPublicIpArgs) error
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_public_ip.go
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
1type UpdateEniSecurityGroupArgs struct {
2 EniId string `json:"-"`
3 ClientToken string `json:"-"`
4 SecurityGroupIds []string `json:"securityGroupIds"`
5}
6func (c *Client) UpdateEniSecurityGroup(args *UpdateEniSecurityGroupArgs) error
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.go
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
1type UpdateEniEnterpriseSecurityGroupArgs struct {
2 EniId string `json:"-"`
3 ClientToken string `json:"-"`
4 EnterpriseSecurityGroupIds []string `json:"enterpriseSecurityGroupIds"`
5}
6func (c *Client) UpdateEniEnterpriseSecurityGroup(args *UpdateEniEnterpriseSecurityGroupArgs) error
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.go
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
1type EniBatchPrivateIpArgs struct {
2 EniId string `json:"-"`
3 ClientToken string `json:"-"`
4 IsIpv6 bool `json:"isIpv6,omitempty"`
5 PrivateIpAddresses []string `json:"privateIpAddresses"`
6 PrivateIpAddressCount int `json:"privateIpAddressCount,omitempty"`
7}
8func (c *Client) BatchDeletePrivateIp(args *EniBatchPrivateIpArgs) error
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.go
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
1type EniBatchPrivateIpArgs struct {
2 EniId string `json:"-"`
3 ClientToken string `json:"-"`
4 IsIpv6 bool `json:"isIpv6,omitempty"`
5 PrivateIpAddresses []string `json:"privateIpAddresses"`
6 PrivateIpAddressCount int `json:"privateIpAddressCount,omitempty"`
7}
8type BatchAddPrivateIpResult struct {
9 PrivateIpAddresses []string `json:"privateIpAddresses"`
10}
11func (c *Client) BatchAddPrivateIp(args *EniBatchPrivateIpArgs) (*BatchAddPrivateIpResult, error)
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/9kw4xi713
Response value
Operation succeeded:
1{
2 "privateIpAddresses": ["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.go
Query elastic network interface status
Function declaration
1type EniStatusInfo struct {
2 Status string `json:"status"`
3}
4func (c *Client) GetEniStatus(eniId string) (*EniStatusInfo, error)
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.go
