Class: Cumulus::Common::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/common/manager/Manager.rb

Overview

Public: Base class for AWS resource manager classes.

Classes that extend this class should provide the following methods:

resource_name - return the resource name type (ie "Autoscaling Group", "Security Group", etc)
local_resources - return a Hash of local resource name to local resource config object
aws_resources - return a Hash of aws resource name to aws resource object
diff_resource - a function that will produce an array of differences between the local resource
  passed in and the aws resource passed in
unmanaged_diff - return the correct type of diff from an AWS resource
added_diff - return the correct type of diff from a local configuration object
create - given a local configuration, create the AWS resource
update - given a local configuration and an array of diffs, update the AWS resource

Additionally, the following instance variables can be set to change the behavior of the manager:

create_asset - if true, the asset will be created, if false, a warning will be printed about
  the asset not being created

Instance Method Summary collapse

Constructor Details

#initializeManager

Returns a new instance of Manager.



26
27
28
29
# File 'lib/common/manager/Manager.rb', line 26

def initialize
  @migration_root = "generated"
  @create_asset = true
end

Instance Method Details

#diffObject

Public: Print a diff between local configuration and configuration in AWS



32
33
34
# File 'lib/common/manager/Manager.rb', line 32

def diff
  each_difference(local_resources, true) { |key, diffs| print_difference(key, diffs) }
end

#diff_one(name) ⇒ Object

Public: Print the diff between local configuration and AWS for a single resource

name - the name of the resource to diff



39
40
41
# File 'lib/common/manager/Manager.rb', line 39

def diff_one(name)
  each_difference(filter_local(name), false) { |key, diffs| print_difference(key, diffs) }
end

#filter_local(name) ⇒ Object

Public: Select local resources based on name



61
62
63
# File 'lib/common/manager/Manager.rb', line 61

def filter_local(name)
  local_resources.reject { |key, l| l.name != name }
end

#listObject

Public: Print out the names of all resources managed by Cumulus



44
45
46
# File 'lib/common/manager/Manager.rb', line 44

def list
  puts local_resources.map { |key, l| l.name }.join(" ")
end

#syncObject

Public: Sync local configuration to AWS



49
50
51
# File 'lib/common/manager/Manager.rb', line 49

def sync
  each_difference(local_resources, true) { |key, diffs| sync_difference(key, diffs) }
end

#sync_one(name) ⇒ Object

Public: Sync local configuration to AWS for a single resource

name - the name of the resource to sync



56
57
58
# File 'lib/common/manager/Manager.rb', line 56

def sync_one(name)
  each_difference(filter_local(name), false) { |key, diffs| sync_difference(key, diffs) }
end