Class: SimpleDeploy::Stack

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_deploy/stack.rb,
lib/simple_deploy/stack/ssh.rb,
lib/simple_deploy/stack/execute.rb,
lib/simple_deploy/stack/deployment.rb,
lib/simple_deploy/stack/output_mapper.rb,
lib/simple_deploy/stack/deployment/status.rb

Defined Under Namespace

Classes: Deployment, Execute, OutputMapper, SSH

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Stack

Returns a new instance of Stack.



16
17
18
19
20
21
22
23
24
25
# File 'lib/simple_deploy/stack.rb', line 16

def initialize(args)
  @environment = args[:environment]
  @name = args[:name]

  @config = SimpleDeploy.config
  @logger = SimpleDeploy.logger

  @use_internal_ips = !!args[:internal]
  @entry = Entry.new :name => @name
end

Instance Method Details

#attributesObject



147
148
149
# File 'lib/simple_deploy/stack.rb', line 147

def attributes
  stack_reader.attributes
end

#create(args) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/simple_deploy/stack.rb', line 27

def create(args)
  attributes = stack_attribute_formatter.updated_attributes args[:attributes]
  @template_file = args[:template]

  @entry.set_attributes attributes
  stack_creator.create

  @entry.save
end

#deploy(force = false) ⇒ Object



80
81
82
# File 'lib/simple_deploy/stack.rb', line 80

def deploy(force = false)
  deployment.execute force
end

#destroyObject



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/simple_deploy/stack.rb', line 92

def destroy
  if attributes['protection'] != 'on'
    stack_destroyer.destroy
    @entry.delete_attributes
    @logger.info "#{@name} destroyed."
    true
  else
    @logger.warn "#{@name} could not be destroyed because it is protected. Run the protect subcommand to unprotect it"
    false
  end
end

#events(limit) ⇒ Object



104
105
106
# File 'lib/simple_deploy/stack.rb', line 104

def events(limit)
  stack_reader.events limit
end

#execute(args) ⇒ Object



84
85
86
# File 'lib/simple_deploy/stack.rb', line 84

def execute(args)
  executer.execute args
end

#exists?Boolean

Returns:

  • (Boolean)


140
141
142
143
144
145
# File 'lib/simple_deploy/stack.rb', line 140

def exists?
  status
  true
rescue Exceptions::UnknownStack
  false
end

#in_progress_update(args) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/simple_deploy/stack.rb', line 64

def in_progress_update(args)
  if args[:caller].kind_of? Stack::Deployment::Status
    @logger.info "Updating #{@name}."
    attributes = stack_attribute_formatter.updated_attributes args[:attributes]

    @entry.set_attributes attributes
    stack_updater.update_stack attributes
    @logger.info "Update complete for #{@name}."

    @entry.save
    true
  else
    false
  end
end

#instancesObject



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/simple_deploy/stack.rb', line 116

def instances
  stack_reader.instances.map do |instance| 
    instance['instancesSet'].map do |info|
      if info['vpcId'] || @use_internal_ips
        info['privateIpAddress']
      else
        info['ipAddress']
      end
    end
  end.flatten.compact
end

#outputsObject



108
109
110
# File 'lib/simple_deploy/stack.rb', line 108

def outputs
  stack_reader.outputs
end

#parametersObject



151
152
153
# File 'lib/simple_deploy/stack.rb', line 151

def parameters
  stack_reader.parameters
end

#raw_instancesObject



128
129
130
# File 'lib/simple_deploy/stack.rb', line 128

def raw_instances
  stack_reader.instances
end

#resourcesObject



112
113
114
# File 'lib/simple_deploy/stack.rb', line 112

def resources
  stack_reader.resources
end

#sshObject



88
89
90
# File 'lib/simple_deploy/stack.rb', line 88

def ssh
  deployment.ssh
end

#statusObject



132
133
134
# File 'lib/simple_deploy/stack.rb', line 132

def status
  stack_reader.status
end

#templateObject



155
156
157
# File 'lib/simple_deploy/stack.rb', line 155

def template
  stack_reader.template
end

#update(args) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/simple_deploy/stack.rb', line 37

def update(args)
  if !deployment.clear_for_deployment? && args[:force]
    deployment.clear_deployment_lock true

    Backoff.exp_periods do |p|
      sleep p
      break if deployment.clear_for_deployment?
    end
  end

  if deployment.clear_for_deployment?
    @logger.info "Updating #{@name}."
    attributes = stack_attribute_formatter.updated_attributes args[:attributes]
    @template_body = args[:template_body] || template

    @entry.set_attributes attributes
    stack_updater.update_stack attributes
    @logger.info "Update complete for #{@name}."

    @entry.save
    true
  else
    @logger.info "Not clear to update."
    false
  end
end

#wait_for_stableObject



136
137
138
# File 'lib/simple_deploy/stack.rb', line 136

def wait_for_stable
  stack_status.wait_for_stable
end