Class: Rivet::Autoscale
- Inherits:
-
Object
- Object
- Rivet::Autoscale
- Defined in:
- lib/rivet/as/autoscale.rb
Constant Summary collapse
- OPTIONS =
[ :availability_zones, :default_cooldown, :desired_capacity, :health_check_grace_period, :health_check_type, :launch_configuration, :load_balancers, :max_size, :min_size, :placement_group, :subnets, :tags, :termination_policies ].each { |a| attr_reader a }
- REQUIRED_OPTIONS =
[ :availability_zones, :launch_configuration, :max_size, :min_size ]
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #differences ⇒ Object
- #differences? ⇒ Boolean
- #display(level = 'info') ⇒ Object
- #display_lc_diff ⇒ Object
-
#initialize(config) ⇒ Autoscale
constructor
A new instance of Autoscale.
- #options ⇒ Object
- #sync ⇒ Object
Constructor Details
#initialize(config) ⇒ Autoscale
Returns a new instance of Autoscale.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rivet/as/autoscale.rb', line 32 def initialize(config) @name = config.name @remote_group = AwsAutoscaleWrapper.new(@name) @launch_config = LaunchConfig.new(config) OPTIONS.each do |o| if config.respond_to?(o) instance_variable_set("@#{o}", config.send(o)) end end # The launch_configuration attr exists because that is what # the aws SDK refers to the launch configuration name as. @launch_configuration = @launch_config.identity end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
30 31 32 |
# File 'lib/rivet/as/autoscale.rb', line 30 def name @name end |
Instance Method Details
#differences ⇒ Object
52 53 54 |
# File 'lib/rivet/as/autoscale.rb', line 52 def differences @differences ||= get_differences end |
#differences? ⇒ Boolean
56 57 58 |
# File 'lib/rivet/as/autoscale.rb', line 56 def differences? !differences.empty? end |
#display(level = 'info') ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rivet/as/autoscale.rb', line 60 def display(level = 'info') Rivet::Log.write(level, 'Remote and local match') unless differences? differences.each_pair do |attr, values| Rivet::Log.write(level, "#{attr}:") Rivet::Log.write(level, " remote: #{values[:remote]}") Rivet::Log.write(level, " local: #{values[:local]}") end Rivet::Log.write('debug', @launch_config.user_data) display_lc_diff end |
#display_lc_diff ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rivet/as/autoscale.rb', line 71 def display_lc_diff @lc_diff ||= get_lc_diff Rivet::Log.info"Displaying diff for launch configuration:" @lc_diff.each do |d| d.each do |current| Rivet::Log.info " #{current.action} #{current.element.join}" end end end |
#options ⇒ Object
48 49 50 |
# File 'lib/rivet/as/autoscale.rb', line 48 def ||= end |
#sync ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/rivet/as/autoscale.rb', line 82 def sync if differences? Rivet::Log.info "Syncing autoscale group changes to AWS for #{@name}" autoscale = AWS::AutoScaling.new group = autoscale.groups[@name] @launch_config.save create() unless group.exists? Rivet::Log.debug 'Updating autoscaling group with the follow options' Rivet::Log.debug .inspect # It's easier to just delete all the tags if there are changes and apply # new ones, than ferret out exactly which ones should be removed. if differences.has_key? : group. end group.update() else Rivet::Log.info "No autoscale differences to sync to AWS for #{@name}." end end |