Permalink
Browse files

Add SpotRequest routine handlers.

  • Loading branch information...
1 parent 86c2202 commit 78955b99714ec84eaff2039363998968b87b2ba7 @Fluxx Fluxx committed May 30, 2011
Showing with 47 additions and 0 deletions.
  1. +12 −0 lib/rudy/huxtable.rb
  2. +1 −0 lib/rudy/routines.rb
  3. +34 −0 lib/rudy/routines/handlers/spot_request.rb
View
12 lib/rudy/huxtable.rb
@@ -178,6 +178,14 @@ def current_machine_count
fetch_machine_param(:positions) || 1
end
+ def current_machine_positions
+ if @@global.position
+ Array(@@global.position)
+ else
+ Array.new(current_machine_count.to_i || 1) { |i| i + 1 }
+ end
+ end
+
def current_machine_hostname
# NOTE: There is an issue with Caesars that a keyword that has been
# defined as forced_array (or forced_hash, etc...) is like that for
@@ -203,6 +211,10 @@ def current_machine_size
fetch_machine_param(:size) || 'm1.small'
end
+ def current_machine_pricing
+ fetch_machine_param(:pricing) || fetch_machine_param(:spot) || :on_demand
+ end
+
def current_machine_address(position='01')
#raise NoConfig unless @@config
#raise NoMachinesConfig unless @@config.machines
View
1 lib/rudy/routines.rb
@@ -150,6 +150,7 @@ module Handlers
autoload :Keypair, 'rudy/routines/handlers/keypair'
autoload :Machines, 'rudy/routines/handlers/machines'
autoload :RyeTools, 'rudy/routines/handlers/rye'
+ autoload :SpotRequest, 'rudy/routines/handlers/spot_request'
# The following can't be autoloaded because they call
# Rudy::Routines.add_handler when they're loaded.
require 'rudy/routines/handlers/depends'
View
34 lib/rudy/routines/handlers/spot_request.rb
@@ -0,0 +1,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
+ }
+
+ Rudy::AWS::EC2::SpotRequests.create(opts).tap do |request|
+ wait_for_fulfillment_of(request)
+ end
+ end
+
+ def wait_for_fulfillment_of(spot_requests)
+ msg = "Waiting for #{spot_requests.length} spot requests to be fulfilled"
+ Rudy::Utils.waiter(2, 90, Rudy::Huxtable.logger, msg, 2) {
+ Rudy::AWS::EC2::SpotRequests.fulfilled?(spot_requests)
+ }
+ end
+
+ end
+end; end; end

0 comments on commit 78955b9

Please sign in to comment.