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.



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

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



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

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

#aws_resourcesObject



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

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

#diff_resource(local, aws) ⇒ Object



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

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

#local_resourcesObject



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

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

#migrateObject

Public: Migrate AWS Autoscaling to Cumulus configuration.



23
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
# File 'lib/autoscaling/manager/Manager.rb', line 23

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



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

def resource_name
  "AutoScaling Group"
end

#unmanaged_diff(aws) ⇒ Object



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

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