Commit 69d70863 authored by SN150021's avatar SN150021

引入腾讯云 ecs API

parent 4de233c8
...@@ -194,6 +194,12 @@ ...@@ -194,6 +194,12 @@
<artifactId>alibabacloud-ecs20140526</artifactId> <artifactId>alibabacloud-ecs20140526</artifactId>
<version>5.0.13</version> <version>5.0.13</version>
</dependency> </dependency>
<!--腾讯云 云服务器ECS api -->
<dependency>
<groupId>com.tencentcloudapi</groupId>
<artifactId>tencentcloud-sdk-java</artifactId>
<version>3.1.830</version>
</dependency>
</dependencies> </dependencies>
......
...@@ -36,10 +36,6 @@ import org.springframework.stereotype.Service; ...@@ -36,10 +36,6 @@ import org.springframework.stereotype.Service;
@Slf4j @Slf4j
public class AliEcsClient { public class AliEcsClient {
private final CloudPlatformConfigRepository cloudPlatformConfigRepository;
//access_key_id //access_key_id
private static String getAccessKeyId() { private static String getAccessKeyId() {
return "LTAI5tEdz1DY4A4oYUawUuNH"; return "LTAI5tEdz1DY4A4oYUawUuNH";
......
package com.edgec.browserbackend.common.client;
import com.alibaba.fastjson.JSON;
import com.edgec.browserbackend.browser.domain.CloudPlatformConfig;
import com.edgec.browserbackend.common.utils.Aes;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.cvm.v20170312.CvmClient;
import com.tencentcloudapi.cvm.v20170312.models.*;
import darabonba.core.client.ClientOverrideConfiguration;
import java.util.concurrent.CompletableFuture;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* @Description //腾讯云ECS相关api
* @Date 2024/9/2 14:40
* @Author SN150021
**/
@Service
@RequiredArgsConstructor
@Slf4j
public class TenCentEcsClient {
//SecretId
private static String getSecretId() {
return "";
}
//SecretKey
private static String getSecretKey() {
return "";
}
//脚本userData
private static String getUserData() {
return "#!/bin/sh\n"
+ "echo \"users %s:CL:%s\n"
+ "allow %s *\n"
+ "auth strong\n"
+ "proxy -p8880\n"
+ "proxy -p8881 -a\n"
+ "socks -p8882\n"
+ "flush\" | tee /etc/3proxy.cfg\n"
+ "systemctl restart 3proxy";
}
private static CvmClient createClient(String regionId) {
Credential cred = new Credential(getSecretId(), getSecretKey());
// 实例化一个http选项,可选的,没有特殊需求可以跳过
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("cvm.tencentcloudapi.com");
// 实例化一个client选项,可选的,没有特殊需求可以跳过
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
// 实例化要请求产品的client对象,clientProfile是可选的
return new CvmClient(cred, regionId, clientProfile);
}
/**
* 创建并运行实例
*/
public static RunInstancesResponse runInstances(String owner,String username, String password, CloudPlatformConfig config) {
CvmClient cvmClient = createClient(config.getRegionId());
RunInstancesResponse runInstancesResponse = null;
String userData = String.format(getUserData(), username, password, username);
try {
RunInstancesRequest runInstancesRequest = new RunInstancesRequest();
log.info("调用TenCentEcs创建并运行实例,入参:owner:{},regionId:{}", owner, config.getRegionId());
runInstancesResponse = cvmClient.RunInstances(
runInstancesRequest);
log.info("调用TenCentEcs创建并运行实例,响应参数:owner:{},response:{}", owner,
JSON.toJSON(runInstancesResponse));
} catch (Exception e) {
log.error("fail to tenCentEcs runInstances {}", e.getMessage());
}
return runInstancesResponse;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment