Class: Cloudshaper::Stack

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

Overview

Wrapper to instantiate a stack from a yaml definition

Defined Under Namespace

Classes: MalformedConfig

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Stack

Returns a new instance of Stack.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cloudshaper/stack.rb', line 22

def initialize(config)
  @name = config.fetch('name')
  @uuid = config.fetch('uuid')
  @remote = config['remote'] || {}
  @description = config['description'] || ''

  @stack_id = "cloudshaper#{@name}_#{@uuid}"
  @stack_dir = File.join(Stacks.dir, @stack_id)

  @module = StackModules.get(config.fetch('root'))
  @variables = config['variables'] || {}
  @variables['cloudshaper_stack_id'] = @stack_id
  @module.build(@variables.map { |k, v| [k.to_sym, v] }.to_h)
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



19
20
21
# File 'lib/cloudshaper/stack.rb', line 19

def description
  @description
end

#moduleObject (readonly)

Returns the value of attribute module.



19
20
21
# File 'lib/cloudshaper/stack.rb', line 19

def module
  @module
end

#nameObject (readonly)

Returns the value of attribute name.



19
20
21
# File 'lib/cloudshaper/stack.rb', line 19

def name
  @name
end

#remoteObject (readonly)

Returns the value of attribute remote.



19
20
21
# File 'lib/cloudshaper/stack.rb', line 19

def remote
  @remote
end

#stack_dirObject (readonly)

Returns the value of attribute stack_dir.



19
20
21
# File 'lib/cloudshaper/stack.rb', line 19

def stack_dir
  @stack_dir
end

#stack_idObject (readonly)

Returns the value of attribute stack_id.



19
20
21
# File 'lib/cloudshaper/stack.rb', line 19

def stack_id
  @stack_id
end

Class Method Details

.load(config) ⇒ Object



11
12
13
14
15
16
# File 'lib/cloudshaper/stack.rb', line 11

def load(config)
  fail MalformedConfig, "Configuration malformed at #{config}" unless config.is_a?(Hash)
  fail MalformedConfig, "A name must be specified for the stack #{config}" unless config.key?('name')
  fail MalformedConfig, 'You must specify a uuid. Get one from rake uuid and add it to the config' unless config.key?('uuid')
  new(config)
end

Instance Method Details

#applyObject



37
38
39
# File 'lib/cloudshaper/stack.rb', line 37

def apply
  Command.new(self, :apply).execute
end

#destroyObject



41
42
43
# File 'lib/cloudshaper/stack.rb', line 41

def destroy
  Command.new(self, :destroy).execute
end

#getObject



49
50
51
# File 'lib/cloudshaper/stack.rb', line 49

def get
  Command.new(self, :get).execute
end

#planObject



45
46
47
# File 'lib/cloudshaper/stack.rb', line 45

def plan
  Command.new(self, :plan).execute
end

#pullObject



57
58
59
# File 'lib/cloudshaper/stack.rb', line 57

def pull
  Remote.new(self, :pull).execute
end

#pushObject



61
62
63
# File 'lib/cloudshaper/stack.rb', line 61

def push
  Remote.new(self, :pull).execute
end

#remote_configObject



65
66
67
# File 'lib/cloudshaper/stack.rb', line 65

def remote_config
  Remote.new(self, :config).execute
end

#showObject



53
54
55
# File 'lib/cloudshaper/stack.rb', line 53

def show
  Command.new(self, :show).execute
end

#to_sObject



69
70
71
72
73
74
75
# File 'lib/cloudshaper/stack.rb', line 69

def to_s
  <<-eos
Name: #{@name}
Description: #{@description}
Stack Directory: #{@stack_dir}
  eos
end