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:
1$configs = array(
2 'credentials' => array(
3 'ak' => '',
4 'sk' => '',
5 ),
6 'endpoint' => 'bcc.bj.baidubce.com', //bj
7);
8$client = new VpcClient($configs)
Create VPC
The function is defined as follows:
1/**
2 * @param string $name
3 * The name of vpc to be created.
4 * @param string $cidr
5 * The CIDR of the vpc.
6 * @param string $description
7 * The description of the vpc.
8 * @param string $clientToken
9 * An ASCII string whose length is less than 64.
10 * The request will be idempotent if clientToken is provided.
11 * If the clientToken is not specified by the user, a random String generated by default algorithm will be used.
12 * @param array $options
13 * @return mixed
14 */
15 public function createVpc($name, $cidr, $description = null, $clientToken = null, $options = array()) {
16 .......
17 }
The parameter description is as follows:
| Parameter name | Types | Whether required | Description |
|---|---|---|---|
| name | string | Yes | VPC name, which cannot be set as "default", must not exceed 65 characters, and may consist of numbers, letters, and underscores |
| cidr | string | Yes | VPC CIDR |
| description | string | No | VPC description, not exceeding 200 characters |
| clientToken | string | No | Idempotence Token, an ASCII string with a length not exceeding 64 bits. |
| options | array | No | Additional options |
Usage examples are as follows:
1// testCreateVpc
2$vpcName = 'test_vpc_name'
3$vpcCidr = '192.168.240.0/20'
4$description = 'test_vpc_descrition'
5$resp = $client->createVpc($vpcName, $vpcCidr, $description);
6print_r($resp);
List VPCs
The function is defined as follows:
1/**
2 * Return a list of vpcs owned by the authenticated user.
3 * @param string $marker
4 * The optional parameter marker specified in the original request to specify
5 * where in the results to begin listing.
6 * Together with the marker, specifies the list result which listing should begin.
7 * If the marker is not specified, the list result will listing from the first one.
8 * @param int $maxkeys
9 * The optional parameter to specifies the max number of list result to return.
10 * The default value is 1000.
11 * @param boolean $isDefault
12 * The option param demotes whether the vpc is default vpc.
13 * @param array $options
14 * @return mixed
15 */
16public function listVpcs($marker = null, $maxkeys = null, $isDefault = null, $options = array()) {
17 ......
18}
The parameter description is as follows:
| Parameter name | Types | Whether required | Description |
|---|---|---|---|
| marker | string | No | The starting position of the batch list query is a system-generated string |
| maxKeys | int | No | Maximum number of items included per page, maximum: 1,000, default: 1,000 |
| isDefault | boolean | No | Whether it is the default VPC, with optional values: true or false; if this parameter is not provided, all VPCs will be returned |
| options | array | No | Additional options |
Usage examples are as follows:
1// testListVpcs
2$resp = $client->listVpcs(0, 1000, true);
3print_r($resp);
Query VPC
The function is defined as follows:
1/**
2 * Get the detail information of specified vpc.
3 * @param string $vpcId
4 * The id of the vpc
5 * @param array $options
6 * @return \stdClass
7 */
8public function getVpc($vpcId, $options = array()) {
9 ......
10}
The parameter description is as follows:
| Parameter name | Types | Whether required | Description |
|---|---|---|---|
| vpcId | string | Yes | ID of VPC to be queried |
| options | array | No | Additional options |
Usage examples are as follows:
1// testGetVpc
2$vpcId = ''
3$resp = $client->deleteVpc($vpcId);
4print_r($resp);
Update VPC
The function is defined as follows:
1/**
2 * Modify the special attribute to new value of the vpc owned by the user.
3 * @param string $vpcId
4 * The id of the specified vpc
5 * @param string $name
6 * The name of the specified vpc
7 * @param string $description
8 * The option param to describe the vpc
9 * @param string $clientToken
10 * An ASCII string whose length is less than 64.
11 * The request will be idempotent if clientToken is provided.
12 * If the clientToken is not specified by the user, a random String generated by default algorithm will be used.
13 * @param array $options
14 * @return mixed
15 */
16public function updateVpc($vpcId, $name, $description = null, $clientToken = null, $options = array()) {
17 ......
18}
The parameter description is as follows:
| Parameter name | Types | Whether required | Description |
|---|---|---|---|
| vpcId | string | Yes | ID of VPC to be updated |
| name | string | Yes | VPC name, which cannot be set as "default", must not exceed 65 characters, and may consist of numbers, letters, and underscores |
| description | string | No | VPC description, not exceeding 200 characters |
| clientToken | string | No | Idempotence Token, an ASCII string with a length not exceeding 64 bits. |
| options | array | No | Additional options |
Usage examples are as follows:
1// testUpdateVpc
2$vpcId = ''
3$vpcName = 'vpc-test'
4$description = 'description-test'
5$resp = $client->updateVpc($vpcId, $vpcName, $description);
6print_r($resp);
Delete VPC
The function is defined as follows:
1/**
2 * Delete the specified vpc owned by the user.All resource in the vpc must be deleted before the vpc itself
3 * can be deleted.
4 * @param string $vpcId
5 * The id of the specified vpc
6 * @param string $clientToken
7 * An ASCII string whose length is less than 64.
8 * The request will be idempotent if clientToken is provided.
9 * If the clientToken is not specified by the user, a random String generated by default algorithm will be used.
10 * @param array $options
11 * @return mixed
12 */
13public function deleteVpc( $vpcId, $clientToken = null, $options = array()) {
14 .......
15}
The parameter description is as follows:
| Parameter name | Types | Whether required | Description |
|---|---|---|---|
| vpcId | string | Yes | ID of VPC to be deleted |
| clientToken | string | No | Idempotence Token, an ASCII string with a length not exceeding 64 bits. |
| options | array | No | Additional options |
Usage examples are as follows:
1// testDeleteVpc
2$vpcId = ''
3$resp = $client->deleteVpc($vpcId);
4print_r($resp);
