lib/forger/create/info.rb in forger-1.6.0 vs lib/forger/create/info.rb in forger-2.0.0
- old
+ new
@@ -14,25 +14,40 @@
launch_template
end
def spot(instance_id)
+ puts "Max monthly price: $#{monthly_spot_price}/mo" if monthly_spot_price
+
retries = 0
begin
resp = ec2.describe_instances(instance_ids: [instance_id])
rescue Aws::EC2::Errors::InvalidInstanceIDNotFound
retries += 1
puts "Aws::EC2::Errors::InvalidInstanceIDNotFound error. Retry: #{retries}"
sleep 2**retries
- retry if retries <= 3
+ if retries <= 3
+ retry
+ else
+ puts "Unable to find lauched spot instance"
+ return
+ end
end
+
spot_id = resp.reservations.first.instances.first.spot_instance_request_id
return unless spot_id
puts "Spot instance request id: #{spot_id}"
end
+ def monthly_spot_price
+ max_price = @params[:instance_market_options][:spot_options][:max_price].to_f
+ monthly_price = max_price * 24 * 30
+ "%.2f" % monthly_price
+ rescue
+ end
+
def launch_template
launch_template = params[:launch_template]
return unless launch_template
resp = ec2.describe_launch_template_versions(
@@ -51,11 +66,11 @@
puts "Please double check that it exists."
exit
end
def cloudwatch(instance_id)
- return unless @options[:cloudwatch]
+ return unless Forger.cloudwatch_enabled?(@options)
region = cloudwatch_log_region
stream = "#{instance_id}/var/log/cloud-init-output.log"
url = "https://#{region}.console.aws.amazon.com/cloudwatch/home?region=#{region}#logEventViewer:group=ec2;stream=#{stream}"
cw_init_log = "cw tail -f ec2 #{stream}"
@@ -66,10 +81,10 @@
if show_cw && @options[:auto_terminate]
cw_terminate_log = "cw tail -f ec2 #{instance_id}/var/log/auto-terminate.log"
puts " #{cw_terminate_log}"
end
- puts "Note: It takes a little time for the instance to launch and report logs."
+ puts "Note: It takes at least a few minutes for the instance to launch and report logs."
paste_command = show_cw ? cw_init_log : url
add_to_clipboard(paste_command)
end