/
spot_request.rb
34 lines (29 loc) · 1013 Bytes
/
spot_request.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module Rudy; module Routines; module Handlers;
module SpotRequest
include Rudy::Routines::Handlers::Base
extend self
def needed?
current_machine_pricing.is_a?(Hash) || current_machine_pricing.to_sym == :spot
end
def create
opts = {
:price => current_machine_pricing[:bid],
:count => current_machine_positions.length,
:size => current_machine_size,
:os => current_machine_os,
:ami => current_machine_image,
:group => current_group_name,
:keypair => root_keypairname
}
request = Rudy::AWS::EC2::SpotRequests.create(opts)
wait_for_fulfillment_of(request)
Rudy::AWS::EC2::SpotRequests.list(request)
end
def wait_for_fulfillment_of(spot_requests)
msg = "Waiting for #{spot_requests.length} spot requests to be fulfilled"
Rudy::Utils.waiter(2, 180, Rudy::Huxtable.logger, msg, 2) {
Rudy::AWS::EC2::SpotRequests.fulfilled?(spot_requests)
}
end
end
end; end; end