Subnet
Retrieve Endpoint
Before configuring the endpoint for SDK usage, please refer to the developer guide section on VPC Service Domain Name to understand endpoint-related concepts. Baidu AI Cloud currently supports multiple regions. Please refer to the network product VPC section in Region Selection Guide.
Note: Subnet API supports both HTTP and HTTPS calling methods. To enhance data security, it is recommended to call via HTTPS.
Retrieve AK/SK
To use the subnets of Baidu AI Cloud, you must have a valid AK (Access Key ID) and SK (Secret Access Key) for signature authentication. AK/SK are system-generated strings that verify users and ensure secure access to services. You can obtain and manage your AK/SK using the following steps:
Create SubnetClient
SubnetClient serves as the client for subnet services, providing developers with a range of methods to interact with subnet services. When creating a SubnetClient, first configure a BCE client configuration-type config instance using endpoint, AK and SK, and then use the config instance to configure the SubnetClient. The specific configuration method is as follows:
1static final String ENDPOINT = ""
2static final String AK = "";
3static final String SK = "";
4SubnetClientConfiguration config = new SubnetClientConfiguration();
5config.setCredentials(new DefaultBceCredentials(AK, SK));
6config.setEndpoint(ENDPOINT);
7SubnetClient subnetClient = new SubnetClient(config);
Create subnet
Function declaration
1public CreateSubnetResponse createSubnet(String name, String vpcId, String cidr, String zoneName) {
2}
3public CreateSubnetResponse createSubnet(CreateSubnetRequest request)
4 throws BceClientException {
5}
Note:
The first API only supports a few common parameters
The second API supports more parameters but requires creating a request instance.
Parameter Meaning
Please refer to the OpenAPI documentation: Request Parameters for Creating Subnet
Response Value
- Operation succeeded
1{
2 "metadata": For details, refer to the metadata section in the appendix,
3 "subnetId":"sbn-p09p0ihp7498"
4}
- Operation failed
For response exception list of operation failure, refer to the Subnet Exception List.
Code example
For specific code examples, refer to ExampleCreateSubnet.java
List subnets
Function declaration
1public ListSubnetsResponse listSubnets() {
2}
3public ListSubnetsResponse listSubnets(ListSubnetsRequest request) {
4}
Note:
The first API only supports a few common parameters
The second API supports more parameters but requires creating a request instance.
Parameter Meaning
Please refer to the OpenAPI documentation: Request Parameters for Listing Subnet
Response Value
- Operation succeeded
1{
2 "metadata": For details, refer to the metadata section in the appendix,
3 "subnets":[
4 {
5 "name": "System predefined subnet",
6 "subnetId":"sbn-qz55vemw0n40",
7 "zoneName":"cn-bj-a",
8 "cidr":"192.168.0.0/20",
9 "ipv6Cidr":"",
10 "vpcId":"vpc-hdq0mqg68si0",
11 "subnetType":"BCC",
12 "description":"",
13 "createdTime":"2020-03-11T04:01:11Z"
14 }
15 ]
16}
- Operation failed
For response exception list of operation failure, refer to the Subnet Exception List.
Code example
For specific code examples, refer to ExampleListSubnet.java
Query subnet
Function declaration
1 public GetSubnetDetailResponse getSubnetDetail(String subnetId) {
2 }
Parameter meaning
Please refer to the OpenAPI documentation: Request Parameters for Querying Subnet
Response value
- Operation succeeded
1{
2 "metadata": For details, refer to the metadata section in the appendix,
3 "subnet": {
4 "name": "System predefined subnet",
5 "subnetId":"sbn-qz55vemw0n40",
6 "zoneName":"cn-bj-a",
7 "cidr":"192.168.0.0/20",
8 "ipv6Cidr":"",
9 "vpcId":"vpc-hdq0mqg68si0",
10 "subnetType":"BCC",
11 "description":"",
12 "createdTime":"2020-03-11T04:01:11Z"
13 }
14}
- Operation failed
For response exception list of operation failure, refer to the Subnet Exception List.
Code example
For specific code examples, refer to ExampleGetSubnet.java
Update subnet
Function declaration
1public void modifySubnetAttributes(String subnetId, String name) {
2}
3public void modifySubnetAttributes(ModifySubnetAttributesRequest modifySubnetAttributesRequest) {
4}
Note:
The first API only supports a few common parameters
The second API supports more parameters but requires creating a request instance.
Parameter Meaning
Please refer to the OpenAPI documentation: Request Parameters for Updating Subnet
Response value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the Subnet Exception List.
Code example
For specific code examples, refer to ExampleUpdateSubnet.java
Delete subnet
Function declaration
1public void deleteSubnet(String subnetId) {
2}
3public void deleteSubnet(DeleteSubnetRequest deleteSubnetRequest) {
4}
Note:
The first API only supports a few common parameters
The second API supports more parameters but requires creating a request instance.
Parameter meaning
Please refer to the OpenAPI documentation: Request Parameters for Deleting Subnet
Response value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the Subnet Exception List.
Code example
For specific code examples, refer to ExampleDeleteSubnet.java
Create reserved network segment
Function declaration
1public CreateIpReservedResponse createIpReserved(CreateIpReservedReq createIpReservedReq) {
2}
Parameter meaning
Please refer to the OpenAPI documentation Request Parameters for Creating Reserved Network Segment
Response value
- Operation succeeded
1{
2 "metadata": For details, refer to the metadata section in the appendix,
3 "ipReserveId":"ipr-vjh3nqvptqkk"
4}
- Operation failed
For response exception list of operation failure, refer to the Reserved Network Segment Exception List.
Code example
For specific code examples, refer to ExampleCreateIpReserve.java
Delete reserved network segment
Function declaration
1public void deleteIpReserve(String ipReserveId) {
2}
3public void deleteIpReserve(DeleteIpReserveRequest deleteIpReserveRequest) {
4}
Note:
The first API only supports a few common parameters
The second API supports more parameters but requires creating a request instance.
Parameter meaning
Please refer to the OpenAPI documentation Request Parameters for Deleting Reserved Network Segment
Response Value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the Reserved Network Segment Exception List.
Code example
For specific code examples, refer to ExampleDeleteIpReserve.java
Query the reserved network segment list
Function declaration
1public ListIpReserveResponse listIpReserve() {
2}
3public ListIpReserveResponse listIpReserve(ListIpReserveRequest request) {
4}
Note:
The first API only supports a few common parameters
The second API supports more parameters but requires creating a request instance.
Parameter Meaning
Please refer to the OpenAPI documentation Request Parameters for Querying Reserved Network Segment
Response Value
- Operation succeeded
1{
2 "metadata": For details, refer to the metadata section in the appendix,
3 "ipReserves":[
4 {
5 "ipReserveId":"ipr-vjh3nqvptqkk",
6 "subnetId":"sbn-6ha6gp1vczuv",
7 "ipCidr":"192.168.0.0/30",
8 "ipVersion":"4",
9 "description":"aaa",
10 "createdTime":"2023-12-08T06:40:20Z",
11 "updatedTime":"2023-12-08T06:40:20Z"
12 }
13 ]
14}
- Operation failed
For response exception list of operation failure, refer to the Reserved Network Segment Exception List.
Code example
For specific code examples, refer to ExampleListIpReserve.java
Appendix
Public response information in Metadata format
1 {
2 "bceRequestId":"f5f0821d-45fe-439b-bbf4-fc48b639f84a",
3 "contentLength":28,
4 "contentType":"application/json;charset=UTF-8",
5 "date":1701917695000,
6 "server":"openresty/1.15.8.1"
7 }
