Class: OpenDelivery::Stack
- Inherits:
-
Object
- Object
- OpenDelivery::Stack
- Defined in:
- lib/opendelivery/stack.rb
Constant Summary collapse
- SUCCESS_STATUSES =
[ "CREATE_COMPLETE", "UPDATE_COMPLETE" ]
- FAILURE_STATUSES =
[ "CREATE_FAILED", "ROLLBACK_FAILED", "ROLLBACK_COMPLETE", "DELETE_FAILED", "UPDATE_ROLLBACK_FAILED", "UPDATE_ROLLBACK_COMPLETE", "DELETE_COMPLETE" ]
- PROGRESS_STATUSES =
[ "CREATE_IN_PROGRESS", "ROLLBACK_IN_PROGRESS", "DELETE_IN_PROGRESS", "UPDATE_IN_PROGRESS", "UPDATE_COMPLETE_CLEANUP_IN_PROGRESS", "UPDATE_ROLLBACK_IN_PROGRESS", "UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS" ]
Instance Method Summary collapse
- #create(stack_name, template, parameters = {}, wait = false, domain = nil) ⇒ Object
- #destroy(stack_name, domain = nil, wait = false) ⇒ Object
-
#initialize(region = nil) ⇒ Stack
constructor
A new instance of Stack.
- #list ⇒ Object
- #resume_scaling_activities(stack_name) ⇒ Object
- #watch(stack_name, sleep_time, silent = false) ⇒ Object
Constructor Details
#initialize(region = nil) ⇒ Stack
Returns a new instance of Stack.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/opendelivery/stack.rb', line 28 def initialize(region=nil) if region.nil? @cfn = AWS::CloudFormation.new @autoscaling = AWS::AutoScaling.new else @autoscaling = AWS::AutoScaling.new(:region => region) @cfn = AWS::CloudFormation.new(:region => region) end @domain = OpenDelivery::Domain.new(region) end |
Instance Method Details
#create(stack_name, template, parameters = {}, wait = false, domain = nil) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/opendelivery/stack.rb', line 72 def create(stack_name, template, parameters = {}, wait=false, domain=nil) @cfn.stacks.create(stack_name, File.open(template, "r").read, :parameters => parameters, :capabilities => ["CAPABILITY_IAM"], :disable_rollback => true) end |
#destroy(stack_name, domain = nil, wait = false) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/opendelivery/stack.rb', line 80 def destroy(stack_name, domain=nil, wait=false) stack = @cfn.stacks[stack_name] if stack.exists? resume_scaling_activities(stack_name) stack.delete while wait and stack.exists? sleep 20 end @domain.destroy_item(domain, stack_name) else raise "Stack: #{stack_name} doesn't exist, therefore it cannot be destroyed" end end |
#list ⇒ Object
94 95 96 97 98 |
# File 'lib/opendelivery/stack.rb', line 94 def list @cfn.stacks.each do |stack| puts "Stack Name: #{stack.name} | Status: #{stack.status}" end end |
#resume_scaling_activities(stack_name) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/opendelivery/stack.rb', line 100 def resume_scaling_activities(stack_name) stack = @cfn.stacks[stack_name] stack.resources.each do |resource| if resource.resource_type == "AWS::AutoScaling::AutoScalingGroup" begin @autoscaling.groups[resource.physical_resource_id].resume_all_processes rescue Exception => e puts "ASG operation failed with [#{e.message}]" end end end end |
#watch(stack_name, sleep_time, silent = false) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/opendelivery/stack.rb', line 59 def watch(stack_name, sleep_time, silent=false) success = false begin stack = @cfn.stacks[stack_name] success = watch_loop(stack, sleep_time, silent) rescue AWS::CloudFormation::Errors::ValidationError => msg print_status "Exception raised: #{msg}" success = false end return success end |