High-availability virtual IP address (HAVIP)
Get 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 VPC section in the Region Selection Guide. High-availability virtual ip address service is part of the VPC service and adopts the VPC service domain name.
Retrieve AK/SK
To use the Baidu AI Cloud products, you need a Baidu AI Cloud account, a valid AK (Access Key ID) and SK (Secret Access Key) for signature certification. Your AK/SK information can be obtained and understood through the following steps: 1. Register a Baidu AI Cloud account 2. Create AK/SK
Create HaVipClient
When creating a HaVipClient, first configure a HaVipClientConfiguration-type config instance using endpoint, AK and SK, and then use the config instance to configure the HaVipClient. The specific configuration method is as follows:
1ak = b''
2sk = b''
3endpoint = b'bcc.bj.baidubce.com' # Replace with your havip endpoint
4config = BceClientConfiguration(credentials=BceCredentials(access_key_id=ak, secret_access_key=sk),endpoint=endpoint)
5havip_client = havip_client.HavipClient(config)
Create high-availability virtual IP address
Function declaration
1@required(name=(bytes, str),
2 subnet_id=(bytes, str),
3 private_ip_address=(bytes, str),
4 description=(bytes, str))
5def create_havip(self, name, subnet_id, private_ip_address,
6 description="", client_token=None, version=None,
7 config=None):
Parameter meaning
Please refer to the OpenAPI documentation Parameters for Creating High-availability Virtual IP Address
Response value
- Operation succeeded
1{
2 "metadata": For details, refer to the metadata section in the appendix,
3 "haVipId":"havip-w2d4kgc3x0y1"
4}
-
Operation failed
For response exception list of operation failure, refer to the Exception List.
Code example
For specific code examples, refer to example_create_havip.py
Query high-availability virtual IP address list
Function declaration
1@required(vpc_id=(bytes, str))
2def get_havip_detail_list(self, vpc_id=None, config=None):
3 ....
Parameter meaning
Please refer to the OpenAPI documentation: Parameters for Querying High-availability Virtual IP Address List
Response value
- Operation succeeded
1{
2 "haVips":[
3 {
4 "haVipId":"havip-jshdu47sk",
5 "name":"test_havip",
6 "description":"",
7 "vpcId":"vpc-r625rqw3wuer",
8 "subnetId":"sbn-i4d47zb73ztx",
9 "status":"available",
10 "privateIpAddress":"192.168.1.221",
11 "publicIpAddress":"180.76.245.166",
12 "createdTime":"2022-08-31T11:42:19Z"
13 },
14 {
15 "haVipId":"havip-jshdu47sk",
16 "name":"test_havip",
17 "description":"",
18 "vpcId":"vpc-r625rqw3wuer",
19 "subnetId":"sbn-i4d47zb73ztx",
20 "status":"available",
21 "privateIpAddress":"192.168.1.221",
22 "publicIpAddress":"180.76.245.166",
23 "createdTime":"2022-08-31T11:42:19Z"
24 },
25
26 ],
27 is_truncated:False,
28 max_keys:1000,
29 marker:,
30 metadata: For details, refer to the metadata section in the appendix
31}
-
Operation failed
For response exception list of operation failure, refer to the Exception List.
Code example
For specific code examples, refer to example_get_havip_detail_list.py
Query the specified high-availability virtual IP address
Function declaration
1@required(havip_id=(bytes, str))
2def get_havip_detail(self, havip_id, config=None):
3 .....
Parameter meaning
Please refer to the OpenAPI documentation: Parameters for Querying Specified High-availability Virtual IP Address
Response value
- Operation succeeded
1{
2 "haVipId": "havip-jshdu47sk",
3 "name": "test_havip",
4 "description": "",
5 "vpcId": "vpc-r625rqw3wuer",
6 "subnetId": "sbn-i4d47zb73ztx",
7 "status": "available",
8 "privateIpAddress": "192.168.1.221",
9 "publicIpAddress": "180.76.245.166",
10 "createdTime": "2022-08-31T11:42:19Z",
11 "bindedInstances": [
12 {
13 "instanceId": "eni-w2kmnu1peqxg",
14 "instanceType": "ENI",
15 "master": true
16 },
17 {
18 "instanceId": "eni-7c9yzhkfn9c2",
19 "instanceType": "ENI",
20 "master": false
21 }
22 ],
23 "metadata": For details, refer to the metadata section in the appendix
24}
-
Operation failed
For response exception list of operation failure, refer to the Exception List.
Code example
For specific code examples, refer to example_get_havip_detail.py
Delete high-availability virtual IP address
Function declaration
1@required(havip_id=(bytes, str))
2def delete_havip(self, havip_id, client_token=None, config=None):
3 ......
Parameter meaning
Please refer to the OpenAPI documentation: Parameters for Deleting High-availability Virtual IP Address
Response value
-
Operation succeeded
No response value
-
Operation failed
For response exception list of operation failure, refer to the Exception List.
Code example
For specific code examples, refer to example_delete_havip.py
Update high-availability virtual IP address
Function declaration
1@required(name=(bytes, str),
2 havip_id=(bytes, str),
3 description=(bytes, str))
4def update_havip(self, name, havip_id, description="", version=None,
5 client_token=None,
6 config=None):
7 .....
Parameter meaning
Please refer to the OpenAPI documentation Parameters for Updating High-availability Virtual IP Address
Response value
-
Operation succeeded
No response value
-
Operation failed
For response exception list of operation failure, refer to the Exception List.
Code example
For specific code examples, refer to example_update_havip.py
Bind instance to high-availability virtual IP address
Function declaration
1@required(instance_ids=[(bytes, str)],
2 instance_type=(bytes, str),
3 havip_id=(bytes, str))
4def havip_attach_instance(self, instance_ids, instance_type, havip_id, client_token=None, config=None):
5 ......
Parameter meaning
Refer to OpenAPI documentation: Parameters for Binding Instance for High-availability Virtual IP Address
Response value
-
Operation succeeded
No response value
-
Operation failed
For response exception list of operation failure, refer to the Exception List.
Code example
For specific code examples, refer to example_havip_attach_instance.py
Unbind instance from high-availability virtual IP address
Function declaration
1@required(instance_ids=[(bytes, str)],
2 instance_type=(bytes, str),
3 havip_id=(bytes, str))
4def havip_detach_instance(self, instance_ids, instance_type, havip_id, client_token=None, config=None):
5 ....
Parameter meaning
Refer to OpenAPI documentation: Parameters for Unbinding Instance from High-availability Virtual IP Address
Response value
-
Operation succeeded
No response value
-
Operation failed
For response exception list of operation failure, refer to the Exception List.
Code example
For specific code examples, refer to example_havip_detach_instance.py
Bind EIP to high-availability virtual IP address
1@required(havip_id=(bytes, str),
2 public_ip_address=(bytes, str))
3def havip_bind_public_ip(self, havip_id, public_ip_address, version=None,
4 client_token=None, config=None):
5 ......
Parameter meaning
Refer to OpenAPI documentation: Parameters for Binding EIP to High-availability Virtual IP Address
Response value
-
Operation succeeded
No response value
-
Operation failed
For response exception list of operation failure, refer to the Exception List.
Code example
For specific code examples, refer to example_havip_bind_public_ip.py
Unbind EIP from high-availability virtual IP address
Function declaration
1@required(havip_id=(bytes, str))
2def havip_unbind_public_ip(self, havip_id, version=None,
3 client_token=None, config=None):
4 ......
Parameter meaning
Refer to OpenAPI documentation: Parameters for Unbinding EIP from High-availability Virtual IP Address
Response value
-
Operation succeeded
No response value
-
Operation failed
For response exception list of operation failure, refer to the Exception List.
Code example
For specific code examples, refer to example_havip_unbind_public_ip.py
