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 a Baidu AI Cloud subnet, users need a valid Access Key ID (AK) and Secret Access Key (SK) for signature authentication. AK/SK are system-generated strings that identify users and authenticate service access. You can learn how to obtain and understand your AK/SK information by following these 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 BceClientConfiguration-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:
1$configs = array(
2 'credentials' => array(
3 'ak' => '',
4 'sk' => '',
5 ),
6 'endpoint' => 'bcc.bj.baidubce.com', //bj
7);
8$client = new SubnetClient($configs)
Create subnet
The function is defined as follows:
1/**
2 * Create a subnet with the specified options.
3 *
4 * @param string $name
5 * The name of subnet that will be created.
6 * @param string $zoneName
7 * the name of available zone which the subnet belong
8 * through listZones, we can get all available zone info at current region
9 * ee.g. "cn-gz-a" "cn-gz-b"
10 * @param string $cidr
11 * The CIDR of this subnet.
12 * @param string $vpcId
13 * The id of vpc which this subnet belongs.
14 * @param string $subnetType
15 * The option param to describe the type of subnet create
16 * @param string $description
17 * The option param to describe the subnet
18 * @param string $clientToken
19 * An ASCII string whose length is less than 64.
20 * The request will be idempotent if clientToken is provided.
21 * If the clientToken is not specified by the user, a random String generated by default algorithm will be used.
22 * @param array $options
23 * @return mixed
24 */
25public function createSubnet($name, $zoneName, $cidr, $vpcId, $subnetType = null, $description = null, $clientToken = null, $options = array()) {
26 ......
27}
The parameter description is as follows:
| Parameter name | Types | Whether required | Description |
|---|---|---|---|
| name | string | Yes | Subnet name, which cannot be set as "default", must not exceed 65 characters, and may consist of numbers, letters, and underscores |
| zoneName | string | Yes | Availability zone name |
| cidr | string | Yes | Subnet cidr |
| vpcId | string | Yes | ID of VPC to which the subnet belongs |
| subnetType | string | No | Subnet type, "BCC", "BBC" |
| description | string | No | Subnet 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// testCreateSubnet
2$subnetName = 'sbn-test'
3$zoneName = 'cn-bj-a'
4$cidr = '192.168.0.0/20'
5$vpcId = ''
6$resp = $client->createSubnet($subnetName, $zoneName, $cidr, $vpcId);
7print_r($resp);
List subnets
The function is defined as follows:
1/**
2 * Return a list of subnets owned by the authenticated user.
3 *
4 * @param string $marker
5 * The optional parameter marker specified in the original request to specify
6 * where in the results to begin listing.
7 * Together with the marker, specifies the list result which listing should begin.
8 * If the marker is not specified, the list result will listing from the first one.
9 * @param int $maxKeys
10 * The optional parameter to specifies the max number of list result to return.
11 * The default value is 1000.
12 * @param string $vpcId
13 * The id of the vpc
14 * @param string $zoneName
15 * the name of available zone which the subnet belong
16 * through listZones, we can get all available zone info at current region
17 * ee.g. "cn-gz-a" "cn-gz-b"
18 * @param string $subnetType
19 * he option param to describe the type of subnet to be created
20 * @param array $options
21 * @return mixed
22 */
23public function listSubnets($marker = null, $maxKeys = null, $vpcId = null, $zoneName = null,
24 $subnetType = null, $options = array()) {
25 ......
26}
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 |
| vpcId | string | No | ID of VPC to which the subnet belongs |
| zoneName | string | No | Availability zone name |
| subnetType | string | No | Subnet type, "BCC", "BBC" |
| options | array | No | Additional options |
Usage examples are as follows:
1// testListSubnets
2$resp = $client->listSubnets();
3print_r($resp);
Query subnet
The function is defined as follows:
1/**
2 * Get the detail information of a specified subnet.
3 *
4 * @param string $subnetId
5 * the id of the subnet
6 * @param array $options
7 * @return mixed
8 */
9public function getSubnet($subnetId, $options = array()) {
10 ......
11}
The parameter description is as follows:
| Parameter name | Types | Whether required | Description |
|---|---|---|---|
| SubnetId | string | Yes | ID of subnet to be queried |
| options | array | No | Additional options |
Usage examples are as follows:
1// testGetSubnet
2$subnetId = ''
3$resp = $client->getSubnet($subnetId);
4print_r($resp);
Update subnet
The function is defined as follows:
1/**
2 * Modify the special attribute to new value of the subnet owned by the user.
3 *
4 * @param string $subnetId
5 * The id of the specific subnet to be updated
6 * @param string $name
7 * The name of the subnet
8 * @param string $description
9 * The option param to describe the subnet
10 * @param string $clientToken
11 * An ASCII string whose length is less than 64.
12 * The request will be idempotent if clientToken is provided.
13 * If the clientToken is not specified by the user, a random String generated by default algorithm will be used.
14 * @param array $options
15 * @return mixed
16 */
17public function updateSubnet($subnetId, $name, $description = null, $clientToken = null, $options = array()) {
18 ......
19}
The parameter description is as follows:
| Parameter name | Types | Whether required | Description |
|---|---|---|---|
| subnetId | string | Yes | ID of subnet to be updated |
| name | string | Yes | Subnet name, which cannot be set as "default", must not exceed 65 characters, and may consist of numbers, letters, and underscores |
| description | string | No | Subnet 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// testUpdateSubnet
2$subnetId = ''
3$subnetName = 'sbn-test'
4$description = 'description-test'
5$resp = $client->updateSubnet($subnetId, $subnetName $description);
6print_r($resp);
Delete subnet
The function is defined as follows:
1/**
2 * Delete the specified subnet owned by the user.
3 *
4 * @param string $subnetId
5 * the id of the subnet to be deleted
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 deleteSubnet($subnetId, $clientToken = null, $options = array()) {
14 ......
15}
The parameter description is as follows:
| Parameter name | Types | Whether required | Description |
|---|---|---|---|
| subnetId | string | Yes | ID of subnet 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// testDeleteSubnet
2$subnetId = ''
3$resp = $client->deleteSubnet($subnetId);
4print_r($resp);
