Dedicated line
Dedicated line services
Overview
This document details the usage of ET GO SDK. Prerequisites include prior understanding of dedicated line fundamentals, and dedicated line service. If you are not yet familiar with dedicated line, you can refer to Product Description and Guide.
Initialization
Retrieve Endpoint
Before configuring the endpoint for SDK usage, please refer to the developer guide section on ET Service Domain Name to understand endpoint-related concepts. Baidu AI Cloud currently supports multiple regions. Please refer toRegion 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 ET, you will need a valid AK (Access Key ID) and SK (Secret Access Key) for signature authorization. AK and SK are unique identifiers assigned by the system to verify users and authorize signatures for ET.
Your AK/SK information can be obtained and understood through the following steps:
Register a Baidu AI Cloud account
Create a new ET client
An ET client serves as the interface for ET services, offering developers various methods to interact with these services.
Create a new ET client with AK/SK
Users can refer to the following code to create a new ET Client to access ET with AK/SK:
1import (
2 "github.com/baidubce/bce-sdk-go/services/et"
3)
4func main() {
5 // User’s Access Key ID and Secret Access Key
6 ACCESS_KEY_ID, SECRET_ACCESS_KEY := <your-access-key-id>, <your-secret-access-key>
7 // User-specified Endpoint
8 ENDPOINT := <domain-name>
9 // Initialize an ET Client
10 etClient, err := et.NewClient(AK, SK, ENDPOINT)
11}
In the code above, ACCESS_KEY_ID corresponds to “Access Key ID” in the console. SECRET_ACCESS_KEY corresponds to “Access Key Secret” in the console. Refer to the Guide - How to Retrieve AKSK. The third parameter ENDPOINT is a user-specified domain name. If left empty, the default domain name will be used as the ET service address.
Note:
The endpointparameter must be defined with the domain name of the specified region. For example, if the service is located in Beijing, the endpoint will bebcc.bj.baidubce.com.
Create a ET client with STS
Request STS Token
ET supports temporary third-party access authorization through the STS mechanism. STS (Security Token Service) is a service provided by Baidu AI Cloud that issues temporary access credentials with customizable validity periods and permissions to third-party users. These users can then use the credentials to directly call Baidu AI Cloud APIs or SDKs to access cloud resources.
To access ET using STS, users must first acquire a certification string via the STS client.
Create ET Client with STS Token
Once you have the STS token, configure it in the ET Client to facilitate the creation of an STS-based ET client.
Code example
The GO SDK implements the STS service API. Below is a complete example for requesting an STS Token and creating an ET Client object:
1import (
2 "fmt"
3 "github.com/baidubce/bce-sdk-go/auth" //Import the authentication module
4 "github.com/baidubce/bce-sdk-go/services/et" //Import ET service module
5 "github.com/baidubce/bce-sdk-go/services/sts" //Import the Baige service module
6)
7func main() {
8 //Create a Client object for the STS service, using the default Endpoint
9 AK, SK := <your-access-key-id>, <your-secret-access-key>
10 stsClient, err := sts.NewClient(AK, SK)
11 if err != nil {
12 fmt.Println("create sts client object :", err)
13 return
14 }
15 //Obtain a temporary authentication token with a validity period of 60 seconds and an empty ACL
16 stsObj, err := stsClient.GetSessionToken(60, "")
17 if err != nil {
18 fmt.Println("get session token failed:", err)
19 return
20 }
21 fmt.Println(" GetSessionToken result:")
22 fmt.Println(" accessKeyId:", stsObj.AccessKeyId)
23 fmt.Println(" secretAccessKey:", stsObj.SecretAccessKey)
24 fmt.Println(" sessionToken:", stsObj.SessionToken)
25 fmt.Println(" createTime:", stsObj.CreateTime)
26 fmt.Println(" expiration:", stsObj.Expiration)
27 fmt.Println(" userId:", stsObj.UserId)
28 //Create a ET Client object using the requested temporary STS, with the default endpoint
29 etClient, err := et.NewClient(stsObj.AccessKeyId, stsObj.SecretAccessKey, "bcc.bj.baidubce.com")
30 if err != nil {
31 fmt.Println("create et client failed:", err)
32 return
33 }
34 stsCredential, err := auth.NewSessionBceCredentials(
35 stsObj.AccessKeyId,
36 stsObj.SecretAccessKey,
37 stsObj.SessionToken)
38 if err != nil {
39 fmt.Println("create sts credential object failed:", err)
40 return
41 }
42 etClient.Config.Credentials = stsCredential
43}
Note: Currently, when configuring a ET client with STS, regardless of where the corresponding ET service endpoint is located, the STS endpoint must be set to http://sts.bj.baidubce.com. This default is utilized when creating an STS object in the above code.
Configure HTTPS access to ET
ET supports the HTTPS transport protocol. To use HTTPS to access ET services with the ET Go SDK, specify HTTPS in the endpoint when creating the ET client object.
1// import "github.com/baidubce/bce-sdk-go/services/et"
2 ENDPOINT := ""https://bcc.bj.baidubce.com" // Specify the use of HTTPS protocol
3AK, SK := <your-access-key-id>, <your-secret-access-key>
4etClient, _ := et.NewClient(AK, SK, ENDPOINT)
Configure the ET client
If users need to configure specific parameters for the ET Client, they can customize the configuration using the exported Config field of the ET Client object after its creation. This allows for configuring parameters such as proxy and maximum number of connections for the client.
Use a proxy
The following code snippet enables the client to access ET service using a proxy:
1// import "github.com/baidubce/bce-sdk-go/services/et"
2 // Create an ET Client object
3AK, SK := <your-access-key-id>, <your-secret-access-key>
4ENDPOINT := "bcc.bj.baidubce.com"
5client, _ := et.NewClient(AK, SK, ENDPOINT)
6 // Use the local port 8080 for the proxy
7client.Config.ProxyUrl = "127.0.0.1:8080"
Set network parameters
Users can configure network parameters using the following example code:
1// import "github.com/baidubce/bce-sdk-go/services/et"
2AK, SK := <your-access-key-id>, <your-secret-access-key>
3ENDPOINT := "bcc.bj.baidubce.com"
4client, _ := et.NewClient(AK, SK, ENDPOINT)
5 // Configure to not retry, default: Back Off retry
6client.Config.Retry = bce.NewNoRetryPolicy()
7 // Configure connection timeout to 30 seconds
8client.Config.ConnectionTimeoutInMillis = 30 * 1000
Configure options for generating signature strings
1// import "github.com/baidubce/bce-sdk-go/services/et"
2AK, SK := <your-access-key-id>, <your-secret-access-key>
3ENDPOINT := "bcc.bj.baidubce.com"
4client, _ := et.NewClient(AK, SK, ENDPOINT)
5 // Configure the HTTP request header Host for signing
6headersToSign := map[string]struct{}{"Host": struct{}{}}
7client.Config.SignOption.HeadersToSign = HeadersToSign
8 // Configure the validity period of the signature to 30 seconds
9client.Config.SignOption.ExpireSeconds = 30
Parameter description
When using the GO SDK to access ET, the Config field of the created ET Client object supports the following parameters, as shown in the table below:
| ConfigMap name | Types | Meaning |
|---|---|---|
| Endpoint | string | Domain name for service requests |
| ProxyUrl | string | The proxy address for client requests |
| Region | string | Region for resource requests |
| UserAgent | string | User name, HTTP request’s User-Agent header |
| Credentials | *auth.BceCredentials | Authentication object for requests, divided into regular AK/SK and STS |
| SignOption | *auth.SignOptions | Options for authentication string signing |
| Retry | RetryPolicy | Retry policy for connections |
| ConnectionTimeoutInMillis | int | Connection timeout, in milliseconds, defaulting to 20 minutes |
Description:
- The
Credentialsis created using theauth.NewBceCredentialsandauth.NewSessionBceCredentialsfunctions. The former is used by default, while the latter is used for STS certification. See "Create a ET client with STS" for details. - The
SignOptionfield represents options when generating a signature string, as detailed in the table below:
| Name | Types | Meaning |
|---|---|---|
| HeadersToSign | map[string]struct{} | HTTP headers used when generating the signature string |
| Timestamp | int64 | Timestamp used in the generated signature string, defaulting to the value at the time of sending request |
| ExpireSeconds | int | Validity period of the signature string |
1 Among configuration options, HeadersToSign defaults to `Host`, `Content-Type`, `Content-Length` and `Content-MD5`; TimeStamp is typically set to zero, indicating that the timestamp at the time of generating the certification string shall be used, and users generally shall not explicitly specify the value for this field; ExpireSeconds defaults to 1,800 seconds or 30 minutes.
- The
Retryfield specifies the retry policy, currently supporting two types:NoRetryPolicyandBackOffRetryPolicy. By default, the latter is used. This retry policy specifies the maximum number of retries, the maximum retry duration, and the retry base. Retries increase exponentially based on the retry base multiplied by 2 until the maximum number of retries or the maximum retry duration is reached.
ET
Apply for physical dedicated line
Function declaration
1func (c *Client) CreateEtDcphy(args *CreateEtDcphyArgs) (*CreateEtDcphyResult, error) {
2 ......
3}
Parameter description
Please refer to the OpenAPI documentation: Parameters for Applying for Physical Dedicated Line
Response value
- Operation succeeded
1{
2 "id": "dcphy-gq65bz9ip712"
3}
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, please refer to: examples_create_et.go
Query dedicated line list
Function declaration
1func (c *Client) ListEtDcphy(args *ListEtDcphyArgs) (*ListEtDcphyResult, error) {
2 ......
3}
Parameter description
Please refer to the OpenAPI documentation Parameters for Querying Dedicated Line List
Response Value
- Operation succeeded
1{
2 "nextMarker": "dcphy-gq65bz9ip712",
3 "marker": "dcphy-gq65bz9ie712",
4 "maxKeys": 1,
5 "isTruncated": true,
6 "ets": [{
7 "id": "dcphy-jy1sbnx32ez0",
8 "name": "et_6",
9 "description": "Description",
10 "status": "established",
11 "expireTime": "2019-01-30T08:50:00Z",
12 "isp": "ISP_CTC",
13 "intfType": "10G",
14 "apType": "BAIDU",
15 "apAddr": "BB",
16 "userName": "Zhang San",
17 "userPhone": "133*****333",
18 "userEmail": "1***@123.com",
19 "userIdc": "Beijing|Municipal District|Dongcheng District|2321"
20 "tags": []
21 }]
22}
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, please refer to: examples_list_et.go
Query dedicated line details
Function declaration
1func (c *Client) ListEtDcphyDetail(dcphyId string) (*EtDcphyDetail, error) {
2 ......
3}
Parameter description
Please refer to the OpenAPI documentation Parameters for Querying Dedicated Line Details
Response Value
- Operation succeeded
1{
2 "id": "dcphy-gq65bz9ip712",
3 "name": "ZX051501-testET",
4 "description": "",
5 "status": "established",
6 "expireTime": 1,
7 "isp": "ISP_CUCC",
8 "intfType": "10G",
9 "apType": "SINGLE",
10 "apAddr": "WHGG",
11 "userName": "Zhang San",
12 "userPhone": "133*****333",
13 "userEmail": "1***@123.com",
14 "userIdc": "Beijing|Municipal Districts|Dongcheng District|Baidu Technology Park K2"
15 "tags":[]
16}
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, please refer to: examples_list_et_detail.go
Update physical dedicated line
Function declaration
1func (c *Client) UpdateEtDcphy(dcphyId string, args *UpdateEtDcphyArgs) error {
2 ......
3}
Parameter description
Please refer to the OpenAPI documentation: Parameters for Updating Physical Dedicated Line
Response Value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, please refer to: examples_update_et.go
Create dedicated channel
Function declaration
1func (c *Client) CreateEtChannel(args *CreateEtChannelArgs) (*CreateEtChannelResult, error) {
2 ......
3}
Parameter description
Please refer to the OpenAPI documentation: Parameters for Creating Dedicated Channel
Response Value
- Operation succeeded
1 {
2 "id": "dedicatedconn-zy9t7n91k0iq"
3 }
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, refer to examples_create_et_channel.go
Query dedicated channel
Function declaration
1func (c *Client) GetEtChannel(args *GetEtChannelArgs) (*EtChannelResult, error) {
2 ......
3}
Parameter description
Please refer to the OpenAPI documentation: Parameters for Querying Dedicated Channel
Response Value
- Operation succeeded
1 {
2 "etChannels": [
3 {
4 "authorizedUsers": [
5 "8770xxxxxxxxxxxxxxxxxxxxxxx4df8"
6 ],
7 "description": "",
8 "baiduAddress": "11.11.11.21/24",
9 "name": "channel_name",
10 "bgpAsn": "45084",
11 "bgpKey": "7kab824",
12 "customerAddress": "11.11.11.12/24",
13 "routeType": "bgp",
14 "vlanId": 56,
15 "id":"dedicatedconn-zy9t7n91k0iq",
16 "status":"building",
17 "enableIpv6": 1,
18 "baiduIpv6Address": "2400:da00:e003:0:1eb:200::1/88",
19 "customerIpv6Address": "2400:da00:e003:0:0:200::1/88"
20 "tags": []
21 }
22 ]
23 }
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, please refer to: examples_get_et_channel.go
Resubmit the dedicated channel
Function declaration
1func (c *Client) RecommitEtChannel(args *RecommitEtChannelArgs) error {
2 ......
3}
Parameter description
Refer to the OpenAPI documentation: Parameters for Resubmitting Dedicated Channel
Response Value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, please refer to: examples_recommit_et_channel.go
Update dedicated channel
Function declaration
1func (c *Client) UpdateEtChannel(args *UpdateEtChannelArgs) error {
2 ......
3}
Parameter description
Please refer to the OpenAPI documentation: Parameters for Updating Dedicated Channel
Response Value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, please refer to: examples_update_et_channel.go
Delete dedicated channel
Function declaration
1func (c *Client) DeleteEtChannel(args *DeleteEtChannelArgs) error {
2 ......
3}
Parameter description
Please refer to the OpenAPI documentation: Parameters for Deleting Dedicated Channel
Response Value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, please refer to: examples_delete_et_channel.go
Enable IPv6 function for the dedicated channel
Function declaration
1func (c *Client) EnableEtChannelIPv6(args *EnableEtChannelIPv6Args) error {
2 ......
3}
Parameter description
Refer to OpenAPI documentation: Parameters for Enabling IPv6 Function for Dedicated Channel
Response Value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, please refer to:examples_enable_channel_ipv6.go
Disable dedicated channel IPv6 function
Function declaration
1func (c *Client) DisableEtChannelIPv6(args *DisableEtChannelIPv6Args) error {
2 ......
3}
Parameter description
Refer to OpenAPI documentation: Parameters for Disabling IPv6 for Dedicated Channel
Response Value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, please refer to:example_disable_et_channel_ipv6.go
Create routing rules of Dedicated channel
Function declaration
1func (c *Client) CreateEtChannelRouteRule(args *CreateEtChannelRouteRuleArgs) (*CreateEtChannelRouteRuleResult, error) {
2 ......
3}
Parameter
Refer to OpenAPI documentation: Parameters for Creating Dedicated Channel Routing Rules
Response Value
- Operation succeeded
1{
2 "routeRuleId":"dcrr-5afcf643-94e"
3}
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, please refer to: example_create_et_channel_route_rule.go
Query the routing rules of the dedicated channel
Function declaration
1func ListEtChannelRouteRule() {
2 ......
3}
Parameter
Refer to OpenAPI documentation: Parameters for Querying Dedicated Channel Routing Rule
Response Value
- Operation succeeded
1{
2 "nextMarker": "14eabc99-dce7-11ec-84d4-6c92bf29c398",
3 "maxKeys": 1,
4 "isTruncated": true,
5 "routeRules": [{
6 "routeRuleId": "dcrr-5afcf643-94e",
7 "ipVersion": 4,
8 "destAddress": "10.0.0.1/32",
9 "nexthopType": "etGateway"
10 "nexthopId": "dcgw-arc647h3014w",
11 "description": "route_1"
12 }]
13}
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, please refer to:example_list_et_channel_route_rules.go
Modify the dedicated channel routing rules
Function declaration
1func UpdateEtChannelRouteRule() {
2 ......
3}
Parameter
Refer to OpenAPI documentation: Parameters for Modifying Dedicated Channel Routing Rules
Response Value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, please refer to: example_update_et_channel_route_rule.go
Delete routing rules of dedicated channel
Function declaration
1func DeleteEtChannelRouteRule() {
2 ......
3}
Parameter
Refer to OpenAPI documentation: Parameters for Deleting Dedicated Channel Routing Rules
Response Value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the Exception List.
Example code
For specific code examples, please refer to: example_delete_et_channel_route_rule.go
