Class: Cumulus::AutoScaling::Manager

Inherits:
Common::Manager show all
Defined in:
lib/autoscaling/manager/Manager.rb

Overview

Public: The main class for the AutoScaling management module

Instance Method Summary collapse

Methods inherited from Common::Manager

#diff, #diff_one, #filter_local, #list, #sync, #sync_one

Constructor Details

#initializeManager

Public: Constructor. Initializes the AWS client.



17
18
19
20
21
# File 'lib/autoscaling/manager/Manager.rb', line 17

def initialize
  super()
  @aws = Aws::AutoScaling::Client.new(Configuration.instance.client)
  @cloudwatch = Aws::CloudWatch::Client.new(Configuration.instance.client)
end

Instance Method Details

#added_diff(local) ⇒ Object



67
68
69
# File 'lib/autoscaling/manager/Manager.rb', line 67

def added_diff(local)
  AutoScalingDiff.added(local)
end

#aws_resourcesObject



59
60
61
# File 'lib/autoscaling/manager/Manager.rb', line 59

def aws_resources
  @aws_resources ||= AutoScaling::named_groups
end

#diff_resource(local, aws) ⇒ Object



71
72
73
# File 'lib/autoscaling/manager/Manager.rb', line 71

def diff_resource(local, aws)
  local.diff(aws, @aws)
end

#local_resourcesObject



55
56
57
# File 'lib/autoscaling/manager/Manager.rb', line 55

def local_resources
  @local_resources ||= Hash[Loader.groups.map { |local| [local.name, local] }]
end

#migrateObject

Public: Migrate AWS Autoscaling to Cumulus configuration.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/autoscaling/manager/Manager.rb', line 24

def migrate
  groups_dir = "#{@migration_root}/groups"

  if !Dir.exists?(@migration_root)
    Dir.mkdir(@migration_root)
  end
  if !Dir.exists?(groups_dir)
    Dir.mkdir(groups_dir)
  end

  aws_resources.each do |name, resource|
    puts "Processing #{name}..."
    config = GroupConfig.new(resource.auto_scaling_group_name)
    config.populate(resource)
    config.populate_scheduled(@aws.describe_scheduled_actions({
      auto_scaling_group_name: resource.auto_scaling_group_name
    }).scheduled_update_group_actions)
    config.populate_policies(@aws.describe_policies({
      auto_scaling_group_name: resource.auto_scaling_group_name
    }).scaling_policies)

    puts "Writing #{resource.auto_scaling_group_name} configuration to file..."
    File.open("#{groups_dir}/#{config.name}.json", 'w') { |f| f.write(config.pretty_json) }
  end

end

#resource_nameObject



51
52
53
# File 'lib/autoscaling/manager/Manager.rb', line 51

def resource_name
  "AutoScaling Group"
end

#unmanaged_diff(aws) ⇒ Object



63
64
65
# File 'lib/autoscaling/manager/Manager.rb', line 63

def unmanaged_diff(aws)
  AutoScalingDiff.unmanaged(aws)
end