复制已有负载均衡器
功能介绍
复制已有的负载均衡器实例。
调用方法
请参见如何调用API。
URI
POST /v3/{project_id}/elb/loadbalancers/{loadbalancer_id}/clone
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
参数解释:项目ID。获取方式请参见获取项目ID。 约束限制:不涉及 取值范围:长度为32个字符,由小写字母和数字组成。 默认取值:不涉及 |
loadbalancer_id |
是 |
String |
负载均衡器ID。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
参数解释:IAM鉴权Token。 约束限制:不涉及 取值范围:不涉及 默认取值:不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
count |
否 |
Integer |
参数解释:单次最大复制数量。 约束限制:不涉及 取值范围:1-10 默认取值:1 |
target_loadbalancer_param |
是 |
TargetLoadbalancerParam object |
参数解释:负载均衡器复制新实例参数对象。 约束限制:不涉及 默认取值:不涉及 默认范围:无 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
name |
否 |
String |
参数解释:新实例名称。 约束限制:不涉及 取值范围:不涉及 默认范围:不传时使用源ELB名称加"-copy-{x}"的后缀作为新实例名称。{x}代表数字序号。 |
availability_zone_list |
否 |
Array of strings |
参数解释:新实例所属可用区。 约束限制:仅支持源ELB独享型复制场景设置该字段。 取值范围:不涉及 默认范围:不传时使用源ELB的availability_zone_list。 |
vip_subnet_cidr_id |
否 |
String |
参数解释:新实例所属子网的ipv4子网ID。 约束限制:所选子网必须与源ELB在同一个vpc内。 取值范围:不涉及 默认范围:不传时使用源ELB的vip_subnet_cidr_id。 |
vip_address |
否 |
String |
参数解释:新实例的ipv4私网地址。 约束限制:仅支持源ELB独享型复制场景、源ELB共享型复制为独享型场景支持设置该字段。 取值范围:不涉及 默认范围:不传时随机分配vip_subnet_cidr_id对应子网的可用IP地址。 |
ipv6_vip_virsubnet_id |
否 |
String |
参数解释:新实例ipv6网络所属的子网网络ID。 约束限制:
取值范围:不涉及 默认范围:不传时使用源ELB的ipv6_vip_virsubnet_id。 |
ipv6_vip_address |
否 |
String |
参数解释:新实例的ipv6地址。 约束限制:仅支持源ELB为独享型复制场景设置该字段。 取值范围:不涉及 默认范围:不传时随机分配ipv6_vip_virsubnet_id对应子网的可用IP地址。 |
elb_virsubnet_ids |
否 |
Array of strings |
参数解释:新实例后端子网的网络ID。 约束限制:
取值范围:不涉及 默认范围:不传时使用源负载均衡器的后端子网。 |
l4_flavor_id |
否 |
String |
参数解释:新实例4层规格。 约束限制:仅支持源ELB独享型复制场景、源ELB共享型复制为独享型场景支持设置该字段。 取值范围:不涉及 默认范围:不传时保持与源负载均衡器的4层规格一致。 |
l7_flavor_id |
否 |
String |
参数解释:新实例7层规格。 约束限制:仅支持源ELB独享型复制场景、源ELB共享型复制为独享型场景支持设置该字段。 取值范围:不涉及 默认范围:不传时保持与源负载均衡器的7层规格一致。 |
enterprise_project_id |
否 |
String |
参数解释:资源所属的企业项目ID。 约束限制:不涉及 取值范围:不涉及 默认取值:不传时保持与源负载均衡器的企业项目一致。 |
reuse_pool |
否 |
Boolean |
参数解释:新实例是否复用源ELB的后端服务器组。 约束限制:
取值范围:
默认范围:false |
guaranteed |
否 |
Boolean |
参数解释:新实例类型。 约束限制:不涉及 取值范围:
默认范围: |
响应参数
状态码:200
参数 |
参数类型 |
描述 |
---|---|---|
loadbalancer_list |
Array of loadbalancer_list objects |
参数解释:新实例信息。 取值范围:不涉及 |
request_id |
String |
参数解释:请求ID。 取值范围:由数字、小写字母和中划线(-)组成的字符串,自动生成。 |
job_id |
String |
参数解释:实例复制任务ID。 取值范围:不涉及 |
请求示例
复制已有负载均衡器实例。
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
}
}
响应示例
状态码:200
操作正常返回。
{
"loadbalancer_list" : [ {
"id" : "00ac869a-16f2-4335-b40a-15f277604f18"
} ],
"request_id" : "53013c36-751b-4687-9819-cc0bb609468c",
"job_id" : "3ccae6c1-615c-48b4-82b5-abfcdcb82849"
}
SDK代码示例
SDK代码示例如下。
复制已有负载均衡器实例。
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());
}
}
}
|
复制已有负载均衡器实例。
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)
|
复制已有负载均衡器实例。
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)
}
}
|
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
复制已有负载均衡器实例。
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());
}
}
}
|
复制已有负载均衡器实例。
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)
|
复制已有负载均衡器实例。
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)
}
}
|
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
操作正常返回。 |
错误码
请参见错误码。