lib/kitchen/driver/ec2.rb in kitchen-ec2-1.0.0.beta.1 vs lib/kitchen/driver/ec2.rb in kitchen-ec2-1.0.0

- old
+ new

@@ -60,11 +60,12 @@ driver.default_windows_user_data end end default_config :private_ip_address, nil default_config :iam_profile_name, nil - default_config :price, nil + default_config :spot_price, nil + default_config :block_duration_minutes, nil default_config :retryable_tries, 60 default_config :retryable_sleep, 5 default_config :aws_access_key_id, nil default_config :aws_secret_access_key, nil default_config :aws_session_token, nil @@ -159,11 +160,11 @@ free-tier, you may be charged to run these suites. The charge should be minimal, but neither Test Kitchen nor its maintainers are responsible for your incurred costs. END - if config[:price] + if config[:spot_price] # Spot instance when a price is set server = submit_spot(state) else # On-demand instance server = submit_server @@ -318,16 +319,12 @@ ec2.create_instance(instance_data) end def submit_spot(state) # rubocop:disable Metrics/AbcSize debug("Creating EC2 Spot Instance..") - request_data = {} - request_data[:spot_price] = config[:price].to_s - request_data[:launch_specification] = instance_generator.ec2_instance_data - response = ec2.client.request_spot_instances(request_data) - spot_request_id = response[:spot_instance_requests][0][:spot_instance_request_id] + spot_request_id = create_spot_request # deleting the instance cancels the request, but deleting the request # does not affect the instance state[:spot_request_id] = spot_request_id ec2.client.wait_until( :spot_instance_request_fulfilled, @@ -342,10 +339,23 @@ end end ec2.get_instance_from_spot_request(spot_request_id) end + def create_spot_request + request_data = { + :spot_price => config[:spot_price].to_s, + :launch_specification => instance_generator.ec2_instance_data + } + if config[:block_duration_minutes] + request_data[:block_duration_minutes] = config[:block_duration_minutes] + end + + response = ec2.client.request_spot_instances(request_data) + response[:spot_instance_requests][0][:spot_instance_request_id] + end + def tag_server(server) tags = [] config[:tags].each do |k, v| tags << { :key => k, :value => v } end @@ -420,10 +430,11 @@ # INTERFACE_TYPES = { "dns" => "public_dns_name", "public" => "public_ip_address", - "private" => "private_ip_address" + "private" => "private_ip_address", + "private_dns" => "private_dns_name" } # # Lookup hostname of provided server. If interface_type is provided use # that interface to lookup hostname. Otherwise, try ordered list of