ESS伸缩组分为经典网络伸缩组和专有网络伸缩组。当您在创建专有网络伸缩组的时候,需要配置伸缩组对应的交换机。伸缩组创建出来以后,通过当前的伸缩组弹性创建出来的ECS实例都属于该交换机。
ESS伸缩组多可用区参数介绍
原ESS弹性伸缩服务限定,一个专有网络伸缩组只能配置一个交换机。由于一个交换机只归属于一个可用区,这样存在的问题就是,当您配置好ESS伸缩组的交换机以后,如果交换机所在的可用区由于库存不足等原因无法创建出ECS实例,那么您伸缩组中的伸缩配置、伸缩规则以及伸缩组对应的报警任务等都将生效。
为了优化上述问题,提高伸缩组的可用性,ESS伸缩组新增多可用区参数(VSwitchIds.N),您在创建伸缩组的时候可以使用该参数为您的伸缩组配置多个交换机,当一个交换机所在可用区无法创建实例的时候,ESS弹性伸缩服务会为您自动切换到其它可用区。在使用该参数的时候,您需要注意以下几点:
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-ess</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>3.5.0</version>
</dependency>
public class EssSdkDemo {
public static final String REGION_ID = "cn-hangzhou";
public static final String AK = "ak";
public static final String AKS = "aks";
public static final Integer MAX_SIZE = 10;
public static final Integer MIN_SIZE = 1;
public static final String SCALING_GROUP_NAME = "TestScalingGroup";
//交换机列表,交换机优先级从前往后依次降低,第一位的交换机优先级最高。
public static final String[] vswitchIdArray = { "vsw-id1", "vsw-id2", "vsw-id3",
"vsw-id4", "vsw-id5" };
public static final List<String> vswitchIds = Arrays.asList(vswitchIdArray);
public static void main(String[] args) throws Exception {
IClientProfile clientProfile = DefaultProfile.getProfile(REGION_ID, AK, AKS);
IAcsClient client = new DefaultAcsClient(clientProfile);
createScalingGroup(client);
}
/**
* 创建多可用区伸缩组。
* @param client
* @return
* @throws Exception
*/
public static String createScalingGroup(IAcsClient client) throws Exception {
CreateScalingGroupRequest request = new CreateScalingGroupRequest();
request.setRegionId("cn-beijing");
request.setMaxSize(MAX_SIZE);
request.setMinSize(MIN_SIZE);
request.setScalingGroupName(SCALING_GROUP_NAME);
request.setVSwitchIds(vswitchIds);
CreateScalingGroupResponse response = client.getAcsResponse(request);
return response.getScalingGroupId();
}
}
# coding=utf-8
import json
import logging
from aliyunsdkcore import client
from aliyunsdkess.request.v20140828.CreateScalingGroupRequest import CreateScalingGroupRequest
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
datefmt='%a, %d %b %Y %H:%M:%S')
# 请替换自己的ak信息。
ak = 'ak'
aks = 'aks'
scaling_group_name = 'ScalingGroupTest'
max_size = 10
min_size = 1
vswitch_ids = ["vsw-id1", "vsw-id2", "vsw-id3", "vsw-id4", "vsw-id5"]
region_id = 'cn-beijing'
clt = client.AcsClient(ak, aks, region_id)
def _create_scaling_group():
request = CreateScalingGroupRequest()
request.set_ScalingGroupName(scaling_group_name)
request.set_MaxSize(max_size)
request.set_MinSize(min_size)
request.set_VSwitchIds(vswitch_ids)
response = _send_request(request)
return response.get('ScalingGroupId')
def _send_request(request):
request.set_accept_format('json')
try:
response_str = clt.do_action(request)
logging.info(response_str)
response_detail = json.loads(response_str)
return response_detail
except Exception as e:
logging.error(e)
if __name__ == '__main__':
scaling_group_id = _create_scaling_group()
print '创建伸缩组成功,伸缩组ID:' + str(scaling_group_id)
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。