Subnet

VPC VPC

  • API Reference
    • ACL-Related Interfaces
      • Add ACL rule
      • Delete ACL rules
      • Query ACL rules
      • Query ACL
      • Update ACL rules
    • API function release records
    • API Overview
    • Appendix
    • Common Headers and Error Responses
    • Dedicated Gateway-Related Interfaces
      • Bind physical dedicated line
      • Create dedicated gateway
      • Create health check for dedicated gateway
      • Query dedicated gateway details
      • Query dedicated gateway list
      • Release dedicated gateway
      • Unbind physical dedicated line
      • Update dedicated gateway
    • Elastic Network Interface-Related Interfaces
      • Add intranet IP to elastic network interface in batches
      • Add Secondary IP Address of Elastic Network Interface
      • Create elastic network interface
      • Delete elastic network interface
      • Delete Intranet IP from elastic network interface in batches
      • Delete Secondary IP Address of Elastic Network Interface
      • Elastic network interface binds to EIP
      • Elastic Network Interface Mounts Cloud Product Instance
      • Elastic network interface unbinds from EIP
      • Elastic Network Interface Unmounts Cloud Product Instance
      • Query elastic network interface list
      • Query elastic network interface status
      • Query the specified elastic network interface
      • Update elastic network interface with enterprise security group
      • Update elastic network interface with regular security group
      • Update elastic network interface
    • Gateway Bandwidth Limiting Rule Related Interfaces
      • Create gateway bandwidth limiting rules
      • Delete Gateway Bandwidth Limiting Rule
      • Modify Gateway Bandwidth Limiting Rule
      • View Gateway Bandwidth Limiting Rule
    • General Description
    • High-Availability Virtual IP Address(HAVIP) Related Interfaces
      • Bind EIP to high-availability virtual IP address
      • Bind instance to high-availability virtual IP address
      • Create high-availability virtual IP address
      • Delete high-availability virtual IP address
      • Query high-availability virtual IP address list
      • Query the specified high-availability virtual IP address
      • Unbind EIP from high-availability virtual IP address
      • Unbind instance from high-availability virtual IP address
      • Update high-availability virtual IP address
    • Interface Overview
    • IPv6 Gateway-Related Interfaces
      • Add IPv6 egress-only policy
      • Bandwidth resizing for IPv6 gateway
      • Create IPv6 gateway bandwidth limiting policy
      • Create IPv6 gateway
      • Delete IPv6 gateway bandwidth limiting policy
      • Delete IPv6 Gateway
      • Delete the IPv6 egress-only policy
      • Query IPv6 gateway bandwidth limiting policy list
      • Query IPv6 gateway
      • Query the IPv6 egress-only policy list
      • Update IPv6 gateway bandwidth limiting policy
      • Update the IPv6 gateway release protection switch
    • NAT Gateway-Related Interfaces
      • Bind DNAT EIP to the NAT gateway
      • Bind SNAT EIP to the NAT gateway
      • Create DNAT rules in batches
      • Create DNAT rules
      • Create NAT gateway
      • Create SNAT rules in batches
      • Create SNAT rules
      • Delete DNAT rules
      • Delete SNAT rules
      • NAT Gateway Binds EIP
      • NAT gateway renewal
      • NAT Gateway Resize
      • NAT Gateway Unbinds EIP
      • Query DNAT rules
      • Query NAT gateway details
      • Query NAT gateway list
      • Query SNAT rules
      • Release NAT gateway
      • Unbind DNAT EIP from the NAT gateway
      • Unbind SNAT EIP from the NAT gateway
      • Update DNAT rules
      • Update NAT Delete Protection Switch
      • Update NAT gateway name
      • Update SNAT rules
    • Network Detection Related Interfaces
      • Create Network Probe
      • Delete network probe
      • Query network probe details
      • Query network probe list.
      • Update probe
    • Parameter Template-Related Interfaces
      • Add IP addresses to the IP address family
      • Add IP addresses to the IP address group
      • Create IP address family
      • Create IP address set
      • Delete IP address family
      • Delete IP address from IP address group
      • Delete IP address set
      • Query IP address family list
      • Query IP address group list
      • Query specified IP address family
      • Query specified IP address group
      • Remove IP address group from IP address family
      • Update IP address family
      • Update IP address set
    • Peering Connections-Related Interfaces
      • Application to process the peering connection
      • Bandwidth resizing for peering connections
      • Create peering connections
      • Disable DNS synchronization for the peering connections.
      • Enable DNS synchronization for the peering connections
      • List of peering connections to be queried.
      • Peering connection renewal
      • Release peering connections
      • Update the local API name and remarks for peering connections
      • Update the peering connection release protection switch
      • View details of peering connection
    • Route Table Related Interfaces
      • Create route rules
      • Delete route rules
      • Primary-standby switch
      • Query route table
      • Query routing rules
      • Update route rules
    • Security Group Related Interfaces
      • Enterprise security group
        • Authorize enterprise security group rules
        • Create enterprise security group
        • Delete enterprise security group rules
        • Delete enterprise security group
        • Query enterprise security group list
        • Update enterprise security group rules
      • Regular security group
        • Authorize regular security group rules
        • Create regular security group
        • Delete regular security group rules
        • Delete regular security group
        • Query regular security group list
        • Revoke regular security group rules
        • Update regular security group rules
        • View security group details
    • Service domain
    • Service Network Interface Card (SNIC)-Related Interfaces
      • Create service network interface card
      • Delete service network interface card
      • Query mountable public services
      • Query service network interface card details
      • Query service network interface card list
      • Update regular security group for service network interface card
      • Update service network interface card with enterprise security group
      • Update the service network interface card
    • Subnet-Related Interfaces
      • Create reserved network segment
      • Create subnet
      • Delete reserved network segment
      • Delete subnet
      • Query specified subnet
      • Query subnet list
      • Query the reserved network segment list
      • Update subnet
    • VPC-Related Interfaces
      • Create VPC
      • Delete VPC
      • Open VPC relay
      • Query IP Usage by Products in VPC
      • Query specified VPC
      • Query VPC intranet IP
      • Query VPC list
      • Shut down VPC relay
      • Update VPC
    • VPN-Related Interfaces
      • Bind EIP
      • Create SSL VPN server
      • Create SSL VPN users in batches
      • Create VPN tunnel
      • Create VPN
      • Delete SSL VPN server
      • Delete SSL VPN user
      • Delete VPN tunnel
      • Query SSL-VPN server
      • Query SSL-VPN user
      • Query VPN details
      • Query VPN List
      • Query VPN tunnels
      • Release VPN
      • Unbind EIP
      • Update SSL VPN server
      • Update SSL VPN user
      • Update VPN release protection switch
      • Update VPN tunnel
      • Update VPN
      • VPN gateway renewal
    • High-Availability Virtual IP Address (HAVIP) Related Interfaces
      • Bind EIP to high-availability virtual IP address
      • Bind instance to high-availability virtual IP address
      • Create high-availability virtual IP address
      • Delete high-availability virtual IP address
      • Query high-availability virtual IP address list
      • Query the specified high-availability virtual IP address
      • Unbind EIP from high-availability virtual IP address
      • Unbind instance from high-availability virtual IP address
      • Update high-availability virtual IP address
  • FAQs
    • Common Questions Overview
    • NAT FAQs
    • Route Table FAQs
    • Service Network Interface Card(SNIC) Common Questions
    • VPC FAQs
    • VPN FAQs
    • Service Network Interface Card (SNIC) Common Questions
  • Function Release Records
  • Operation guide
    • Access control
      • ACL
      • Parameter Template
      • Security group
    • Identity and access management
    • Monitor and Operations
      • NAT Gateway Instance Diagnosis
    • Network Connection
      • Dedicated gateway
      • IPv6 gateway
      • Layer 2 Gateway
      • NAT Gateway
        • Private Network NAT(Network Address Translation) Gateway
        • Public Network NAT(Network Address Translation) Gateway
        • Private Network NAT (Network Address Translation) Gateway
        • Public Network NAT (Network Address Translation) Gateway
      • Peering Connections
      • VPN Gateway
        • GRE VPN Gateway
        • IPsec VPN Gateway
        • SSL VPN Gateway
    • Network Diagnostics
      • Flow log
      • Gateway bandwidth limiting
      • Network probe
      • Path analysis
      • Port verification
      • Traffic monitor
    • Network interface card
      • Elastic network interface
      • High-availability virtual IP address (HAVIP)
      • Service network interface card
    • Network topology
    • Route table
    • Subnet
    • Tag Management
    • Using IPv6
    • VPC
  • Product Description
    • Application scenarios
    • Product advantages
    • Product features
    • Product Introduction
    • Related concepts
    • Usage restrictions
  • Product pricing
  • SDK
    • Go-SDK
      • ACL
      • Dedicated gateway
      • Elastic network interface
      • Exception handling
      • High-availability virtual IP address (HAVIP)
      • Initialization
      • Install the SDK Package
      • IPv6Gateway
      • NAT
      • Network probe
      • Overview
      • Peering Connections
      • Route
      • Security group
        • Enterprise security group
        • Regular security group
      • Service network interface card
      • Subnet
      • VPC
      • VPN
    • Java-SDK
      • ACL
      • Dedicated gateway
      • Elastic network interface
      • Enterprise security group
      • High-availability virtual IP address (HAVIP)
      • Install the SDK Package
      • IPv6 gateway
      • NAT
      • Network probe
      • Overview
      • Parameter Template
      • Peering Connections
      • Regular security group
      • Route
      • Service network interface card
      • Subnet
      • Version history
      • vpc
      • VPN
    • PHP-SDK
      • ACL
      • Install the SDK Package
      • NAT
      • Overview
      • Peering Connections
      • Route
      • Security group
      • Subnet
      • Version history
      • vpc
    • Python-SDK
      • ACL
      • Dedicated gateway
      • Elastic network interface
      • Enterprise security group
      • High-availability virtual IP address (HAVIP)
      • Install the SDK Package
      • IPv6Gateway
      • NAT
      • Network probe
      • Overview
      • Peering Connections
      • Route
      • Security group
      • Service network interface card
      • Subnet
      • Version history
      • VPC
      • VPN
  • Service Level Agreement (SLA)
    • IPv6 Gateway Service Level Agreement SLA
    • NAT(Network Address Translation) Gateway Service Level Agreement SLA
    • Peering Connections Service Level Agreement SLA
    • Service Network Interface Card(SNIC) Service Level Agreement SLA
    • VPN Gateway Service Level Agreement SLA
    • NAT (Network Address Translation) Gateway Service Level Agreement SLA
    • Service Network Interface Card (SNIC) Service Level Agreement SLA
  • Typical Practices
    • Configure Custom Service and Use Service Network Interface Card(SNIC) to Provide Service for Other VPCs
    • HAVIP Combined with Keepalived to Achieve Master-Backup Multi-Machine High Availability
    • Layer 2 Gateway Combined with Dedicated Line Access ET to Build Large Layer 2 Network Between IDC and Cloud VPC
    • Network Layer Security Description
    • Peering Connections Typical Practice
    • Security Group Configuration Practice (Advanced Level)
    • Security Group Configuration Practice (Beginner Level)
    • Typical Practice of Managing Elastic Network Interface Using Terraform
    • Typical Practice of Managing IPsec VPN Gateway Using Terraform
    • Using Keepalived in VPC to Achieve High-Availability Architecture
    • VPC Custom Route Table to Achieve Secure Traffic Mutual Access
    • Windows Using HAVIP to Configure Master-Backup Multi-Machine
    • Configure Custom Service and Use Service Network Interface Card (SNIC) to Provide Service for Other VPCs
  • VPC CLI
    • Configure BCE-CLI
    • Install BCE-CLI
    • Route Table Related Operations
    • Subnet Related Operations
    • Using VPC Service via CLI
    • Version Change Records
    • VPC Related Operations
All documents
menu
No results found, please re-enter

VPC VPC

  • API Reference
    • ACL-Related Interfaces
      • Add ACL rule
      • Delete ACL rules
      • Query ACL rules
      • Query ACL
      • Update ACL rules
    • API function release records
    • API Overview
    • Appendix
    • Common Headers and Error Responses
    • Dedicated Gateway-Related Interfaces
      • Bind physical dedicated line
      • Create dedicated gateway
      • Create health check for dedicated gateway
      • Query dedicated gateway details
      • Query dedicated gateway list
      • Release dedicated gateway
      • Unbind physical dedicated line
      • Update dedicated gateway
    • Elastic Network Interface-Related Interfaces
      • Add intranet IP to elastic network interface in batches
      • Add Secondary IP Address of Elastic Network Interface
      • Create elastic network interface
      • Delete elastic network interface
      • Delete Intranet IP from elastic network interface in batches
      • Delete Secondary IP Address of Elastic Network Interface
      • Elastic network interface binds to EIP
      • Elastic Network Interface Mounts Cloud Product Instance
      • Elastic network interface unbinds from EIP
      • Elastic Network Interface Unmounts Cloud Product Instance
      • Query elastic network interface list
      • Query elastic network interface status
      • Query the specified elastic network interface
      • Update elastic network interface with enterprise security group
      • Update elastic network interface with regular security group
      • Update elastic network interface
    • Gateway Bandwidth Limiting Rule Related Interfaces
      • Create gateway bandwidth limiting rules
      • Delete Gateway Bandwidth Limiting Rule
      • Modify Gateway Bandwidth Limiting Rule
      • View Gateway Bandwidth Limiting Rule
    • General Description
    • High-Availability Virtual IP Address(HAVIP) Related Interfaces
      • Bind EIP to high-availability virtual IP address
      • Bind instance to high-availability virtual IP address
      • Create high-availability virtual IP address
      • Delete high-availability virtual IP address
      • Query high-availability virtual IP address list
      • Query the specified high-availability virtual IP address
      • Unbind EIP from high-availability virtual IP address
      • Unbind instance from high-availability virtual IP address
      • Update high-availability virtual IP address
    • Interface Overview
    • IPv6 Gateway-Related Interfaces
      • Add IPv6 egress-only policy
      • Bandwidth resizing for IPv6 gateway
      • Create IPv6 gateway bandwidth limiting policy
      • Create IPv6 gateway
      • Delete IPv6 gateway bandwidth limiting policy
      • Delete IPv6 Gateway
      • Delete the IPv6 egress-only policy
      • Query IPv6 gateway bandwidth limiting policy list
      • Query IPv6 gateway
      • Query the IPv6 egress-only policy list
      • Update IPv6 gateway bandwidth limiting policy
      • Update the IPv6 gateway release protection switch
    • NAT Gateway-Related Interfaces
      • Bind DNAT EIP to the NAT gateway
      • Bind SNAT EIP to the NAT gateway
      • Create DNAT rules in batches
      • Create DNAT rules
      • Create NAT gateway
      • Create SNAT rules in batches
      • Create SNAT rules
      • Delete DNAT rules
      • Delete SNAT rules
      • NAT Gateway Binds EIP
      • NAT gateway renewal
      • NAT Gateway Resize
      • NAT Gateway Unbinds EIP
      • Query DNAT rules
      • Query NAT gateway details
      • Query NAT gateway list
      • Query SNAT rules
      • Release NAT gateway
      • Unbind DNAT EIP from the NAT gateway
      • Unbind SNAT EIP from the NAT gateway
      • Update DNAT rules
      • Update NAT Delete Protection Switch
      • Update NAT gateway name
      • Update SNAT rules
    • Network Detection Related Interfaces
      • Create Network Probe
      • Delete network probe
      • Query network probe details
      • Query network probe list.
      • Update probe
    • Parameter Template-Related Interfaces
      • Add IP addresses to the IP address family
      • Add IP addresses to the IP address group
      • Create IP address family
      • Create IP address set
      • Delete IP address family
      • Delete IP address from IP address group
      • Delete IP address set
      • Query IP address family list
      • Query IP address group list
      • Query specified IP address family
      • Query specified IP address group
      • Remove IP address group from IP address family
      • Update IP address family
      • Update IP address set
    • Peering Connections-Related Interfaces
      • Application to process the peering connection
      • Bandwidth resizing for peering connections
      • Create peering connections
      • Disable DNS synchronization for the peering connections.
      • Enable DNS synchronization for the peering connections
      • List of peering connections to be queried.
      • Peering connection renewal
      • Release peering connections
      • Update the local API name and remarks for peering connections
      • Update the peering connection release protection switch
      • View details of peering connection
    • Route Table Related Interfaces
      • Create route rules
      • Delete route rules
      • Primary-standby switch
      • Query route table
      • Query routing rules
      • Update route rules
    • Security Group Related Interfaces
      • Enterprise security group
        • Authorize enterprise security group rules
        • Create enterprise security group
        • Delete enterprise security group rules
        • Delete enterprise security group
        • Query enterprise security group list
        • Update enterprise security group rules
      • Regular security group
        • Authorize regular security group rules
        • Create regular security group
        • Delete regular security group rules
        • Delete regular security group
        • Query regular security group list
        • Revoke regular security group rules
        • Update regular security group rules
        • View security group details
    • Service domain
    • Service Network Interface Card (SNIC)-Related Interfaces
      • Create service network interface card
      • Delete service network interface card
      • Query mountable public services
      • Query service network interface card details
      • Query service network interface card list
      • Update regular security group for service network interface card
      • Update service network interface card with enterprise security group
      • Update the service network interface card
    • Subnet-Related Interfaces
      • Create reserved network segment
      • Create subnet
      • Delete reserved network segment
      • Delete subnet
      • Query specified subnet
      • Query subnet list
      • Query the reserved network segment list
      • Update subnet
    • VPC-Related Interfaces
      • Create VPC
      • Delete VPC
      • Open VPC relay
      • Query IP Usage by Products in VPC
      • Query specified VPC
      • Query VPC intranet IP
      • Query VPC list
      • Shut down VPC relay
      • Update VPC
    • VPN-Related Interfaces
      • Bind EIP
      • Create SSL VPN server
      • Create SSL VPN users in batches
      • Create VPN tunnel
      • Create VPN
      • Delete SSL VPN server
      • Delete SSL VPN user
      • Delete VPN tunnel
      • Query SSL-VPN server
      • Query SSL-VPN user
      • Query VPN details
      • Query VPN List
      • Query VPN tunnels
      • Release VPN
      • Unbind EIP
      • Update SSL VPN server
      • Update SSL VPN user
      • Update VPN release protection switch
      • Update VPN tunnel
      • Update VPN
      • VPN gateway renewal
    • High-Availability Virtual IP Address (HAVIP) Related Interfaces
      • Bind EIP to high-availability virtual IP address
      • Bind instance to high-availability virtual IP address
      • Create high-availability virtual IP address
      • Delete high-availability virtual IP address
      • Query high-availability virtual IP address list
      • Query the specified high-availability virtual IP address
      • Unbind EIP from high-availability virtual IP address
      • Unbind instance from high-availability virtual IP address
      • Update high-availability virtual IP address
  • FAQs
    • Common Questions Overview
    • NAT FAQs
    • Route Table FAQs
    • Service Network Interface Card(SNIC) Common Questions
    • VPC FAQs
    • VPN FAQs
    • Service Network Interface Card (SNIC) Common Questions
  • Function Release Records
  • Operation guide
    • Access control
      • ACL
      • Parameter Template
      • Security group
    • Identity and access management
    • Monitor and Operations
      • NAT Gateway Instance Diagnosis
    • Network Connection
      • Dedicated gateway
      • IPv6 gateway
      • Layer 2 Gateway
      • NAT Gateway
        • Private Network NAT(Network Address Translation) Gateway
        • Public Network NAT(Network Address Translation) Gateway
        • Private Network NAT (Network Address Translation) Gateway
        • Public Network NAT (Network Address Translation) Gateway
      • Peering Connections
      • VPN Gateway
        • GRE VPN Gateway
        • IPsec VPN Gateway
        • SSL VPN Gateway
    • Network Diagnostics
      • Flow log
      • Gateway bandwidth limiting
      • Network probe
      • Path analysis
      • Port verification
      • Traffic monitor
    • Network interface card
      • Elastic network interface
      • High-availability virtual IP address (HAVIP)
      • Service network interface card
    • Network topology
    • Route table
    • Subnet
    • Tag Management
    • Using IPv6
    • VPC
  • Product Description
    • Application scenarios
    • Product advantages
    • Product features
    • Product Introduction
    • Related concepts
    • Usage restrictions
  • Product pricing
  • SDK
    • Go-SDK
      • ACL
      • Dedicated gateway
      • Elastic network interface
      • Exception handling
      • High-availability virtual IP address (HAVIP)
      • Initialization
      • Install the SDK Package
      • IPv6Gateway
      • NAT
      • Network probe
      • Overview
      • Peering Connections
      • Route
      • Security group
        • Enterprise security group
        • Regular security group
      • Service network interface card
      • Subnet
      • VPC
      • VPN
    • Java-SDK
      • ACL
      • Dedicated gateway
      • Elastic network interface
      • Enterprise security group
      • High-availability virtual IP address (HAVIP)
      • Install the SDK Package
      • IPv6 gateway
      • NAT
      • Network probe
      • Overview
      • Parameter Template
      • Peering Connections
      • Regular security group
      • Route
      • Service network interface card
      • Subnet
      • Version history
      • vpc
      • VPN
    • PHP-SDK
      • ACL
      • Install the SDK Package
      • NAT
      • Overview
      • Peering Connections
      • Route
      • Security group
      • Subnet
      • Version history
      • vpc
    • Python-SDK
      • ACL
      • Dedicated gateway
      • Elastic network interface
      • Enterprise security group
      • High-availability virtual IP address (HAVIP)
      • Install the SDK Package
      • IPv6Gateway
      • NAT
      • Network probe
      • Overview
      • Peering Connections
      • Route
      • Security group
      • Service network interface card
      • Subnet
      • Version history
      • VPC
      • VPN
  • Service Level Agreement (SLA)
    • IPv6 Gateway Service Level Agreement SLA
    • NAT(Network Address Translation) Gateway Service Level Agreement SLA
    • Peering Connections Service Level Agreement SLA
    • Service Network Interface Card(SNIC) Service Level Agreement SLA
    • VPN Gateway Service Level Agreement SLA
    • NAT (Network Address Translation) Gateway Service Level Agreement SLA
    • Service Network Interface Card (SNIC) Service Level Agreement SLA
  • Typical Practices
    • Configure Custom Service and Use Service Network Interface Card(SNIC) to Provide Service for Other VPCs
    • HAVIP Combined with Keepalived to Achieve Master-Backup Multi-Machine High Availability
    • Layer 2 Gateway Combined with Dedicated Line Access ET to Build Large Layer 2 Network Between IDC and Cloud VPC
    • Network Layer Security Description
    • Peering Connections Typical Practice
    • Security Group Configuration Practice (Advanced Level)
    • Security Group Configuration Practice (Beginner Level)
    • Typical Practice of Managing Elastic Network Interface Using Terraform
    • Typical Practice of Managing IPsec VPN Gateway Using Terraform
    • Using Keepalived in VPC to Achieve High-Availability Architecture
    • VPC Custom Route Table to Achieve Secure Traffic Mutual Access
    • Windows Using HAVIP to Configure Master-Backup Multi-Machine
    • Configure Custom Service and Use Service Network Interface Card (SNIC) to Provide Service for Other VPCs
  • VPC CLI
    • Configure BCE-CLI
    • Install BCE-CLI
    • Route Table Related Operations
    • Subnet Related Operations
    • Using VPC Service via CLI
    • Version Change Records
    • VPC Related Operations
  • Document center
  • arrow
  • VPCVPC
  • arrow
  • SDK
  • arrow
  • Python-SDK
  • arrow
  • Subnet
Table of contents on this page
  • Retrieve Endpoint
  • Retrieve AK/SK
  • Create SubnetClient
  • Create subnet
  • List subnets
  • Query subnet
  • Update subnet
  • Delete subnet
  • Create reserved network segment
  • Function declaration
  • Parameter meaning
  • Response value
  • Code example
  • Query the reserved network segment list
  • Function declaration
  • Parameter meaning
  • Response value
  • Code example
  • Delete reserved network segment
  • Function declaration
  • Parameter meaning
  • Response value
  • Code example

Subnet

Updated at:2025-10-16

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 the subnets of Baidu AI Cloud, you must have a valid AK (Access Key ID) and SK (Secret Access Key) for signature authentication. AK/SK are system-generated strings that verify users and ensure secure access to services. You can obtain and manage your AK/SK using the following steps:

  1. Register a Baidu AI Cloud account
  2. Create AK/SK

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 BCE client configuration-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:

Plain Text
1HOST = b'bcc.bj.baidubce.com'
2AK = b''
3SK = b''
4config = BceClientConfiguration(credentials=BceCredentials(AK, SK), endpoint=HOST)
5self.the_client = subnet_client.SubnetClient(config)

Create subnet

Function declaration

Plain Text
1@required(name=(bytes, str), zone_name=(bytes, str), cidr=(bytes, str), vpc_id=(bytes, str))
2def create_subnet(self, name, zone_name, cidr, vpc_id, subnet_type=None, description=None, client_token=None, config=None)

Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Yjwvyu8o1

Usage example

Plain Text
1subnet_name = 'test_subnet_name'
2subnet_cidr = '192.168.0.64/26'
3vpc_id = 'vpc-51csm6rxs9mg'
4self.the_client.create_subnet(subnet_name, 'cn-bj-a', subnet_cidr, vpc_id))

Response value
Operation succeeded:

Plain Text
1{
2    "subnetId":"sbn-1A09ef6b"
3}   

Operation failed:
Throw an exception. For the exception list, refer to https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7
Code example
For specific code examples, please refer to example_create_subnet.py

List subnets

Function declaration

Plain Text
1@required(marker=(bytes, str),
2          max_Keys=int,
3          vpc_id=(bytes, str),
4          zone_name=(bytes, str),
5          subnet_type=(bytes, str))
6def list_subnets(self, marker=None, max_keys=None, vpc_id=None,
7                 zone_name=None, subnet_type=None, config=None):

Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/xjwvyu8zu

Usage example

Plain Text
1self.the_client.list_subnets()

Response value
Operation succeeded:

Plain Text
1{
2    "nextMarker": "sbn-IyarenI7",
3    "marker": "sbn-IyWRnII7",
4    "maxKeys": 1,
5    "isTruncated": true,
6    "subnets": [
7        {
8 "name": "System predefined subnet",
9        	"subnetId": "sbn-IyWRnII7",
10        	"zoneName": "cn-bj-a",
11        	"cidr": "192.168.0.0/20",
12            "ipv6Cidr": "",
13        	"vpcId": "vpc-IyrqYIQ7",
14        	"subnetType": "BCC",
15        	"description": "",
16            "createdTime": "2020-11-19T12:46:01Z",
17        	"tags": [
18                  {
19                    "tagKey": "aa",
20                    "tagValue": "bb"
21                  }
22              ]
23        }
24    ]
25}

Operation failed:
Throw an exception. For the exception list, refer to https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7
Code example
For specific code examples, please refer to example_list_subnet.py

Query subnet

Function declaration

Plain Text
1@required(subnet_id=(bytes, str))
2def get_subnet(self, subnet_id, config=None):

Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Sjwvyu89a

Usage example

Plain Text
1self.the_client.get_subnet(subnet_id)

Response value
Operation succeeded:

Plain Text
1{     
2    "subnet":     
3        {
4 "name": "System predefined subnet",
5        	"subnetId": "sbn-IyWRnII7",
6        	"zoneName": "cn-bj-a",
7        	"cidr": "192.168.0.0/20",
8            "ipv6Cidr": "",
9        	"vpcId": "vpc-IyrqYIQ7",
10        	"subnetType": "BCC",
11            "availableIp": 4090,
12        	"description": "",
13            "createdTime": "2020-11-19T12:46:01Z"
14        }
15}     

Operation failed:
Throw an exception. For the exception list, refer to https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7
Code example
For specific code examples, please refer to example_get_subnet.py

Update subnet

Function declaration

Plain Text
1@required(subnet_id=(bytes, str),
2          name=(bytes, str),
3          description=(bytes, str))
4def update_subnet(self, subnet_id, name, description=None, client_token=None, config=None):

Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/3jwvyu7wm

Usage example

Plain Text
1self.the_client.update_subnet(subnet_id, 'test_update_name1', 'test_update_description1')

Response value
Operation succeeded:

Plain Text
1{
2}

Operation failed:
Throw an exception. For the exception list, refer to https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7
Code example
For specific code examples, please refer to example_update_subnet.py

Note: Only the name and description fields of the subnet can be updated; the cidr, zone_name, and type fields cannot be modified

Delete subnet

Function declaration

Plain Text
1@required(subnet_id=(bytes, str))
2def delete_subnet(self, subnet_id, client_token=None, config=None):

Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/6jwvyu9b8

Usage example

Plain Text
1self.the_client.delete_subnet(subnet_id)

Response Value
Operation succeeded:

Plain Text
1{
2}

Operation failed:
Throw an exception. For the exception list, refer to https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7
Code example
For specific code examples, please refer to example_delete_subnet.py

Create reserved network segment

Function declaration

Python
1@required(subnet_id=(bytes, str),
2          ip_cidr=(bytes, str),
3          ip_version=int,
4          description=(bytes, str))
5def create_subnet_ipreserve(self, subnet_id, ip_cidr, ip_version, description=None,client_token=None, config=None):

Parameter meaning

Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/xlgyjw2kn

Response value

Operation succeeded:

Plain Text
1{
2  "ipReserveId":"ipr-te2pa9cv4ikk"
3}

Operation failed:

Return error. Refer to the error code list at: https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7

Code example

For specific code examples, please refer to: example_create_subnet_ipreserve.py

Query the reserved network segment list

Function declaration

Python
1@required(subnet_id=(bytes, str),
2          marker=(bytes, str),
3          max_keys=int)
4def list_subnet_ipreserve(self, subnet_id=None, marker=None, max_keys=None, config=None):

Parameter meaning

Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Flgyjya1o

Response value

Operation succeeded:

Plain Text
1{
2   "marker": "",
3   "nextMarker": "ipr-7xp6wvzqpmhd",
4   "maxKeys": 1,
5   "isTruncated": true,
6   "ipReserves":[
7        {
8            "ipReserveId":"ipr-tqsbpf5hcvbp",
9            "subnetId":"sbn-a4cikyt7756r",
10            "ipCidr":"192.168.0.200/30",
11            "ipVersion":"4",
12            "description":"test",
13            "createdTime":"2023-04-27T03:44:38Z",
14            "updatedTime":"2023-04-27T03:45:38Z"
15        }
16    ]
17}

Operation failed: Return error. Refer to the error code list at: https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7

Code example

For specific code examples, please refer to: example_list_subnet_ipreserve.py

Delete reserved network segment

Function declaration

Python
1@required(ip_reserve_id=(bytes, str))
2def delete_subnet_ipreserve(self, ip_reserve_id, lient_token=None, config=None):

Parameter meaning

Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/6lgyjz8jn

Response value

Operation succeeded:

Plain Text
1{}

Operation failed:

Return error. Refer to the error code list at: https://cloud.baidu.com/doc/VPC/s/sjwvyuhe7

Code example

For specific code examples, please refer to: example_delete_subnet_ipreserve.py

Previous
Service network interface card
Next
Version history