Copying a Load Balancer
Function
This API is used to copy a load balancer.
Calling Method
For details, see Calling APIs.
URI
POST /v3/{project_id}/elb/loadbalancers/{loadbalancer_id}/clone
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Specifies the ID of the project where the load balancer is used. |
loadbalancer_id |
Yes |
String |
Specifies the load balancer ID. |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
X-Auth-Token |
Yes |
String |
Specifies the token used for IAM authentication. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
count |
No |
Integer |
Specifies the maximum number of replicas at a time. Value range: 1 to 10 Default value: 1 |
target_loadbalancer_param |
Yes |
TargetLoadbalancerParam object |
Specifies the parameters for the new load balancer. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
name |
No |
String |
(Optional) Specifies the new load balancer name. If this parameter is not specified, the new load balancer name will be the original load balancer name plus suffix copy-x. |
availability_zone_list |
No |
Array of strings |
(Optional) Specifies the AZ where new load balancer works. If this parameter is not specified, the AZ of the original load balancer is used. This parameter is available only for copying a dedicated load balancer. |
vip_subnet_cidr_id |
No |
String |
(Optional) Specifies the ID of the IPv4 subnet where the new load balancer works. If this parameter is not specified, the IPv4 subnet of the original load balancer is used. The subnets where the original and new load balancers work must be in the same VPC. |
vip_address |
No |
String |
(Optional) Specifies the private IPv4 address of the new load balancer. If this parameter is not specified, a private IPv4 address will be randomly assigned to the new load balancer. This parameter is available only when you copy a dedicated or shared load balancer as a dedicated load balancer. |
ipv6_vip_virsubnet_id |
No |
String |
(Optional) Specifies the ID of the IPv6 subnet where the new load balancer works. If this parameter is not specified, the IPv6 subnet of the original load balancer is used. The subnets where the original and new load balancers work must be in the same VPC. This parameter is available only for copying a dedicated load balancer. |
ipv6_vip_address |
No |
String |
(Optional) Specifies the private IPv6 address of the new load balancer. If this parameter is not specified, a private IPv6 address will be randomly assigned to the new load balancer. This parameter is available only for copying a dedicated load balancer. |
elb_virsubnet_ids |
No |
Array of strings |
(Optional) Specifies the ID of the backend subnet of the new load balancer. If this parameter is not specified, the backend subnet of the original load balancer is used. The subnets where the original and new load balancers work must be in the same VPC. This parameter is available only when you copy a dedicated or shared load balancer as a dedicated load balancer. |
l4_flavor_id |
No |
String |
(Optional) Specifies the Layer 4 specifications of the new load balancer. If this parameter is not specified, the Layer 4 specifications of the original load balancer are used. This parameter is available only when you copy a dedicated or shared load balancer as a dedicated load balancer. |
l7_flavor_id |
No |
String |
(Optional) Specifies the Layer 7 specifications of the new load balancer. If this parameter is not specified, the Layer 7 specifications of the original load balancer are used. This parameter is available only when you copy a dedicated or shared load balancer as a dedicated load balancer. |
enterprise_project_id |
No |
String |
(Optional) Specifies the enterprise project where the new load balancer is used. If this parameter is not specified, the enterprise project of the original load balancer is used. |
reuse_pool |
No |
Boolean |
(Optional) Specifies whether to reuse the backend server group and backend server ID of the original load balancer. If this parameter is set to true, the backend server group of the original load balancer will be used. If no backend server group is selected, a new backend server group is created by default. This parameter is invalid when enterprise_project_id is set to another enterprise project. This parameter is available only when you copy a dedicated or shared load balancer as a dedicated load balancer. |
guaranteed |
No |
Boolean |
(Optional) Specifies the type of the new load balancer. When a dedicated load balancer is copied, the default value is true. If the value is explicitly specified, it can only be set to true. When a shared load balancer is copied, the default value is false. If the value is explicitly set to false, the new load balancer is a shared load balancer. If the value is explicitly set to true, the new load balancer is a dedicated load balancer. |
Response Parameters
Status code: 200
Parameter |
Type |
Description |
---|---|---|
loadbalancer_list |
Array of loadbalancer_list objects |
Specifies the information about the new load balancer. |
request_id |
String |
Specifies the request ID. |
job_id |
String |
Specifies the copy task ID. |
Example Requests
Copying a load balancer
POST https://{ELB_Endpoint}/v3/{project_id}/elb/loadbalancers/{loadbalancer_id}/clone { "target_loadbalancer_param" : { "availability_zone_list" : [ "az1", "az2" ], "vip_address" : "1.1.1.1", "guaranteed" : true } }
Example Responses
Status code: 200
Normal response
{ "loadbalancer_list" : [ { "id" : "00ac869a-16f2-4335-b40a-15f277604f18" } ], "request_id" : "53013c36-751b-4687-9819-cc0bb609468c", "job_id" : "3ccae6c1-615c-48b4-82b5-abfcdcb82849" }
SDK Sample Code
The SDK sample code is as follows.
Copying a load balancer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.elb.v3.region.ElbRegion; import com.huaweicloud.sdk.elb.v3.*; import com.huaweicloud.sdk.elb.v3.model.*; import java.util.List; import java.util.ArrayList; public class CloneLoadbalancerSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); ElbClient client = ElbClient.newBuilder() .withCredential(auth) .withRegion(ElbRegion.valueOf("<YOUR REGION>")) .build(); CloneLoadbalancerRequest request = new CloneLoadbalancerRequest(); request.withLoadbalancerId("{loadbalancer_id}"); CloneLoadbalancerRequestBody body = new CloneLoadbalancerRequestBody(); List<String> listTargetLoadbalancerParamAvailabilityZoneList = new ArrayList<>(); listTargetLoadbalancerParamAvailabilityZoneList.add("az1"); listTargetLoadbalancerParamAvailabilityZoneList.add("az2"); TargetLoadbalancerParam targetLoadbalancerParambody = new TargetLoadbalancerParam(); targetLoadbalancerParambody.withAvailabilityZoneList(listTargetLoadbalancerParamAvailabilityZoneList) .withVipAddress("1.1.1.1") .withGuaranteed(true); body.withTargetLoadbalancerParam(targetLoadbalancerParambody); request.withBody(body); try { CloneLoadbalancerResponse response = client.cloneLoadbalancer(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } |
Copying a load balancer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkelb.v3.region.elb_region import ElbRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkelb.v3 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = ElbClient.new_builder() \ .with_credentials(credentials) \ .with_region(ElbRegion.value_of("<YOUR REGION>")) \ .build() try: request = CloneLoadbalancerRequest() request.loadbalancer_id = "{loadbalancer_id}" listAvailabilityZoneListTargetLoadbalancerParam = [ "az1", "az2" ] targetLoadbalancerParambody = TargetLoadbalancerParam( availability_zone_list=listAvailabilityZoneListTargetLoadbalancerParam, vip_address="1.1.1.1", guaranteed=True ) request.body = CloneLoadbalancerRequestBody( target_loadbalancer_param=targetLoadbalancerParambody ) response = client.clone_loadbalancer(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
Copying a load balancer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" elb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := elb.NewElbClient( elb.ElbClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CloneLoadbalancerRequest{} request.LoadbalancerId = "{loadbalancer_id}" var listAvailabilityZoneListTargetLoadbalancerParam = []string{ "az1", "az2", } vipAddressTargetLoadbalancerParam:= "1.1.1.1" guaranteedTargetLoadbalancerParam:= true targetLoadbalancerParambody := &model.TargetLoadbalancerParam{ AvailabilityZoneList: &listAvailabilityZoneListTargetLoadbalancerParam, VipAddress: &vipAddressTargetLoadbalancerParam, Guaranteed: &guaranteedTargetLoadbalancerParam, } request.Body = &model.CloneLoadbalancerRequestBody{ TargetLoadbalancerParam: targetLoadbalancerParambody, } response, err := client.CloneLoadbalancer(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
Copying a load balancer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.elb.v3.region.ElbRegion; import com.huaweicloud.sdk.elb.v3.*; import com.huaweicloud.sdk.elb.v3.model.*; import java.util.List; import java.util.ArrayList; public class CloneLoadbalancerSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); ElbClient client = ElbClient.newBuilder() .withCredential(auth) .withRegion(ElbRegion.valueOf("<YOUR REGION>")) .build(); CloneLoadbalancerRequest request = new CloneLoadbalancerRequest(); request.withLoadbalancerId("{loadbalancer_id}"); CloneLoadbalancerRequestBody body = new CloneLoadbalancerRequestBody(); List<String> listTargetLoadbalancerParamAvailabilityZoneList = new ArrayList<>(); listTargetLoadbalancerParamAvailabilityZoneList.add("az1"); listTargetLoadbalancerParamAvailabilityZoneList.add("az2"); TargetLoadbalancerParam targetLoadbalancerParambody = new TargetLoadbalancerParam(); targetLoadbalancerParambody.withAvailabilityZoneList(listTargetLoadbalancerParamAvailabilityZoneList) .withVipAddress("1.1.1.1") .withGuaranteed(true); body.withTargetLoadbalancerParam(targetLoadbalancerParambody); request.withBody(body); try { CloneLoadbalancerResponse response = client.cloneLoadbalancer(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } |
Copying a load balancer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkelb.v3.region.elb_region import ElbRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkelb.v3 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = ElbClient.new_builder() \ .with_credentials(credentials) \ .with_region(ElbRegion.value_of("<YOUR REGION>")) \ .build() try: request = CloneLoadbalancerRequest() request.loadbalancer_id = "{loadbalancer_id}" listAvailabilityZoneListTargetLoadbalancerParam = [ "az1", "az2" ] targetLoadbalancerParambody = TargetLoadbalancerParam( availability_zone_list=listAvailabilityZoneListTargetLoadbalancerParam, vip_address="1.1.1.1", guaranteed=True ) request.body = CloneLoadbalancerRequestBody( target_loadbalancer_param=targetLoadbalancerParambody ) response = client.clone_loadbalancer(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
Copying a load balancer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" elb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := elb.NewElbClient( elb.ElbClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CloneLoadbalancerRequest{} request.LoadbalancerId = "{loadbalancer_id}" var listAvailabilityZoneListTargetLoadbalancerParam = []string{ "az1", "az2", } vipAddressTargetLoadbalancerParam:= "1.1.1.1" guaranteedTargetLoadbalancerParam:= true targetLoadbalancerParambody := &model.TargetLoadbalancerParam{ AvailabilityZoneList: &listAvailabilityZoneListTargetLoadbalancerParam, VipAddress: &vipAddressTargetLoadbalancerParam, Guaranteed: &guaranteedTargetLoadbalancerParam, } request.Body = &model.CloneLoadbalancerRequestBody{ TargetLoadbalancerParam: targetLoadbalancerParambody, } response, err := client.CloneLoadbalancer(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
Status Codes
Status Code |
Description |
---|---|
200 |
Normal response |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot