Class: VariationEngine
- Inherits:
-
Object
- Object
- VariationEngine
- Defined in:
- bin/vary_instance_types
Instance Method Summary collapse
-
#initialize(options) ⇒ VariationEngine
constructor
A new instance of VariationEngine.
-
#vary_instance_types ⇒ Object
select different instance types for every server.
Constructor Details
#initialize(options) ⇒ VariationEngine
Returns a new instance of VariationEngine.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'bin/vary_instance_types', line 16 def initialize() @options = @instance_vars32 = { "m1.small" => "0.095", "c1.medium" => "0.19" } @instance_vars64 = { "m1.large" => "0.38", "m1.xlarge" => "0.76", "m2.xlarge" => "0.57", "m2.2xlarge" => "1.34", "m2.4xlarge" => "2.68", "c1.xlarge" => "0.76" } if [:micro_mayhem] @instance_vars32 = { "t1.micro" => "0.02" } @instance_vars64 = { "t1.micro" => "0.02" } end @deployments = Deployment.find_by(:nickname) {|n| n =~ /^#{@options[:tag]}/ } puts "loading #{@deployments.size} deployments matching your tag #{@options[:tag]}" return @deployments end |
Instance Method Details
#vary_instance_types ⇒ Object
select different instance types for every server
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'bin/vary_instance_types', line 30 def vary_instance_types small_counter = 0 large_counter = 0 @deployments.each do |deployment| deployment.servers_no_reload.each do |server| server.reload server.settings server.parameters if server.ec2_instance_type =~ /small/ small_counter += 1 new_type = @instance_vars32.keys[small_counter % @instance_vars32.size] server.instance_type = new_type server.max_spot_price = @instance_vars32[new_type] if @options[:spot] elsif server.ec2_instance_type =~ /large/ large_counter += 1 new_type = @instance_vars64.keys[large_counter % @instance_vars64.size] server.instance_type = new_type server.max_spot_price = @instance_vars64[new_type] if @options[:spot] end server.pricing = "spot" if @options[:spot] server.save end end end |