Vpc
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 support. Please refer to the part of network product VPC in Region Selection Introduction.
Note: The VPC API supports both HTTP and HTTPS calling methods. HTTPS calling is recommended to improve data security.
Acquire AK/SK
To use Baidu AI Cloud VPC, 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 sevice. 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 VpcClient
Being the client of the VPC service, VpcClient provides a series of methods for developers to interact with the VPC service. When creating VpcClient, 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 VpcClient. The specific configuration method is as follows:
static final String ENDPOINT = "";
static final String AK = "";
static final String SK = "";
VpcClientConfiguration config = new VpcClientConfiguration();
config.setCredentials(new DefaultBceCredentials(AK, SK));
config.setEndpoint(ENDPOINT);
VpcClient vpcClient = new VpcClient(config);
Create VPC
The function is defined as below:
/**
* Create a vpc with the specified options.
*
* @param name The name of vpc
* @param cidr The CIDR of vpc
* @return List of vpcId newly created
*/
public CreateVpcResponse createVpc(String name, String cidr) {
......
}
/**
* Create a vpc 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 a vpc.
* @return List of vpcId newly created
* @throws BceClientException
*/
public CreateVpcResponse createVpc(CreateVpcRequest 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 vpc name cannot take the "default" value, with the length not exceeding 65 characters, and can be composed by numbers, characters and underlines. |
cidr | String | Yes | cidr of vpc |
description | String | No | vpc description, not exceeding 200 characters. |
The example is as follows:
vpcClient.createVpc("vpc_test_2", "192.168.0.0/16");
List VPC
The function is defined as below:
/**
* Return a list of vpcs owned by the authenticated user.
*
* @return The response containing a list of vpcs owned by the authenticated user.
*/
public ListVpcResponse listVpcs() {
......
}
/**
* Return a list of vpcs owned by the authenticated user.
*
* @param request The request containing all options for listing own's vpc.
* @return The response containing a list of vpcs owned by the authenticated user.
*/
public ListVpcResponse listVpcs(ListVpcRequest 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 |
isDefault | Boolean | No | Default vpc optional values: True, False; return all VPCs when this parameter is not filled in. |
The example is as follows:
vpcClient.listVpcs();
Query VPC
The function is defined as below:
/**
* Get the detail information of specified vpc.
*
* @param vpcId The id of the network.
* @return A vpc detail model for the vpcId.
*/
public GetVpcResponse getVpc(String vpcId) {
/**
* Get the detail information of specified vpc.
*
* @param getVpcRequest The request containing all options for getting the vpc info.
* @return A vpc detail model for the vpcId.
*/
public GetVpcResponse getVpc(GetVpcRequest getVpcRequest) {
......
}
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 |
---|---|---|---|
vpcId | String | Yes | Id of vpc to be queried. |
The example is as follows:
vpcClient.getVpc("vpc-7tay6jx1uj5r");
Update VPC
The function is defined as below:
/**
* Modifying the special attribute to new value of the vpc owned by the user.
* @param name The name of the vpc after modifying
* @param vpcId the id of the vpc
*/
public void modifyInstanceAttributes(String name, String vpcId) {
......
}
/**
* Modifying the special attribute to new value of the vpc owned by the user.
*
* @param modifyVpcAttributesRequest The request containing all options for modifying own's vpc.
*/
public void modifyInstanceAttributes(ModifyVpcAttributesRequest modifyVpcAttributesRequest) {
......
}
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 vpc 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 be updated |
description | String | No | vpc description, not exceeding 200 characters. |
The example is as follows:
vpcClient.modifyInstanceAttributes("test_update_2", "vpc-e8ff5i875svs");
Note: The vpc name and description field can be updated only, and the cidr field cannot be updated.
Delete VPC
The function is defined as below:
/**
* Delete the specified vpc owned by the user.All resource in the vpc must be deleted before the vpc itself
* can be deleted.
*
* @param vpcId The id of the vpc to delete.
*/
public void deleteVpc(String vpcId) {
......
}
/**
* Delete the specified vpc owned by the user.All resource in the vpc must be deleted before the vpc itself
* can be deleted.
*
* @param deleteVpcRequest The request containing all options for deleting own's vpc.
*/
public void deleteVpc(DeleteVpcRequest deleteVpcRequest) {
......
}
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 |
---|---|---|---|
vpcId | String | Yes | Id of vpc to be deleted. |
The example is as follows:
vpcClient.deleteVpc("vpc-2xkpvijkdyp1");