vpc
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: VPC API supports both HTTP and HTTPS calling methods. To enhance data security, it is recommended to call via HTTPS.
Retrieve AK/SK
To use Baidu AI Cloud VPC, you need a valid AK (Access Key ID) and SK (Secret Access Key) for signature authentication. AK/SK are system-generated strings used to identify users and authenticate service access requests. You can retrieve your AK/SK information by following these steps:
Create VpcClient
VPC client serves as the client for VPC services, providing developers with a range of methods to interact with ACL services. When creating a VPC client, first configure a BCE client configuration-type config instance using endpoint, AK and SK, and then use the config instance to configure the VPC client. The specific configuration method is as follows:
1static final String ENDPOINT = "";
2static final String AK = "";
3static final String SK = "";
4VpcClientConfiguration config = new VpcClientConfiguration();
5config.setCredentials(new DefaultBceCredentials(AK, SK));
6config.setEndpoint(ENDPOINT);
7VpcClient vpcClient = new VpcClient(config);
Create VPC
Function declaration
1public CreateVpcResponse createVpc(String name, String cidr) {
2}
3public CreateVpcResponse createVpc(CreateVpcRequest 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 VPC
Response Value
- Operation succeeded
1{
2 "metadata": For details, refer to the metadata section in the appendix
3 "vpcId":"vpc-yzndfjk4g4u6"
4}
- Operation failed
For response exception list of operation failure, refer to the VPC Exception List.
Code example
For specific code examples, refer to ExampleCreateVpc.java
List VPCs
Function declaration
1 public ListVpcResponse listVpcs() {
2 }
3 public ListVpcResponse listVpcs(ListVpcRequest 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 VPC
Response Value
- Operation succeeded
1{
2 "metadata": For details, refer to the metadata section in the appendix,
3 "marker":null,
4 "isTruncated":false,
5 "maxKeys":1000,
6 "vpcs":[
7 {
8 "vpcId":"vpc-39sz5zhb1jp1",
9 "name":"TestSDK-VPC2",
10 "cidr":"192.168.0.0/16",
11 "ipv6Cidr":"",
12 "description":"vpc test",
13 "tags":[
14 {
15 "tagKey":"tagK",
16 "tagValue":"tagV"
17 }
18 ],
19 "isDefault":false,
20 "secondaryCidr":null,
21 "createdTime":"2023-01-31T08:07:33Z"
22 }
23 ]
24}
- Operation failed
For response exception list of operation failure, refer to the VPC Exception List.
Code example
For specific code examples, refer to ExampleListVpc.java
Query specified VPC
Function declaration
1public GetVpcResponse getVpc(String vpcId) {
2}
3public GetVpcResponse getVpc(GetVpcRequest getVpcRequest) {
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 Specified VPC
Response value
- Operation succeeded
1{
2 "metadata": For details, refer to the metadata section in the appendix,
3 "vpc":{
4 "vpcId":"vpc-39sz5zhb1jp1",
5 "name":"TestSDK-VPC2",
6 "cidr":"192.168.0.0/16",
7 "ipv6Cidr":"",
8 "description":"vpc test",
9 "subnets":[
10 ],
11 "default":false
12 }
13}
- Operation failed
For response exception list of operation failure, refer to the VPC Exception List.
Code example
For specific code examples, refer to ExampleGetVpc.java
Update VPC
Function declaration
1public void modifyInstanceAttributes(String name, String vpcId) {
2 }
3
4public void modifyInstanceAttributes(ModifyVpcAttributesRequest modifyVpcAttributesRequest) {
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 Updating VPC
Response value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the VPC Exception List.
Code example
For specific code examples, refer to ExampleUpdateVpc.java
Delete VPC
Function declaration
1public void deleteVpc(String vpcId) {
2}
3public void deleteVpc(DeleteVpcRequest deleteVpcRequest) {
4}
Parameter Meaning
Please refer to the OpenAPI documentation Request Parameters for Deleting VPC
Response Value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the VPC Exception List.
Code example
For specific code examples, refer to ExampleDeleteVpc.java
Query VPC intranet IP
Function declaration
1 public GetVpcPrivateAddressInfoResponse getVpcPrivateIpAddressInfo(GetVpcPrivateIpAddressInfoRequest request) {
2 ......
3}
Parameter Meaning
Please refer to the OpenAPI documentation Request Parameters for Querying VPC Intranet IP
Response Value
- Operation succeeded
1{
2 "metadata": For details, refer to the metadata section in the appendix,
3 "vpcPrivateIpAddresses":[
4 "privateIpAddress":"192.168.0.36",
5 "privateIpAddressType":"bcc",
6 "createdTime":"2023-01-31T08:07:33Z"
7 ]
8}
- Operation failed
For response exception list of operation failure, refer to the VPC Exception List.
Code example
For specific code examples, refer to ExampleGetVpcPrivateIpAddressInfo.java
Open VPC relay
Function declaration
1public void openVpcRelay(String vpcId) {
2}
3
4public void openVpcRelay(SwitchVpcRelayRequest request) {
5}
Parameter meaning
Please refer to the OpenAPI documentation Parameters for Enabling VPC Relay
Response value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the VPC Exception List.
Code example
For specific code examples, refer to ExampleOpenVpcRelay.java
Shut down VPC relay
Function declaration
1public void shutDownVpcRelay(String vpcId) {
2}
3
4public void shutDownVpcRelay(SwitchVpcRelayRequest request) {
5}
Parameter Meaning
Please refer to the OpenAPI documentation Parameters for Disabling VPC Relay
Response value
- Operation succeeded
No response value
- Operation failed
For response exception list of operation failure, refer to the VPC Exception List.
Code example
For specific code examples, refer to ExampleShutDownVpcRelay.java
Query information on intranet IP occupied VPC products
Function declaration
1public GetVpcResourceIpResponse getVpcResourceIpInfo(GetVpcResourceIpRequest request) {
2 ......
3}
Parameter meaning
Please refer to the OpenAPI documentation Request Parameters for Querying VPC Product Occupied Intranet IP
Response Value
- Operation succeeded
1{
2 "metadata": For details, refer to the metadata section in the appendix,
3 "result": [
4 {
5 "ip": "192.168.0.7",
6 "resourceType": "enic"
7 },
8 {
9 "ip": "192.168.0.8",
10 "resourceType": "enic"
11 }
12 ],
13 "pageNo": 1,
14 "pageSize": 2,
15 "totalCount": 19
16}
- Operation failed
For response exception list of operation failure, refer to the VPC Exception List.
Code example
For specific code examples, refer to ExampleGetVpcResourceIpInfo.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 }
