This topic describes how to use Alibaba Cloud SDK for Python to create a custom route for a vRouter or virtual border router (VBR).
Prerequisites
Before you run Alibaba Cloud SDK for Python, make sure that the following requirements
are met:
- An Alibaba Cloud account and the AccessKey pair are obtained. You can create and view your AccessKey pair on the Security Management page of the Alibaba Cloud Management Console.
- Make sure that Alibaba Cloud SDK for Python is installed. For more information, see aliyun-python-sdk-vpc 3.0.11.
- The VPC Python example library is downloaded.
Go to the directory where the setup.py file is stored, and run the following command to initialize the environment:
python setup.py install
Background information
- Create a custom route table named sdk_route_table in the China (Zhangjiakou) region.
- Query vSwitches in the VPC named vpc-8vb7ztbjqomi9xxxxxxxx.
- Associate the custom route table with the vSwitch named vsw-8vbfqpcijj0d1xxxxxxxx.
- Add a route to the custom route table. The destination CIDR block is 168.168.0.0/16. The next hop is an Elastic Compute Service (ECS) instance. The ID of the next hop is i-8vbgsnt7046axxxxxxxx.
- Delete the route.
- Disassociate the custom route table from the vSwitch.
- Delete the custom route table.
Procedure
Result
The following output is returned:
---------------------------create_route_table---------------------------
{
"RouteTableId": "vtb-8vbn7px9zxwr2xxxxxxxx",
"RequestId": "8B351EE1-614F-44E4-93AF-1CADA4BF02E8"
}
---------------------------describe_vswitch_attribute---------------------------
{
"Status": "",
"NetworkAclId": "",
"VpcId": "",
"Description": "",
"Ipv6CidrBlock": "",
"CreationTime": "",
"CloudResources": {
"CloudResourceSetType": []
},
"ZoneId": "",
"ResourceGroupId": "",
"VSwitchId": "",
"RequestId": "5E199415-BBA3-443D-B1EC-06341FE267F4",
"VSwitchName": "",
"CidrBlock": ""
}
---------------------------associate_route_table---------------------------
{
"RequestId": "5F33E444-5CCD-4677-91AB-3E234A9A64E4"
}
---------------------------create_route_entry---------------------------
{
"RequestId": "D6035ECA-DD81-4FAB-B084-55BE60FB18ED"
}
---------------------------delete_route_entry---------------------------
{
"RequestId": "54108FD7-8609-4111-919D-B2983466F480"
}
---------------------------unassociate_route_table---------------------------
{
"RequestId": "0F36A76A-1E54-41DC-852E-1D970FDE8F3F"
}
---------------------------delete_route_table---------------------------
{
"RequestId": "F3151A59-4F90-4531-AFDC-B7B7CF70A8C1"
}