Class: Hygroscope::Stack
- Inherits:
-
Object
- Object
- Hygroscope::Stack
- Defined in:
- lib/hygroscope/stack.rb
Instance Attribute Summary collapse
-
#capabilities ⇒ Object
writeonly
Sets the attribute capabilities.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#name ⇒ Object
Returns the value of attribute name.
-
#on_failure ⇒ Object
writeonly
Sets the attribute on_failure.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#template ⇒ Object
writeonly
Sets the attribute template.
-
#timeout ⇒ Object
writeonly
Sets the attribute timeout.
Instance Method Summary collapse
- #create! ⇒ Object
- #delete! ⇒ Object
- #describe ⇒ Object
-
#initialize(name) ⇒ Stack
constructor
A new instance of Stack.
- #list_resources ⇒ Object
- #update! ⇒ Object
Constructor Details
#initialize(name) ⇒ Stack
Returns a new instance of Stack.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/hygroscope/stack.rb', line 9 def initialize(name) @name = name @parameters = {} = {} @template = '' @capabilities = [] @timeout = 15 @on_failure = 'DO_NOTHING' @client = Aws::CloudFormation::Client.new end |
Instance Attribute Details
#capabilities=(value) ⇒ Object (writeonly)
Sets the attribute capabilities
6 7 8 |
# File 'lib/hygroscope/stack.rb', line 6 def capabilities=(value) @capabilities = value end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/hygroscope/stack.rb', line 7 def client @client end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/hygroscope/stack.rb', line 5 def name @name end |
#on_failure=(value) ⇒ Object (writeonly)
Sets the attribute on_failure
6 7 8 |
# File 'lib/hygroscope/stack.rb', line 6 def on_failure=(value) @on_failure = value end |
#parameters ⇒ Object
Returns the value of attribute parameters.
5 6 7 |
# File 'lib/hygroscope/stack.rb', line 5 def parameters @parameters end |
#tags ⇒ Object
Returns the value of attribute tags.
5 6 7 |
# File 'lib/hygroscope/stack.rb', line 5 def end |
#template=(value) ⇒ Object (writeonly)
Sets the attribute template
6 7 8 |
# File 'lib/hygroscope/stack.rb', line 6 def template=(value) @template = value end |
#timeout=(value) ⇒ Object (writeonly)
Sets the attribute timeout
6 7 8 |
# File 'lib/hygroscope/stack.rb', line 6 def timeout=(value) @timeout = value end |
Instance Method Details
#create! ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/hygroscope/stack.rb', line 20 def create! stack_parameters = [] @parameters.each do |k, v| stack_parameters << { parameter_key: k, parameter_value: v.to_s } end = [] .each do |k, v| << { key: k, value: v.to_s } end stack_opts = { stack_name: @name, template_body: @template, parameters: stack_parameters, timeout_in_minutes: @timeout, on_failure: @on_failure } stack_opts['capabilities'] = @capabilities unless @capabilities.empty? stack_opts['tags'] = begin stack_id = @client.create_stack(stack_opts) rescue => e raise e end stack_id end |
#delete! ⇒ Object
83 84 85 86 87 |
# File 'lib/hygroscope/stack.rb', line 83 def delete! @client.delete_stack(stack_name: @name) rescue => e raise e end |
#describe ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/hygroscope/stack.rb', line 89 def describe resp = @client.describe_stacks(stack_name: @name) rescue => e raise e else resp.stacks.first end |
#list_resources ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/hygroscope/stack.rb', line 97 def list_resources resp = @client.describe_stack_resources(stack_name: @name) rescue => e raise e else resources = [] resp.stack_resources.each do |r| resources << { name: r.logical_resource_id, type: r.resource_type, status: r.resource_status } end resources end |
#update! ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/hygroscope/stack.rb', line 57 def update! stack_parameters = [] @parameters.each do |k, v| stack_parameters << { parameter_key: k, parameter_value: v.to_s } end stack_opts = { stack_name: @name, template_body: @template, parameters: stack_parameters } stack_opts['capabilities'] = @capabilities unless @capabilities.empty? begin stack_id = @client.update_stack(stack_opts) rescue => e raise e end stack_id end |