Class: Stackup::Stack
- Inherits:
-
Object
- Object
- Stackup::Stack
- Includes:
- ErrorHandling
- Defined in:
- lib/stackup/stack.rb
Overview
An abstraction of a CloudFormation stack.
Constant Summary collapse
- DEFAULT_WAIT_POLL_INTERVAL =
seconds
5
- ALMOST_DEAD_STATUSES =
%w(CREATE_FAILED ROLLBACK_COMPLETE)
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#wait ⇒ String
Wait until stack reaches a stable state.
-
#wait_poll_interval ⇒ Object
Returns the value of attribute wait_poll_interval.
Instance Method Summary collapse
-
#cancel_update ⇒ Symbol
Cancel update in-progress.
-
#create_or_update(options) ⇒ Symbol
(also: #up)
Create or update the stack.
-
#delete ⇒ Symbol
(also: #down)
Delete the stack.
-
#exists? ⇒ boolean
True iff the stack exists.
-
#initialize(name, client = {}, options = {}) ⇒ Stack
constructor
A new instance of Stack.
-
#on_event(event_handler = nil, &block) ⇒ Object
Register a handler for reporting of stack events.
-
#outputs ⇒ Hash<String, String>
Get stack outputs.
-
#parameters ⇒ Hash
Get the current parameters.
-
#resources ⇒ Hash<String, String>
Get stack outputs.
-
#status ⇒ String
The current stack status.
-
#tags ⇒ Hash
Get the current tags.
-
#template ⇒ Hash
Get the current template.
- #wait? ⇒ Boolean
- #watch(zero = true) {|watcher| ... } ⇒ Object
Methods included from ErrorHandling
Constructor Details
#initialize(name, client = {}, options = {}) ⇒ Stack
Returns a new instance of Stack.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/stackup/stack.rb', line 16 def initialize(name, client = {}, = {}) client = Aws::CloudFormation::Client.new(client) if client.is_a?(Hash) @name = name @cf_client = client @wait = true .each do |key, value| public_send("#{key}=", value) end @wait_poll_interval ||= DEFAULT_WAIT_POLL_INTERVAL end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
27 28 29 |
# File 'lib/stackup/stack.rb', line 27 def name @name end |
#wait ⇒ String
Wait until stack reaches a stable state
181 182 183 184 185 |
# File 'lib/stackup/stack.rb', line 181 def wait modify_stack(/./, "failed to stabilize") do # nothing end end |
#wait_poll_interval ⇒ Object
Returns the value of attribute wait_poll_interval.
28 29 30 |
# File 'lib/stackup/stack.rb', line 28 def wait_poll_interval @wait_poll_interval end |
Instance Method Details
#cancel_update ⇒ Symbol
Cancel update in-progress.
169 170 171 172 173 174 175 |
# File 'lib/stackup/stack.rb', line 169 def cancel_update modify_stack(/_COMPLETE$/, "update cancel failed") do cf_stack.cancel_update end rescue InvalidStateError nil end |
#create_or_update(options) ⇒ Symbol Also known as: up
Create or update the stack.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/stackup/stack.rb', line 112 def create_or_update() = .dup if (template_data = .delete(:template)) [:template_body] = MultiJson.dump(template_data) end if (parameters = [:parameters]) [:parameters] = Parameters.new(parameters).to_a end if ( = [:tags]) [:tags] = () end if (policy_data = .delete(:stack_policy)) [:stack_policy_body] = MultiJson.dump(policy_data) end if (policy_data = .delete(:stack_policy_during_update)) [:stack_policy_during_update_body] = MultiJson.dump(policy_data) end [:capabilities] ||= ["CAPABILITY_NAMED_IAM"] delete if ALMOST_DEAD_STATUSES.include?(status) update() rescue NoSuchStack create() end |
#delete ⇒ Symbol Also known as: down
Delete the stack.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/stackup/stack.rb', line 147 def delete begin @stack_id = handling_validation_error do cf_stack.stack_id end rescue NoSuchStack return nil end modify_stack("DELETE_COMPLETE", "stack delete failed") do cf_stack.delete end ensure @stack_id = nil end |
#exists? ⇒ boolean
Returns true iff the stack exists.
58 59 60 61 62 63 |
# File 'lib/stackup/stack.rb', line 58 def exists? status true rescue NoSuchStack false end |
#on_event(event_handler = nil, &block) ⇒ Object
Register a handler for reporting of stack events.
39 40 41 42 43 |
# File 'lib/stackup/stack.rb', line 39 def on_event(event_handler = nil, &block) event_handler ||= block fail ArgumentError, "no event_handler provided" if event_handler.nil? @event_handler = event_handler end |
#outputs ⇒ Hash<String, String>
Get stack outputs.
222 223 224 |
# File 'lib/stackup/stack.rb', line 222 def outputs extract_hash(:outputs, :output_key, :output_value) end |
#parameters ⇒ Hash
Get the current parameters.
204 205 206 |
# File 'lib/stackup/stack.rb', line 204 def parameters extract_hash(:parameters, :parameter_key, :parameter_value) end |
#resources ⇒ Hash<String, String>
Get stack outputs.
232 233 234 |
# File 'lib/stackup/stack.rb', line 232 def resources extract_hash(:resource_summaries, :logical_resource_id, :physical_resource_id) end |
#status ⇒ String
Returns the current stack status.
50 51 52 53 54 |
# File 'lib/stackup/stack.rb', line 50 def status handling_validation_error do cf_stack.stack_status end end |
#tags ⇒ Hash
Get the current tags.
213 214 215 |
# File 'lib/stackup/stack.rb', line 213 def extract_hash(:tags, :key, :value) end |
#template ⇒ Hash
Get the current template.
192 193 194 195 196 197 |
# File 'lib/stackup/stack.rb', line 192 def template handling_validation_error do template_json = cf_client.get_template(:stack_name => name).template_body MultiJson.load(template_json) end end |
#wait? ⇒ Boolean
32 33 34 |
# File 'lib/stackup/stack.rb', line 32 def wait? @wait end |
#watch(zero = true) {|watcher| ... } ⇒ Object
236 237 238 239 240 |
# File 'lib/stackup/stack.rb', line 236 def watch(zero = true) watcher = Stackup::StackWatcher.new(cf_stack) watcher.zero if zero yield watcher end |