所有文档

          私有网络 VPC

          Subnet

          获取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信息:

          1. 注册百度智能云账号
          2. 创建AK/SK

          新建SubnetClient

          SubnetClient是Subnet服务的客户端,为开发者与Subnet服务进行交互提供了一系列的方法。 新建SubnetClient时,需要先使用Endpoint、AK、SK对BceClientConfiguration类型的config实例进行配置,再使用config实例对SubnetClient进行配置,具体配置方法如下:

          $configs = array(
              'credentials' => array(
              'ak' => '',
              'sk' => '',
              ),
              'endpoint' => 'bcc.bj.baidubce.com',  //bj
          );
          $client = new SubnetClient($configs)

          创建Subnet

          函数定义如下:

          /**
           * Create a subnet with the specified options.
           * 
           * @param string $name
           *        The name of subnet that will be created.
           * @param string $zoneName
           *        the name of available zone which the subnet belong
           *        through listZones, we can get all available zone info at current region
           *        ee.g. "cn-gz-a"  "cn-gz-b"
           * @param string $cidr
           *        The CIDR of this subnet.
           * @param string $vpcId
           *        The id of vpc which this subnet belongs.
           * @param string $subnetType
           *        The option param to describe the type of subnet create
           * @param string $description
           *        The option param to describe the subnet
           * @param string $clientToken
           *        An ASCII string whose length is less than 64.
           *        The request will be idempotent if clientToken is provided.
           *        If the clientToken is not specified by the user, a random String generated by default algorithm will be used.
           * @param array $options
           * @return mixed
           */
          public function createSubnet($name, $zoneName, $cidr, $vpcId, $subnetType = null, $description = null,                                  $clientToken = null,  $options = array()) {
              ......
          }

          参数说明如下:

          参数名称 类型 是否必需 描述
          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 额外选项

          使用示例如下:

          // testCreateSubnet
          $subnetName = 'sbn-test'
          $zoneName = 'cn-bj-a'
          $cidr = '192.168.0.0/20'
          $vpcId = ''
          $resp = $client->createSubnet($subnetName, $zoneName, $cidr, $vpcId);
          print_r($resp);

          列举Subnet

          函数定义如下:

          /**
           * Return a list of subnets owned by the authenticated user.
           * 
           * @param string $marker
           *        The optional parameter marker specified in the original request to specify
           *        where in the results to begin listing.
           *        Together with the marker, specifies the list result which listing should begin.
           *        If the marker is not specified, the list result will listing from the first one.
           * @param int $maxKeys
           *        The optional parameter to specifies the max number of list result to return.
           *        The default value is 1000.
           * @param string $vpcId
           *        The id of the vpc
           * @param string $zoneName
           *        the name of available zone which the subnet belong
           *        through listZones, we can get all available zone info at current region
           *        ee.g. "cn-gz-a"  "cn-gz-b"
           * @param string $subnetType
           *        he option param to describe the type of subnet to be created
           * @param array $options
           * @return mixed
           */
          public function listSubnets($marker = null, $maxKeys = null, $vpcId = null, $zoneName = null, 
                                      $subnetType = null, $options = array()) {
              ......
          }

          参数说明如下:

          参数名称 类型 是否必需 描述
          marker string 批量获取列表的查询的起始位置,是一个由系统生成的字符串
          maxKeys int 每页包含的最大数量,最大数量通常不超过1000,缺省值为1000
          vpcId string 子网所属vpc的id
          zoneName string 可用区名称
          subnetType string 子网类型,"BCC"、"BBC"
          options array 额外选项

          使用示例如下:

          // testListSubnets
          $resp = $client->listSubnets();
          print_r($resp);

          查询Subnet

          函数定义如下:

          /**
           * Get the detail information of a specified subnet.
           * 
           * @param string $subnetId
           *        the id of the subnet
           * @param array $options
           * @return mixed
           */
          public function getSubnet($subnetId, $options = array()) {
              ......
          }

          参数说明如下:

          参数名称 类型 是否必需 描述
          SubnetId string 待查询子网的id
          options array 额外选项

          使用示例如下:

          // testGetSubnet
          $subnetId = ''
          $resp = $client->getSubnet($subnetId);
          print_r($resp);

          更新Subnet

          函数定义如下:

          /**
           * Modify the special attribute to new value of the subnet owned by the user.
           * 
           * @param string $subnetId
           *        The id of the specific subnet to be updated
           * @param string $name
           *        The name of the subnet
           * @param string $description
           *        The option param to describe the subnet
           * @param string $clientToken
           *        An ASCII string whose length is less than 64.
           *        The request will be idempotent if clientToken is provided.
           *        If the clientToken is not specified by the user, a random String generated by default algorithm will be used.
           * @param array $options
           * @return mixed
           */
          public function updateSubnet($subnetId, $name, $description = null, $clientToken = null, $options = array()) {
              ......
          }

          参数说明如下:

          参数名称 类型 是否必需 描述
          subnetId string 待更新子网的id
          name string 子网名称,不能取值“default”,长度不超过65个字符,可由数字、字符、下划线组成
          description string 子网描述,不超过200字符
          clientToken string 幂等性Token,是一个长度不超过64位的ASCII字符串
          options array 额外选项

          使用示例如下:

          // testUpdateSubnet
          $subnetId = ''
          $subnetName = 'sbn-test'
          $description = 'description-test'
          $resp = $client->updateSubnet($subnetId, $subnetName $description);
          print_r($resp);

          删除Subnet

          函数定义如下:

          /**
           * Delete the specified subnet owned by the user.
           * 
           * @param string $subnetId
           *        the id of the subnet to be deleted
           * @param string $clientToken
           *        An ASCII string whose length is less than 64.
           *        The request will be idempotent if clientToken is provided.
           *        If the clientToken is not specified by the user, a random String generated by default algorithm will be used.
           * @param array $options
           * @return mixed
           */
          public function deleteSubnet($subnetId, $clientToken = null, $options = array()) {
                ......
          }

          参数说明如下:

          参数名称 类型 是否必需 描述
          subnetId string 待删除子网的id
          clientToken string 幂等性Token,是一个长度不超过64位的ASCII字符串
          options array 额外选项

          使用示例如下:

          // testDeleteSubnet
          $subnetId = ''
          $resp = $client->deleteSubnet($subnetId);
          print_r($resp);
          上一篇
          vpc
          下一篇
          安全组