百度智能云

All Product Document

          Virtual Private Cloud

          Subnet

          Acquire Endpoint

          When confirming the Endpoint configured when you use the SDK, you can first read the section on VPC Access Domain Name in the Developer Guide to understand the Endpoint concept. Baidu AI Cloud currently opens the multi-region (Region) support. Please refer to the part of network product VPC in Region Selection Introduction.

          Note: The subnet API supports both HTTP and HTTPS calling methods. HTTPS calling is recommended to improve data security.

          Acquire AK/SK

          To use Baidu AI Cloud Subnet, you need to have a valid AK (Access Key ID) and SK (Secret Access Key) for signature authentication. AK/SK is assigned to users by the system and is a string to identify users and verify signatures for accessing service. You can obtain and understand your AK/SK information through the following steps:

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

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

          Create SubnetClient

          Being the client of the Subnet service, SubnetClient provides a series of methods for developers to interact with the Subnet service. When creating SubnetClient, 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 SubnetClient. The specific configuration method is as follows:

          static final String ENDPOINT = ""
          static final String AK = "";
          static final String SK = "";
          
          SubnetClientConfiguration config = new SubnetClientConfiguration();
          config.setCredentials(new DefaultBceCredentials(AK, SK));
          config.setEndpoint(ENDPOINT);
          SubnetClient subnetClient = new SubnetClient(config);

          Create Subnet

          The function is defined as below:

          /**
           *
           * @param name   The name of subnet that will be created.
           * @param vpcId  The id of vpc which this subnet belong.
           * @param cidr   The CIDR of this subnet.
           * @param zoneName
           *        the name of available zone which the subnet belong
           *        through listZones, we can get all available zone info at current region
           *        ee.g. "cn-gz-a"  "cn-gz-b"
           * @return
           */
          public CreateSubnetResponse createSubnet(String name, String vpcId, String cidr, String zoneName) {
              ......
          }
          
          /**
           * Create a subnet with the specified options.
           * You must fill the field of clientToken,which is especially for keeping idempotent.
           *
           * @param request The request containing all options for creating subnet.
           * @return List of subnetId newly created
           * @throws BceClientException
           */
          public CreateSubnetResponse createSubnet(CreateSubnetRequest request)
              throws BceClientException {
              ......
          }

          Note:
          The first interface only supports a few common parameters.
          The second interface can support more parameters, but the request instance should be created.

          The parameters are described as follows:

          Parameter name Type Required or not Description
          name String Yes The subnet name cannot take the "default" value, with the length not exceeding 65 characters, and can be composed by numbers, characters and underlines.
          vpcId String Yes Id of vpc to which the subnet belongs
          cidr String Yes cidr of Subnet
          zoneName String Yes Available zone name
          subnetType String No Subnet type, "BCC" and "BBC".
          description String No Subnet description, not exceeding 200 characters.

          The example is as follows:

          subnetClient.createSubnet("test_subnet_2", "vpc-e8ff5i875svs", "192.168.0.0/20", "cn-bj-a");

          List Subnet

          The function is defined as below:

          /**
           * Return a list of subnets owned by the authenticated user.
           *
           * @return The response containing a list of subnets owned by the authenticated user.
           */
          public ListSubnetsResponse listSubnets() {
              ......
          }
          
          /**
           * Return a list of subnet owned by the authenticated user.
           *
           * @param request The request containing all options for listing own's subnet.
           * @return The response containing a list of subnets owned by the authenticated user.
           */
          public ListSubnetsResponse listSubnets(ListSubnetsRequest request) {
              ......
          }

          Note:
          The first interface only supports a few common parameters.
          The second interface can support more parameters, but the request instance should be created.

          The parameters are described as follows:

          Parameter name Type Required or not Description
          marker String No The starting location of query for batch acquisition of lists, and is one string generated by the system.
          maxKeys Integer No The maximum quantity contained in each page. The maximum quantity usually does not exceed 1000. The default is 1000
          vpcId String No Id of vpc affiliated
          zoneName String No Name of the available zone affiliated
          subnetType String No Subnet type, "BCC" and "BBC".

          The example is as follows:

          subnetClient.listSubnets();

          Query Subnet

          The function is defined as below:

           /**
               * Get the detail information of specified subnet.
               *
               * @param subnetId The id of the subnet.
               * @return A subnet detail model for the subnetId.
               */
          public GetSubnetResponse getSubnet(String subnetId) {
          
          /**
               * Get the detail information of specified subnet.
               *
               * @param getSubnetRequest The request containing all options for getting the subnet info.
               * @return A subnet detail model for the subnetId.
               */
          public GetSubnetResponse getSubnet(GetSubnetRequest getSubnetRequest) {

          Note:
          The first interface only supports a few common parameters.
          The second interface can support more parameters, but the request instance should be created.

          The parameters are described as follows:

          Parameter name Type Required or not Description
          subnetId String Yes Id of subnet to be queried.

          The example is as follows:

          subnetClient.getSubnet("sbn-kvrxdch0rwaf");

          Update Subnet

          The function is defined as below:

          /**
           * Modifying the special attribute to new value of the subnet owned by the user.
           * @param subnetId The id of the subnet
           * @param name The name of the subnet after modifying
           */
          public void modifySubnetAttributes(String subnetId, String name) {
              ......
          }
          
          /**
           * Modifying the special attribute to new value of the subnet owned by the user.
           *
           * @param modifySubnetAttributesRequest The request containing all options for modifying own's subnet.
           */
          public void modifySubnetAttributes(ModifySubnetAttributesRequest modifySubnetAttributesRequest) {
              ......
          }

          Note
          The first interface only supports a few common parameters.
          The second interface can support more parameters, but the request instance should be created.

          The parameters are described as follows:

          Parameter name Type Required or not Description
          subnetId String Yes Id of subnet to be updated.
          name String Yes The subnet name cannot take the "default" value, with the length not exceeding 65 characters, and can be composed by numbers, characters and underlines.
          description String No Subnet description, not exceeding 200 characters.

          The example is as follows:

          subnetClient.modifySubnetAttributes("sbn-eg6ixcdpa3j2", "subnet_modify");

          Note: The subnet name and description field can be updated only, and the cidr, zoneName and subnetType fields cannot be updated.

          Delete Subnet

          The function is defined as below:

          /**
           * Delete the specified subnet owned by the user.
           *
           * @param subnetId The id of the subnet to delete.
           */
          public void deleteSubnet(String subnetId) {
              ......
          }
          
          /**
           * Delete the specified subnet owned by the user.
           *
           * @param deleteSubnetRequest the request containing all options for deleting own's subnet.
           */
          public void deleteSubnet(DeleteSubnetRequest deleteSubnetRequest) {
              ......
          }

          Note
          The first interface only supports a few common parameters.
          The second interface can support more parameters, but the request instance should be created.

          The parameters are described as follows:

          Parameter name Type Required or not Description
          subnetId String Yes Id of subnet to be deleted

          The example is as follows:

          subnetClient.deleteSubnet("sbn-kvrxdch0rwaf");
          Previous
          Vpc
          Next
          Security Group