Class: Rivet::Autoscale
- Inherits:
-
Object
- Object
- Rivet::Autoscale
- Defined in:
- lib/rivet/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
-
#initialize(config) ⇒ Autoscale
constructor
A new instance of Autoscale.
- #options ⇒ Object
- #show_differences(level = 'info') ⇒ Object
- #sync ⇒ Object
Constructor Details
#initialize(config) ⇒ Autoscale
Returns a new instance of Autoscale.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rivet/autoscale.rb', line 31 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.
29 30 31 |
# File 'lib/rivet/autoscale.rb', line 29 def name @name end |
Instance Method Details
#differences ⇒ Object
51 52 53 |
# File 'lib/rivet/autoscale.rb', line 51 def differences @differences ||= get_differences end |
#differences? ⇒ Boolean
55 56 57 |
# File 'lib/rivet/autoscale.rb', line 55 def differences? !differences.empty? end |
#options ⇒ Object
47 48 49 |
# File 'lib/rivet/autoscale.rb', line 47 def @options ||= end |
#show_differences(level = 'info') ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/rivet/autoscale.rb', line 59 def show_differences(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) end |
#sync ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/rivet/autoscale.rb', line 69 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? :tags group. end group.update() else Rivet::Log.info "No autoscale differences to sync to AWS for #{@name}." end end |