Authored by qinchao

aws和qcloud伸缩接口

... ... @@ -69,39 +69,6 @@ public class CloudToolController {
return response;
}
/**
* 腾讯云:根据组id获取instanceIP
* 亚马逊云:待定
* @param groupId 伸缩组id
* @return
*/
@RequestMapping("/getIpsByScalingGroupId")
@ResponseBody
public BaseResponse getIpsByScalingGroupId(int cloudType,String groupName ,String groupId){
BaseResponse response = new BaseResponse();
List<String> ipList = null;
if(1==cloudType){
if(groupName==null||groupName.length()<=0){
response.setCode(300);
response.setMessage("aws伸缩组名字为空");
return response;
}
List<CommAutoScalingGroup> autoScalingGroups = awsQueryService.autoScalingConfig(groupName);
if(autoScalingGroups!=null&&autoScalingGroups.get(0)!=null&&autoScalingGroups.get(0).getScalingInstancess()!=null){
ipList=new ArrayList<String>();
for(CommAutoScalingInstances ins:autoScalingGroups.get(0).getScalingInstancess()){
ipList.add(ins.getIp());
}
}
}else if(2==cloudType){
ipList = qCloudToolService.getIpsByScalingGroupId(groupId);
}
response.setData(ipList);
return response;
}
/**
* 腾讯云:根据实例id获取ip相关信息
* 亚马逊云:待定
... ...
... ... @@ -3,6 +3,7 @@ package com.monitor.cmdb.ctrl;
import com.yoho.ops.cmdb.aws.autoscaling.AutoScalingFetcher;
import com.yoho.ops.cmdb.domain.BaseResponse;
import com.yoho.ops.cmdb.models.AutoScalingGroup;
import com.yoho.ops.cmdb.models.AutoScalingHost;
import com.yoho.ops.cmdb.qcloud.autoscaling.QcloudAutoScalingFetcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -12,6 +13,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.ArrayList;
import java.util.List;
/**
... ... @@ -54,5 +56,36 @@ public class AutoScalingCtrl {
return response;
}
/**
* 腾讯云:根据组id获取instanceIP
* 亚马逊云:待定
* @param groupId 伸缩组id
* @return
*/
@RequestMapping("/getIpsByScalingGroupId")
@ResponseBody
public com.monitor.model.response.BaseResponse getIpsByScalingGroupId(int cloudType, String groupName , String groupId){
com.monitor.model.response.BaseResponse response = new com.monitor.model.response.BaseResponse();
List<String> ipList =new ArrayList<String>();;
AutoScalingGroup group=null;
if(1==cloudType){
if(groupName==null||groupName.length()<=0){
response.setCode(300);
response.setMessage("aws伸缩组名字为空");
return response;
}
group=awsFetcher.getAutoScalingByGroupName(groupName);
}else if(2==cloudType){
group=qcloudFetcher.getAutoScalingGroupByScalingGroupId(groupId);
}
if(group!=null&&group.getAutoScalingHosts()!=null){
for(AutoScalingHost host:group.getAutoScalingHosts()){
ipList.add(host.getIp());
}
}
response.setData(ipList);
return response;
}
}
... ...
package com.yoho.ops.cmdb.qcloud.autoscaling;
import com.alibaba.fastjson.JSON;
import com.qcloud.Module.Scaling;
import com.yoho.ops.cmdb.models.AutoScalingGroup;
import com.yoho.ops.cmdb.models.Host;
import com.yoho.ops.cmdb.qcloud.QcloudClientFactory;
import com.yoho.ops.cmdb.qcloud.constant.QcloudConstant;
import com.yoho.ops.cmdb.qcloud.model.QcloudInstanceSet;
import com.yoho.ops.cmdb.qcloud.util.QcloudSdkUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.LinkedList;
import java.util.List;
/**
... ... @@ -29,6 +22,10 @@ public class QcloudAutoScalingFetcher {
return autoScalingGroups;
}
public AutoScalingGroup getAutoScalingGroupByScalingGroupId(String scalingGroupId){
return qcloudClientFactory.getAutoScalingGroupByScalingGroupId(scalingGroupId);
}
public List<Host> getAllInstancesSet(){
return qcloudClientFactory.getAllInstancesSet();
}
... ...