Subnet
更新时间:2023-09-11
获取Endpoint
在确认您使用SDK时配置的Endpoint时,可先阅读开发人员指南中关于VPC服务域名的部分,理解Endpoint相关的概念。 百度智能云目前开放了多区域支持,请参考区域选择说明中网络产品VPC的部分。
注意: Subnet API支持HTTP和HTTPS两种调用方式。为了提升数据的安全性,建议通过HTTPS调用
获取AK/SK
要使用百度智能云Subnet,您需要拥有一个有效的 AK(Access Key ID)和SK(Secret Access Key)用来进行签名认证。AK/SK是由系统分配给用户的,均为字符串,用于标识用户,为访问服务做签名验证。 可以通过如下步骤获得并了解您的AK/SK信息:
新建SubnetClient
SubnetClient是Subnet服务的客户端,为开发者与Subnet服务进行交互提供了一系列的方法。 新建SubnetClient时,需要先使用Endpoint、AK、SK对BceClientConfiguration类型的config实例进行配置,再使用config实例对SubnetClient进行配置,具体配置方法如下:
Plain Text
1$configs = array(
2 'credentials' => array(
3 'ak' => '',
4 'sk' => '',
5 ),
6 'endpoint' => 'bcc.bj.baidubce.com', //bj
7);
8$client = new SubnetClient($configs)
创建Subnet
函数定义如下:
Plain Text
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}
参数说明如下:
参数名称 | 类型 | 是否必需 | 描述 |
---|---|---|---|
name | string | 是 | 子网名称,不能取值“default”,长度不超过65个字符,可由数字、字符、下划线组成 |
zoneName | string | 是 | 可用区名称 |
cidr | string | 是 | 子网的cidr |
vpcId | string | 是 | 子网所属vpc的id |
subnetType | string | 否 | 子网类型,"BCC"、"BBC" |
description | string | 否 | 子网描述,不超过200字符 |
clientToken | string | 否 | 幂等性Token,是一个长度不超过64位的ASCII字符串 |
options | array | 否 | 额外选项 |
使用示例如下:
Plain Text
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);
列举Subnet
函数定义如下:
Plain Text
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}
参数说明如下:
参数名称 | 类型 | 是否必需 | 描述 |
---|---|---|---|
marker | string | 否 | 批量获取列表的查询的起始位置,是一个由系统生成的字符串 |
maxKeys | int | 否 | 每页包含的最大数量,最大数量通常不超过1000,缺省值为1000 |
vpcId | string | 否 | 子网所属vpc的id |
zoneName | string | 否 | 可用区名称 |
subnetType | string | 否 | 子网类型,"BCC"、"BBC" |
options | array | 否 | 额外选项 |
使用示例如下:
Plain Text
1// testListSubnets
2$resp = $client->listSubnets();
3print_r($resp);
查询Subnet
函数定义如下:
Plain Text
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}
参数说明如下:
参数名称 | 类型 | 是否必需 | 描述 |
---|---|---|---|
SubnetId | string | 是 | 待查询子网的id |
options | array | 否 | 额外选项 |
使用示例如下:
Plain Text
1// testGetSubnet
2$subnetId = ''
3$resp = $client->getSubnet($subnetId);
4print_r($resp);
更新Subnet
函数定义如下:
Plain Text
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}
参数说明如下:
参数名称 | 类型 | 是否必需 | 描述 |
---|---|---|---|
subnetId | string | 是 | 待更新子网的id |
name | string | 是 | 子网名称,不能取值“default”,长度不超过65个字符,可由数字、字符、下划线组成 |
description | string | 否 | 子网描述,不超过200字符 |
clientToken | string | 否 | 幂等性Token,是一个长度不超过64位的ASCII字符串 |
options | array | 否 | 额外选项 |
使用示例如下:
Plain Text
1// testUpdateSubnet
2$subnetId = ''
3$subnetName = 'sbn-test'
4$description = 'description-test'
5$resp = $client->updateSubnet($subnetId, $subnetName $description);
6print_r($resp);
删除Subnet
函数定义如下:
Plain Text
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}
参数说明如下:
参数名称 | 类型 | 是否必需 | 描述 |
---|---|---|---|
subnetId | string | 是 | 待删除子网的id |
clientToken | string | 否 | 幂等性Token,是一个长度不超过64位的ASCII字符串 |
options | array | 否 | 额外选项 |
使用示例如下:
Plain Text
1// testDeleteSubnet
2$subnetId = ''
3$resp = $client->deleteSubnet($subnetId);
4print_r($resp);