Route
Retrieve Endpoint
Before configuring the Endpoint for SDK usage, please refer to the developer guide section on Service Domains to understand Endpoint-related concepts. Baidu AI Cloud currently supports multiple regions. Please refer to the VPC section in the Region Selection Guide. Route service is part of the VPC service and adopts the VPC service domain name.
Retrieve access key
To use Baidu AI Cloud products, you need a Baidu AI Cloud account along with valid AK (Access Key ID) and SK (Secret Access Key) credentials for signature authorization. You can obtain and understand your AK/SK information through the following steps:
RouteClient
Route client serves as the client for route services, providing developers with a range of methods to interact with route services. When creating a new RouteClient, first configure a BceClientConfigurationl-type config instance using Endpoint, AK and SK, and then use the config instance to configure the RouteClient. The specific configuration method is as follows:
1HOST = b''
2AK = b''
3SK = b''
4config = BceClientConfiguration(credentials=BceCredentials(AK, SK), endpoint=HOST)
5self.the_client = route_client.RouteClient(config)
Query route table
Query route table. The request parameters routeTableId and vpcId cannot both be left empty.
Function declaration
1 @required(vpc_id=(bytes, str),
2 route_table_id=(bytes, str))
3 def get_route(self, vpc_id=None, route_table_id=None, config=None):
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/jjwvyuh0v
Response value
Operation succeeded:
1{
2"routeTableId": "rt-q1zg3i8mx8p6",
3"vpcId": "vpc-56rj0s4ha42a",
4"routeRules": [
5 {
6 "routeTableId": "rt-q1zg3i8mx8p6",
7 "description": "",
8 "nexthopId": "vpn-snx074964j9d",
9 "destinationAddress": "10.0.0.1/32",
10 "sourceAddress": "192.168.0.0/20",
11 "routeRuleId": "rr-dvq3cxpghw5e",
12 "nexthopType": "vpn"
13 },
14 {
15 "routeTableId": "rt-q1zg3i8mx8p6",
16 "description": "",
17 "nexthopId": "",
18 "destinationAddress": "192.168.0.0/20",
19 "sourceAddress": "0.0.0.0/0",
20 "routeRuleId": "",
21 "nexthopType": "sys"
22 },
23 {
24 "routeTableId": "rt-q1zg3i8mx8p6",
25 "description": "",
26 "nexthopId": "",
27 "destinationAddress": "192.168.0.0/20",
28 "sourceAddress": "0.0.0.0/0",
29 "routeRuleId": "",
30 "nexthopType": "sys"
31 }
32 ]
33}
Operation failed:
Return error. Refer to the error code list at: https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7
Code example
For specific code examples, please refer to: example_get_route.py
Create route rules
Function declaration
1@required(route_table_id=(bytes, str),
2 source_address=(bytes, str),
3 destination_address=(bytes, str),
4 description=(bytes, str))
5def create_route(self, route_table_id, source_address, destination_address, next_hop_type=None, description="", next_hop_id=None, ip_version=None, next_hops=None, client_token=None, config=None):
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Ljwvyugpl
Response value
Operation succeeded:
1{"routeRuleId": "rr-dup3cxpebi5e"}
Operation failed:
Return error. Refer to the error code list at: https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7
Code example
For specific code examples, please refer to: example_create_route_rule.py
Delete route rules
Function declaration
1@required(route_rule_id=(bytes, str))
2def delete_route(self, route_rule_id, client_token=None, config=None):
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Vjwvyuge9
Response value
Operation succeeded:
1{}
Operation failed:
Return error. Refer to the error code list at: https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7
Code example
For specific code examples, please refer to: example_delete_route_rule.py
Update route rules
Function declaration
1@required(route_rule_id=(bytes, str),
2 source_address=(bytes, str),
3 destination_address=(bytes, str),
4 description=(bytes, str))
5def update_route(self, route_rule_id, source_address, destination_address, next_hop_type=None, description="", next_hop_id=None, ip_version=None, next_hops=None, client_token=None, config=None):
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Bl6c4kpb4
Response value
Operation succeeded:
1{}
Operation failed:
Return error. Refer to the error code list at: https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7
Code example
For specific code examples, please refer to: example_update_route_rule.py
Query routing rules
Function declaration
1@required(version=(bytes, str),
2 routeTableId=(bytes, str),
3 vpcId=(bytes, str),
4 marker=(bytes, str),
5 maxKeys=int)
6def get_route_rule(self, routeTableId=None, vpcId=None, marker=None, maxKeys=None, config=None):
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Dl6xal44j
Response value
Operation succeeded:
1{
2"nextMarker": "rr-rbn5yyz6rtn8",
3"marker": "rr-y43tr5disam1",
4"maxKeys": 1000,
5"isTruncated": true,
6"routeRules": [{
7 "routeTableId": "rt-q1zg3i8mx8p6",
8 "description": "",
9 "nexthopId": "vpn-snx074964j9d",
10 "destinationAddress": "10.0.0.1/32",
11 "sourceAddress": "192.168.0.0/20",
12 "routeRuleId": "rr-dvq3cxpghw5e",
13 "nexthopType": "vpn"
14 },
15 {
16 "routeTableId": "rt-q1zg3i8mx8p6",
17 "description": "",
18 "nexthopId": "",
19 "destinationAddress": "192.168.0.0/20",
20 "sourceAddress": "0.0.0.0/0",
21 "routeRuleId": "rt-2e9fi8chbxvh",
22 "nexthopType": "sys"
23 },
24 {
25 "routeTableId": "rt-q1zg3i8mx8p6",
26 "description": "",
27 "nexthopId": "",
28 "destinationAddress": "192.168.0.0/20",
29 "sourceAddress": "0.0.0.0/0",
30 "routeRuleId": "rr-rbn5yyz6rtn8",
31 "nexthopType": "sys"
32 }
33]
34}
Operation failed:
Return error. Refer to the error code list at: https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7
Code example
For specific code examples, please refer to: example_get_route_rule.py
Primary-standby switch
Function declaration
1func (c *Client) SwitchRoute(routeRuleId, clientToken string) error
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/xlalxb0tr
Response value
Operation succeeded:
1{}
Operation failed:
Return error. Refer to the error code list at: https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7
Code example
For specific code examples, refer to example_switchroute.py
