Class: CloudProviders::ElasticTrigger

Inherits:
Ec2Helper show all
Defined in:
lib/cloud_providers/ec2/helpers/elastic_auto_scaler.rb

Instance Attribute Summary

Attributes inherited from CloudProvider

#init_opts, #name

Instance Method Summary collapse

Methods inherited from Ec2Helper

#as, #ec2, #elb, #initialize, #pool, property, #rds

Methods inherited from CloudProvider

#after_initialized, #bootstrap_nodes!, #default_keypair_path, default_keypair_path, #initialize, #method_missing

Constructor Details

This class inherits a constructor from CloudProviders::Ec2Helper

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CloudProviders::CloudProvider

Instance Method Details

#diff(hsh = {}) ⇒ Object



362
363
364
365
366
367
368
369
370
371
372
373
374
# File 'lib/cloud_providers/ec2/helpers/elastic_auto_scaler.rb', line 362

def diff(hsh={})
  [ :measure_name, 
    :period, 
    :statistic, 
    :lower_threshold, 
    :lower_breach_scale_increment, 
    :upper_threshold, 
    :upper_breach_scale_increment,
    :unit,
    :trigger_name].reject do |k|
    hsh[k].to_s.capitalize == self.send(k).to_s.capitalize
  end
end

#measure_namesObject



333
334
335
# File 'lib/cloud_providers/ec2/helpers/elastic_auto_scaler.rb', line 333

def measure_names
  {:cpu => "CPUUtilization"}
end

#runObject



341
342
343
344
345
346
347
348
349
350
351
352
353
# File 'lib/cloud_providers/ec2/helpers/elastic_auto_scaler.rb', line 341

def run
  if autoscaling_triggers.empty?
    create_autoscaling_trigger!
  else
    t = autoscaling_triggers.map do |hsh|
      diff(hsh)
    end.flatten
    unless t.empty?
      puts "Creating or updating trigger: #{trigger_name}"
      create_autoscaling_trigger!
    end
  end
end

#statistic_namesObject



337
338
339
# File 'lib/cloud_providers/ec2/helpers/elastic_auto_scaler.rb', line 337

def statistic_names
  {:min => "Minimum", :max => "Maximum", :average => "Average", :sum => "Sum"}
end

#teardownObject



355
356
357
358
359
360
# File 'lib/cloud_providers/ec2/helpers/elastic_auto_scaler.rb', line 355

def teardown
  autoscaling_triggers.each do |trigger|
    puts "Deleting trigger: #{trigger[:trigger_name]}"
    as.delete_trigger(:trigger_name => trigger[:trigger_name], :autoscaling_group_name => name)
  end
end