|
|
|
@ -10,6 +10,7 @@ import net.educoder.constant.CommonConstants;
|
|
|
|
|
import net.educoder.exception.BusinessException;
|
|
|
|
|
import net.educoder.model.dto.CreateCloudHostDto;
|
|
|
|
|
import net.educoder.model.param.CreateCloudHostParam;
|
|
|
|
|
import net.educoder.model.param.ResetCloudHostParam;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
@ -218,7 +219,7 @@ public class JCloudUtil {
|
|
|
|
|
* @param serverId
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static boolean rebuildCloud(String token, String serverId) {
|
|
|
|
|
public static boolean rebuildCloud(String token, String serverId, String imageId) {
|
|
|
|
|
String url = "https://home.jcloud.sjtu.edu.cn:8774/v2.1/servers/{server_id}/action".replaceAll("\\{server_id}", serverId);
|
|
|
|
|
/**
|
|
|
|
|
* {
|
|
|
|
@ -229,7 +230,7 @@ public class JCloudUtil {
|
|
|
|
|
* }
|
|
|
|
|
*/
|
|
|
|
|
JSONObject rebuild = new JSONObject();
|
|
|
|
|
rebuild.put("imageRef", "31a54313-bcfe-4c6e-9e19-dcad8360ef56");
|
|
|
|
|
rebuild.put("imageRef", imageId);
|
|
|
|
|
rebuild.put("adminPass", "Educoder123");
|
|
|
|
|
|
|
|
|
|
JSONObject requestBody = new JSONObject();
|
|
|
|
@ -238,7 +239,7 @@ public class JCloudUtil {
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
|
String result = HttpRequest.post(url).header("Content-Type", "application/json").header("X-Auth-Token", token).body(requestBody.toJSONString()).execute().body();
|
|
|
|
|
long end = System.currentTimeMillis();
|
|
|
|
|
log.info("交大云重新构建云主机密码返回结果:{},耗时:{}ms", result, (end - start));
|
|
|
|
|
log.info("交大云重新构建云主机返回结果:{},耗时:{}ms", result, (end - start));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -375,14 +376,14 @@ public class JCloudUtil {
|
|
|
|
|
log.info("开始执行修改云主机:{} 密码", serverId);
|
|
|
|
|
boolean changePwdStatus = changePassword(apiToken, serverId, "Educoder123");
|
|
|
|
|
if (!changePwdStatus) {
|
|
|
|
|
log.error("serverId:{}密码修改失败", serverId);
|
|
|
|
|
log.error("oneStepCreateCloudHost serverId:{}密码修改失败", serverId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return createCloudHostDto;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 一步创建云主机
|
|
|
|
|
* 一步销毁云主机
|
|
|
|
|
*
|
|
|
|
|
* @param apiToken
|
|
|
|
|
*/
|
|
|
|
@ -394,6 +395,38 @@ public class JCloudUtil {
|
|
|
|
|
log.info("删除云主机状态:{},删除浮动ip状态:{}", status1, status2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 一步重新构建云主机
|
|
|
|
|
* @param apiToken
|
|
|
|
|
* @param resetCloudHostParam
|
|
|
|
|
*/
|
|
|
|
|
public static void oneStepRebuildCloudHost(String apiToken, String imageId, ResetCloudHostParam resetCloudHostParam){
|
|
|
|
|
|
|
|
|
|
String serverId = resetCloudHostParam.getServerId();
|
|
|
|
|
boolean status = rebuildCloud(apiToken, serverId, imageId);
|
|
|
|
|
if(status){
|
|
|
|
|
// 轮询查询创建云主机状态
|
|
|
|
|
int number = 60;
|
|
|
|
|
while (!"ACTIVE".equals(getServerStatus(JCloudUtil.getCloudDetail(apiToken, serverId))) && number-- > 0) {
|
|
|
|
|
SleepUtil.sleep(2000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (number <= 0) {
|
|
|
|
|
// 说明云主机重新build失败了
|
|
|
|
|
log.error("serverId:{}云主机重新构建失败", serverId);
|
|
|
|
|
throw new BusinessException("云主机重新构建失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SleepUtil.sleep(30 * 1000);
|
|
|
|
|
log.info("oneStepRebuildCloudHost 开始执行修改云主机:{} 密码", serverId);
|
|
|
|
|
boolean changePwdStatus = changePassword(apiToken, serverId, "Educoder123");
|
|
|
|
|
if (!changePwdStatus) {
|
|
|
|
|
log.error("oneStepRebuildCloudHost serverId:{}密码修改失败", serverId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log.info("rebuild与主机完成serverId:{}", serverId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 默认创建云主机参数
|
|
|
|
@ -464,10 +497,17 @@ public class JCloudUtil {
|
|
|
|
|
// String imageId = "8abf7057-95db-4b57-9a64-8249a4c64680";
|
|
|
|
|
// oneStepCreateCloudHost(apiToken, imageId);
|
|
|
|
|
|
|
|
|
|
String serverId = "532773ed-c022-458e-85f3-f45649b08096";
|
|
|
|
|
String floatingIpId = "8adc22ff-9cbd-447d-bcdc-2c45014f651a";
|
|
|
|
|
oneStepDestroyCloudHost(apiToken, serverId, floatingIpId);
|
|
|
|
|
// String serverId = "532773ed-c022-458e-85f3-f45649b08096";
|
|
|
|
|
// String floatingIpId = "8adc22ff-9cbd-447d-bcdc-2c45014f651a";
|
|
|
|
|
// oneStepDestroyCloudHost(apiToken, serverId, floatingIpId);
|
|
|
|
|
|
|
|
|
|
// ResetCloudHostParam resetCloudHostParam = new ResetCloudHostParam();
|
|
|
|
|
// resetCloudHostParam.setServerId("8cdfc00b-b90a-4e5a-a6ea-1fb558f9fd04");
|
|
|
|
|
|
|
|
|
|
// oneStepRebuildCloudHost(apiToken,"8abf7057-95db-4b57-9a64-8249a4c64680", resetCloudHostParam);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
createCloudHost(apiToken,defaultCreateCloudHostParam("6d3b7f00-0c33-4bad-9a74-ca7d8d7e7b39", "3302992e-0143-4e06-9d11-78abe8881c5f"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|