From ddd65843c43131612096981ec48b13b17fbe6a5a Mon Sep 17 00:00:00 2001 From: Javier Ros Date: Thu, 3 Dec 2015 11:07:56 +0000 Subject: [PATCH] issue #4, error splitting RIs --- lib/aws_common.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/aws_common.rb b/lib/aws_common.rb index 6e886b8..d16c446 100644 --- a/lib/aws_common.rb +++ b/lib/aws_common.rb @@ -214,12 +214,25 @@ def apply_recommendation(ri, recommendation) ec2 = Aws::EC2::Client.new(region: region, credentials: role_credentials) end end + conf = {} conf[:availability_zone] = recommendation[:az].nil? ? ri[:az] : recommendation[:az] conf[:platform] = recommendation[:vpc].nil? ? (ri[:vpc] == 'VPC' ? 'EC2-VPC' : 'EC2-Classic') : (recommendation[:vpc] == 'VPC' ? 'EC2-VPC' : 'EC2-Classic') conf[:instance_count] = recommendation[:count] conf[:instance_type] = recommendation[:type].nil? ? ri[:type] : recommendation[:type] - ec2.modify_reserved_instances(reserved_instances_ids:[recommendation[:rid]], target_configurations: [conf]) if ENV['MOCK_DATA'].blank? + all_confs = [conf] + + #TODO Fill in the request with all the instances not modified in the RI + if ri[:count] > recommendation[:count] + rest_conf = {} + rest_conf[:availability_zone] = ri[:az] + rest_conf[:platform] = ri[:vpc] == 'VPC' ? 'EC2-VPC' : 'EC2-Classic' + rest_conf[:instance_count] = ri[:count] - recommendation[:count] + rest_conf[:instance_type] = ri[:type] + all_confs << rest_conf + end + + ec2.modify_reserved_instances(reserved_instances_ids:[recommendation[:rid]], target_configurations: all_confs) if ENV['MOCK_DATA'].blank? log = Recommendation.new log.accountid = ri[:account_id] log.rid = recommendation[:rid]