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.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/opendelivery/stack.rb', line 6 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
50 51 52 53 54 55 56 |
# File 'lib/opendelivery/stack.rb', line 50 def create(stack_name, template, parameters = {}, wait=false, domain=nil) stack = @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
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/opendelivery/stack.rb', line 58 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
72 73 74 75 76 |
# File 'lib/opendelivery/stack.rb', line 72 def list @cfn.stacks.each do |stack| puts "Stack Name: #{stack.name} | Status: #{stack.status}" end end |
#resume_scaling_activities(stack_name) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/opendelivery/stack.rb', line 78 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
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/opendelivery/stack.rb', line 37 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 |