Subnet
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 subnet API supports both HTTP and HTTPS calling methods. HTTPS calling is recommended to improve data security.
Acquire AK/SK
To use Baidu AI Cloud Subnet, 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 sevice. 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/? _=1513940574695#/iam/accesslist)
Create SubnetClient
Being the client of the Subnet service, SubnetClient provides a series of methods for developers to interact with the Subnet service.
When creating SubnetClient, 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 SubnetClient. The specific configuration method is as follows:
HOST = b'bcc.bj.baidubce.com'
AK = b''
SK = b''
config = BceClientConfiguration(credentials=BceCredentials(AK, SK), endpoint=HOST)
self.the_client = subnet_client.SubnetClient(config)
Create Subnet
The function is defined as below:
@required(name=(bytes, str),
zone_name=(bytes, str),
cidr=(bytes, str),
vpc_id=(bytes, str))
def create_subnet(self, name, zone_name, cidr, vpc_id, subnet_type=None,
description=None, client_token=None, config=None)
The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
name | String | Yes | The subnet name cannot take the "default" value, with the length not exceeding 65 characters, and can be composed by numbers, characters and underlines. |
zone_name | String | Yes | Available zone name |
cidr | String | Yes | cidr of Subnet |
vpc_id | String | Yes | Id of vpc to which the subnet belongs |
subnet_type | String | No | Subnet type, "BCC" and "BBC". |
description | String | No | Subnet description, not exceeding 200 characters. |
client_token | String | No | The idempotence Token is a ASCII string with the length of no more than 64 bits. |
config | String | No | Instance of baidubce.BceClientConfiguration, the config of client is used if nothing is filled in. |
The example is as follows:
subnet_name = 'test_subnet_name'
subnet_cidr = '192.168.0.64/26'
vpc_id = 'vpc-51csm6rxs9mg'
self.the_client.create_subnet(subnet_name, 'cn-bj-a', subnet_cidr, vpc_id))
List Subnet
The function is defined as below:
@required(marker=(bytes, str),
max_Keys=int,
vpc_id=(bytes, str),
zone_name=(bytes, str),
subnet_type=(bytes, str))
def list_subnets(self, marker=None, max_keys=None, vpc_id=None,
zone_name=None, subnet_type=None, config=None):
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. |
max_keys | Integer | No | The maximum quantity contained in each page. The maximum quantity usually does not exceed 1000. The default is 1000 |
vpc_id | String | No | Id of vpc affiliated |
zone_name | String | No | Name of the available zone affiliated |
subnet_type | String | No | Subnet type, "BCC" and "BBC". |
config | String | No | Instance of baidubce.BceClientConfiguration, the config of client is used if nothing is filled in. |
The example is as follows:
self.the_client.list_subnets()
Query Subnet
The function is defined as below:
@required(subnet_id=(bytes, str))
def get_subnet(self, subnet_id, config=None):
The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
subnet_id | String | Yes | Id of subnet to be queried. |
config | String | No | Instance of baidubce.BceClientConfiguration, the config of client is used if nothing is filled in. |
The example is as follows:
self.the_client.get_subnet(subnet_id)
Update Subnet
The function is defined as below:
@required(subnet_id=(bytes, str),
name=(bytes, str),
description=(bytes, str))
def update_subnet(self, subnet_id, name, description=None, client_token=None, config=None):
The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
subnet_id | String | Yes | Id of subnet to be updated. |
name | String | Yes | The subnet 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 | Subnet description, not exceeding 200 characters. |
client_token | String | No | The idempotence Token is a ASCII string with the length of no more than 64 bits. |
config | String | No | Instance of baidubce.BceClientConfiguration, the config of client is used if nothing is filled in. |
The example is as follows:
self.the_client.update_subnet(subnet_id, 'test_update_name1', 'test_update_description1')
Note: The subnet name and description field can be updated only, and the cidr, zone_name and type fields cannot be updated.
Delete Subnet
The function is defined as below:
@required(subnet_id=(bytes, str))
def delete_subnet(self, subnet_id, client_token=None, config=None):
The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
subnet_id | String | Yes | Id of subnet to be deleted |
client_token | String | No | The idempotence Token is a ASCII string with the length of no more than 64 bits. |
config | String | No | Instance of baidubce.BceClientConfiguration, the config of client is used if nothing is filled in. |
The example is as follows:
self.the_client.delete_subnet(subnet_id)