Class: Stack
- Inherits:
-
Object
- Object
- Stack
- Defined in:
- lib/cloudformer/stack.rb
Instance Attribute Summary collapse
-
#deployed ⇒ Object
Returns the value of attribute deployed.
-
#name ⇒ Object
Returns the value of attribute name.
-
#stack ⇒ Object
Returns the value of attribute stack.
Instance Method Summary collapse
- #apply(template_file, parameters, disable_rollback = false, capabilities = []) ⇒ Object
- #delete ⇒ Object
- #events(options = {}) ⇒ Object
-
#initialize(stack_name) ⇒ Stack
constructor
A new instance of Stack.
- #outputs ⇒ Object
- #start_instances ⇒ Object
- #status ⇒ Object
- #stop_instances ⇒ Object
Constructor Details
#initialize(stack_name) ⇒ Stack
Returns a new instance of Stack.
5 6 7 8 9 10 |
# File 'lib/cloudformer/stack.rb', line 5 def initialize(stack_name) @name = stack_name @cf = AWS::CloudFormation.new @stack = @cf.stacks[name] @ec2 = AWS::EC2.new end |
Instance Attribute Details
#deployed ⇒ Object
Returns the value of attribute deployed.
4 5 6 |
# File 'lib/cloudformer/stack.rb', line 4 def deployed @deployed end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/cloudformer/stack.rb', line 4 def name @name end |
#stack ⇒ Object
Returns the value of attribute stack.
4 5 6 |
# File 'lib/cloudformer/stack.rb', line 4 def stack @stack end |
Instance Method Details
#apply(template_file, parameters, disable_rollback = false, capabilities = []) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/cloudformer/stack.rb', line 16 def apply(template_file, parameters, disable_rollback=false, capabilities=[]) template = File.read(template_file) validation = validate(template) unless validation["valid"] puts "Unable to update - #{validation["response"][:code]} - #{validation["response"][:message]}" return 1 end pending_operations = false if deployed pending_operations = update(template, parameters) else pending_operations = create(template, parameters, disable_rollback, capabilities) end wait_until_end if pending_operations if stack.status == "ROLLBACK_COMPLETE" puts "Unable to update template. Check log for more information." return 1 else return 0 end end |
#delete ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/cloudformer/stack.rb', line 46 def delete with_highlight do puts "Attempting to delete stack - #{name}" stack.delete wait_until_end end end |
#events(options = {}) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/cloudformer/stack.rb', line 64 def events( = {}) with_highlight do if !deployed puts "Stack not up." return end stack.events.sort_by {|a| a.}.each do |event| puts "#{event.timestamp} - #{event.logical_resource_id} - #{event.resource_type} - #{event.resource_status} - #{event.resource_status_reason.to_s}" end end end |
#outputs ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/cloudformer/stack.rb', line 76 def outputs with_highlight do if !deployed puts "Stack not up." return 1 end stack.outputs.each do |output| puts "#{output.key} - #{output.description} - #{output.value}" end end return 0 end |
#start_instances ⇒ Object
42 43 44 |
# File 'lib/cloudformer/stack.rb', line 42 def start_instances update_instances("start") end |
#status ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/cloudformer/stack.rb', line 54 def status with_highlight do if deployed puts "#{stack.name} - #{stack.status} - #{stack.status_reason}" else puts "#{name} - Not Deployed" end end end |
#stop_instances ⇒ Object
38 39 40 |
# File 'lib/cloudformer/stack.rb', line 38 def stop_instances update_instances("stop") end |