百度智能云

All Product Document

          Virtual Private Cloud

          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 (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 service. 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/? _= 1569238111708#/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:

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

          Create VPC

          The function is defined as below:

          /**
           * @param string $name
           *        The name of vpc to be created.
           * @param string $cidr
           *        The CIDR of the vpc.
           * @param string $description
           *        The description of the vpc.
           * @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 createVpc($name, $cidr, $description = null, $clientToken = null, $options = array()) {
               .......
           }

          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.
          clientToken string No The idempotence Token is a ASCII string with the length of no more than 64 bits.
          options array No Additional options

          The example is as follows:

          // testCreateVpc
          $vpcName = 'test_vpc_name'
          $vpcCidr = '192.168.240.0/20'
          $description = 'test_vpc_descrition'
          $resp = $client->createVpc($vpcName, $vpcCidr, $description);
          print_r($resp);

          List VPC

          The function is defined as below:

          /**
           * Return a list of vpcs 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 boolean $isDefault
           *        The option param demotes whether the vpc is default vpc.
           * @param array $options
           * @return mixed
           */
          public function listVpcs($marker = null, $maxkeys = null, $isDefault = null, $options = array()) {
              ......
          }

          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 int 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.
          options array No Additional options

          The example is as follows:

          // testListVpcs
          $resp = $client->listVpcs(0, 1000, true);
          print_r($resp);

          Query VPC

          The function is defined as below:

          /**
           * Get the detail information of specified vpc.
           * @param string $vpcId
           *        The id of the vpc
           * @param array $options
           * @return \stdClass
           */
          public function getVpc($vpcId, $options = array()) {
              ......
          }

          The parameters are described as follows:

          Parameter name Type Required or not Description
          vpcId string Yes Id of vpc to be queried.
          options array No Additional options

          The example is as follows:

          // testGetVpc
          $vpcId = ''
          $resp = $client->deleteVpc($vpcId);
          print_r($resp);

          Update VPC

          The function is defined as below:

          /**
           * Modify the special attribute to new value of the vpc owned by the user.
           * @param string $vpcId
           *        The id of the specified vpc
           * @param string $name
           *        The name of the specified vpc
           * @param string $description
           *        The option param to describe the vpc
           * @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 updateVpc($vpcId, $name, $description = null, $clientToken = null, $options = array()) {
              ......
          }

          The parameters are described as follows:

          Parameter name Type Required or not Description
          vpcId string Yes Id of vpc to be updated
          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.
          description string No vpc description, not exceeding 200 characters.
          clientToken string No The idempotence Token is a ASCII string with the length of no more than 64 bits.
          options array No Additional options

          The example is as follows:

          // testUpdateVpc
          $vpcId = ''
          $vpcName = 'vpc-test'
          $description = 'description-test'
          $resp = $client->updateVpc($vpcId, $vpcName, $description);
          print_r($resp);

          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 string $vpcId
           *        The id of the specified vpc
           * @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 deleteVpc( $vpcId, $clientToken = null, $options = array()) {
              .......
          }

          The parameters are described as follows:

          Parameter name Type Required or not Description
          vpcId string Yes Id of vpc to be deleted.
          clientToken string No The idempotence Token is a ASCII string with the length of no more than 64 bits.
          options array No Additional options

          The example is as follows:

          // testDeleteVpc
          $vpcId = '' 
          $resp = $client->deleteVpc($vpcId);
          print_r($resp);
          Previous
          SDK Installation
          Next
          Subnet