package com.yeshi.buwan.job.domain;
|
|
import com.tencentcloudapi.clb.v20180317.ClbClient;
|
import com.tencentcloudapi.clb.v20180317.models.DescribeLoadBalancersRequest;
|
import com.tencentcloudapi.clb.v20180317.models.DescribeLoadBalancersResponse;
|
import com.tencentcloudapi.clb.v20180317.models.LoadBalancer;
|
import com.tencentcloudapi.common.Credential;
|
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
import com.tencentcloudapi.common.profile.ClientProfile;
|
import com.tencentcloudapi.common.profile.HttpProfile;
|
|
/**
|
* @author hxh
|
* @title: TencentCloudSLBUtil
|
* @description: 腾讯云负载均衡
|
* api:https://console.cloud.tencent.com/api/explorer?Product=clb&Version=2018-03-17&Action=DescribeLoadBalancers&SignVersion=
|
* @date 2022/4/16 13:33
|
*/
|
public class TencentCloudCLBUtil {
|
|
private final static String SECRET_ID = "AKIDTlpgJhLjOozvd6QI2XnpfGbgV4NQJk25";
|
private final static String SECRET_KEY = "xhCSUHo55oHUQ6XicFcmfIgspX0EEzWo";
|
|
|
/**
|
* @return com.tencentcloudapi.clb.v20180317.models.LoadBalancer[]
|
* @author hxh
|
* @description 获取负载均衡的列表,IsBlock表示是否封堵
|
* @date 13:44 2022/4/16
|
* @param: name
|
**/
|
public static LoadBalancer[] getCLBList(String name) throws TencentCloudSDKException {
|
// 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
|
// 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
|
Credential cred = new Credential(SECRET_ID, SECRET_KEY);
|
// 实例化一个http选项,可选的,没有特殊需求可以跳过
|
HttpProfile httpProfile = new HttpProfile();
|
httpProfile.setEndpoint("clb.tencentcloudapi.com");
|
// 实例化一个client选项,可选的,没有特殊需求可以跳过
|
ClientProfile clientProfile = new ClientProfile();
|
clientProfile.setHttpProfile(httpProfile);
|
// 实例化要请求产品的client对象,clientProfile是可选的
|
ClbClient client = new ClbClient(cred, "ap-guangzhou", clientProfile);
|
// 实例化一个请求对象,每个接口都会对应一个request对象
|
DescribeLoadBalancersRequest req = new DescribeLoadBalancersRequest();
|
req.setLoadBalancerName(name);
|
// 返回的resp是一个DescribeLoadBalancersResponse的实例,与请求对象对应
|
DescribeLoadBalancersResponse resp = client.DescribeLoadBalancers(req);
|
|
return resp.getLoadBalancerSet();
|
}
|
|
|
public static void main(String[] args) throws TencentCloudSDKException {
|
LoadBalancer[] bs = TencentCloudCLBUtil.getCLBList("布丸-备用");
|
System.out.println(bs);
|
}
|
|
|
}
|