百度智能云

All Product Document

          Virtual Private Cloud

          Route

          Acquire Endpoint

          When confirming the Endpoint configured when you use the SDK, you can first read the section on Service Domain Name in the Developer Guide to understand the Endpoint concept. Baidu AI Cloud currently opens the multi-region support. Please refer to the part of network product VPC in Region Selection Introduction. The Route services are a part of VPC services, and use the VPC service domain name.

          Get the Key

          To use Baidu Cloud products, you need to have a Baidu Cloud account and a valid AK (Access Key ID) and SK (Secret Access Key) for signature verification. You can obtain and understand your AK/SK information through the following steps:

          1.[Register Baidu Cloud Account](https://login.bce.baidu.com/reg.html? tpl=bceplat&from=portal)

          2.[Create AK/SK](https://login.bce.baidu.com/? account=&redirect=https://console.bce.baidu.com/iam/? _=1513940574695#/iam/accesslist)

          RouteClient

          Being the client of the Route service, RouteClient provides a series of methods for developers to interact with the Route service. When creating RouteClient, you need to first use Endpoint, AK and SK to configure the BceClientConfigurationl type config instance, and then use the config instance to configure the RouteClient. The specific configuration method is as follows:

          HOST = b''
          AK = b''
          SK = b''
          config = BceClientConfiguration(credentials=BceCredentials(AK, SK), endpoint=HOST)
          self.the_client = route_client.RouteClient(config)

          Query Route Table

          For query of a route table, the request's parameter routeTableId and vpcId cannot be simultaneously empty.

          The instance code for query of a route table is as below:

          def get_route(self, vpc_id=None, route_table_id=None, config=None):  
              path = b'/route'
              params = {}
              if route_table_id is not None:
                  params[b'routeTableId'] = route_table_id
              if vpc_id is not None:
                  params[b'vpcId'] = vpc_id
              return self._send_request(http_methods.GET, path, params=params, config=config)

          The parameters are described as follows:

          Parameter name Type Required or not Description
          vpc_id Bytes or str No At least one of the id of VPC and the route_table_id should be selected.
          route_table_id Bytes or str No At least one of the route table id and the vpc_id should be selected.
          config BceClientConfiguration No Config in initializing route_client by default

          Create Route Rule

          To create route table rules, you need to pay attention to the following points:

          • When "Custom" is selected for the source segment, the customized segment need to be within the existing subnet range, excluding 0.0.0.0/0;
          • The target network and the current VPC cidr cannot overlap (except when the target segment or the VPC cidr is 0.0.0.0/0);
          • The source segment and target segment of added route entries cannot be completely consistent with those of existing entries in the route table.

          The code for creating route rules is as follows:

          def create_route(self, route_table_id, source_address, destination_address,
                               next_hop_type, description, next_hop_id=None, client_token=None,
                               config=None):
              path = b'/route/rule'
              params = {}
              if client_token is None:
                  params[b'clientToken'] = generate_client_token()
              else:
                  params[b'clientToken'] = client_token
              body = {
                  'routeTableId': compat.convert_to_string(route_table_id),
                  'sourceAddress': compat.convert_to_string(source_address),
                  'destinationAddress': compat.convert_to_string(destination_address),
                  'nexthopType': compat.convert_to_string(next_hop_type),
                  'description': compat.convert_to_string(description)
              }
              if next_hop_id is not None:
                  body['nexthopId'] = compat.convert_to_string(next_hop_id)
              return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)

          The parameters are described as follows:

          Parameter name Type Required or not Description
          route_table_id Bytes or str Yes Route table id
          source_address Bytes or str Yes For the source segment, you can fill in all network segments 0.0.0.0/0, existing subnet segments in VPC or segments in the subnet range.
          destination_address Bytes or str Yes The target segment can be 0.0.0.0/0, or the destination address and the current VPC cidr cannot overlap (except when the destination segment or the VPC cidr is 0.0.0.0/0).
          next_hop_type Bytes or str Yes Route type. The Bcc type is "custom"; the VPN type is "vpn"; the NAT type is "nat".
          description Bytes or str Yes Description
          next_hop_id Bytes or str No Next hop id
          client_token Bytes or str No The idempotence Token is a ASCII string with the length of no more than 64 bits.
          config BceClientConfiguration No Config in initializing route_client by default

          Delete Route Rule

          The code for deleting route rules according to the routeRuleId is as follows:

          def delete_route(self, route_rule_id, client_token=None, config=None):     
              path = b'/route/rule/%s' % compat.convert_to_bytes(route_rule_id)
              params = {}
              if client_token is None:
                  params[b'clientToken'] = generate_client_token()
              else:
                  params[b'clientToken'] = client_token
              return self._send_request(http_methods.DELETE, path, params=params, config=config)

          The parameters are described as follows:

          Parameter name Type Required or not Description
          route_rule_id Bytes or str Yes Route rule id
          client_token Bytes or str No The idempotence Token is a ASCII string with the length of no more than 64 bits.
          config BceClientConfiguration No Config in initializing route_client by default
          Previous
          ACL
          Next
          NAT