Updated on 2025-09-22 GMT+08:00

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

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Definition: Specifies the project ID. For details about how to obtain a project ID, see Obtaining a Project ID.

Constraints: N/A

Range: The value can contain a maximum of 32 characters, including digits and lowercase letters.

Default value: N/A

loadbalancer_id

Yes

String

Definition: Specifies the load balancer ID.

Constraints: N/A

Range: N/A

Default value: N/A

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Definition: Specifies the token used for IAM authentication.

Constraints: N/A

Range: N/A

Default value: N/A

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

count

No

Integer

Definition: Specifies the maximum number of replicas at a time.

Constraints: N/A

Range: 1 to 10

Default value: 1

target_loadbalancer_param

Yes

TargetLoadbalancerParam object

Definition: Specifies the parameters of the new load balancer.

Constraints: N/A

Table 4 TargetLoadbalancerParam

Parameter

Mandatory

Type

Description

name

No

String

Definition: Specifies the name of the new load balancer.

Constraints: N/A

Range: N/A

Default value: If this parameter is not specified, the new load balancer name will be the original load balancer name plus suffix copy-x. x indicates the serial number.

availability_zone_list

No

Array of strings

Definition: Specifies the AZ where new load balancer works.

Constraints: This parameter is available only for copying a dedicated load balancer.

Range: N/A

Default value: If this parameter is not specified, the AZs defined in availability_zone_list of the original load balancer will be used.

vip_subnet_cidr_id

No

String

Definition: Specifies the ID of the IPv4 subnet where the new load balancer works.

Constraints: The subnets where the original and new load balancers work must be in the same VPC.

Range: N/A

Default value: If this parameter is not specified, the IPv4 subnet defined by vip_subnet_cidr_id of the original load balancer is used.

vip_address

No

String

Definition: Specifies the private IPv4 address of the new load balancer.

Constraints: This parameter is available only when you copy a dedicated or shared load balancer as a dedicated load balancer.

Range: N/A

Default value: If this parameter is not specified, a private IPv4 address in the subnet defined by vip_subnet_cidr_id will be randomly assigned to the new load balancer.

ipv6_vip_virsubnet_id

No

String

Definition: Specifies the ID of the IPv6 subnet where the new load balancer works.

Constraints:

  • This parameter is available only for copying a dedicated load balancer.

  • The subnets where the original and new load balancers work must be in the same VPC.

Range: N/A

Default value: If this parameter is not specified, the IPv6 subnet defined by ipv6_vip_virsubnet_id of the original load balancer is used.

ipv6_vip_address

No

String

Definition: Specifies the private IPv6 address of the new load balancer.

Constraints: This parameter is available only for copying a dedicated load balancer.

Range: N/A

Default value: If this parameter is not specified, a private IPv6 address in the subnet defined by ipv6_vip_virsubnet_id will be randomly assigned to the new load balancer.

elb_virsubnet_ids

No

Array of strings

Definition: Specifies the ID of the backend subnet of the new load balancer.

Constraints:

  • This parameter is available only when you copy a dedicated or shared load balancer as a dedicated load balancer.

  • The subnets where the original and new load balancers work must be in the same VPC.

Range: N/A

Default value: If this parameter is not specified, the backend subnet of the original load balancer is used.

l4_flavor_id

No

String

Definition: Specifies the Layer 4 flavor of the new load balancer.

Constraints: This parameter is available only when you copy a dedicated or shared load balancer as a dedicated load balancer.

Range: N/A

Default value: If this parameter is not specified, the Layer 4 flavor of the original load balancer is used.

l7_flavor_id

No

String

Definition: Specifies the Layer 7 flavor of the new load balancer.

Constraints: This parameter is available only when you copy a dedicated or shared load balancer as a dedicated load balancer.

Range: N/A

Default value: If this parameter is not specified, the Layer 7 flavor of the original load balancer is used.

enterprise_project_id

No

String

Definition: Specifies the ID of the enterprise project.

Constraints: N/A

Range: N/A

Default value: If this parameter is not specified, the enterprise project of the original load balancer is used.

reuse_pool

No

Boolean

Definition: Specifies whether to reuse the backend server group of the original load balancer.

Constraints:

  • 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 the ID of another enterprise project.

  • This parameter can be set to true only when you copy a dedicated or shared load balancer as a dedicated load balancer.

Range:

  • false: A new backend server group will be created and associated with the new load balancer.

  • true: The backend server group of the original load balancer will be used.

Default value: false

guaranteed

No

Boolean

Definition: Specifies the type of the new load balancer.

Constraints: N/A

Range:

  • false: A new shared load balancer will be created. The original load balancer must be a shared load balancer.

  • true: A dedicated load balancer will be created. The original load balancer can be a shared or dedicated load balancer.

Default value:

  • true if the original load balancer is a dedicated load balancer.

  • false if the original load balancer is a shared load balancer.

Response Parameters

Status code: 200

Table 5 Response body parameters

Parameter

Type

Description

loadbalancer_list

Array of loadbalancer_list objects

Definition: Specifies the information about the new load balancer.

Range: N/A

request_id

String

Definition: Specifies the request ID.

Range: The value is automatically generated, and can contain characters including digits, lowercase letters, and hyphens (-).

job_id

String

Definition: Specifies the copy task ID.

Range: N/A

Table 6 loadbalancer_list

Parameter

Type

Description

id

String

Definition: Specifies the ID of the new load balancer.

Range: N/A

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.

Status Codes

Status Code

Description

200

Normal response

Error Codes

See Error Codes.