Class: Cloudshaper::Stacks

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudshaper/stacks.rb

Overview

Singleton to keep track of stack templates

Defined Under Namespace

Classes: MalformedConfig

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.stacksObject (readonly)

Returns the value of attribute stacks.



11
12
13
# File 'lib/cloudshaper/stacks.rb', line 11

def stacks
  @stacks
end

Class Method Details

.base_configObject



33
34
35
36
37
38
# File 'lib/cloudshaper/stacks.rb', line 33

def base_config
  {
    'common' => {},
    'stacks' => [base_stack_config]
  }
end

.base_stack_configObject



40
41
42
43
44
45
46
47
48
# File 'lib/cloudshaper/stacks.rb', line 40

def base_stack_config
  {
    'name' => 'SET_NAME',
    'uuid' => SecureRandom.uuid,
    'description' => 'SET_A_DESCRIPTION',
    'root' => 'SET_A_TEMPLATE',
    'variables' => {}
  }
end

.dirObject



54
55
56
# File 'lib/cloudshaper/stacks.rb', line 54

def dir
  File.expand_path(File.join(ENV['TERRAFORM_DATA_DIR'] || 'data', 'stacks'))
end

.initObject



25
26
27
28
29
30
31
# File 'lib/cloudshaper/stacks.rb', line 25

def init
  config = ENV['STACK_CONFIG'] || 'stacks.yml'
  fail "stacks.yaml already exists at #{File.expand_path(config)}" if File.exist?(config)
  File.open(config, 'w') do |f|
    f.write(YAML.dump(base_config))
  end
end

.loadObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cloudshaper/stacks.rb', line 13

def load
  config = ENV['STACK_CONFIG'] || 'stacks.yml'
  fail 'stacks.yml must exist in root directory, or specify STACK_CONFIG pointing to stacks.yml' unless File.exist?(config)
  stack_specs = YAML.load(File.read(config))
  fail MalformedConfig, 'Stacks must be an array' unless stack_specs.key?('stacks') && stack_specs['stacks'].is_a?(Array)
  common = stack_specs['common'] || {}
  stack_specs['stacks'].each do |stack_spec|
    stack = Stack.load(stack_spec.merge(common))
    @stacks[stack.name] = stack
  end
end

.reset!Object



50
51
52
# File 'lib/cloudshaper/stacks.rb', line 50

def reset!
  @stacks ||= {}
end