Class: CfDeployer::Stack
- Inherits:
-
Object
- Object
- CfDeployer::Stack
- Defined in:
- lib/cf_deployer/stack.rb
Constant Summary collapse
- SUCCESS_STATS =
[:create_complete, :update_complete, :update_rollback_complete, :delete_complete]
- READY_STATS =
SUCCESS_STATS - [:delete_complete]
- FAILED_STATS =
[:create_failed, :update_failed, :delete_failed]
Instance Method Summary collapse
- #delete ⇒ Object
- #deploy ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(stack_name, component, context) ⇒ Stack
constructor
A new instance of Stack.
- #name ⇒ Object
- #output(key) ⇒ Object
- #outputs ⇒ Object
- #parameters ⇒ Object
- #ready? ⇒ Boolean
- #resource_statuses ⇒ Object
- #status ⇒ Object
- #template ⇒ Object
Constructor Details
#initialize(stack_name, component, context) ⇒ Stack
Returns a new instance of Stack.
11 12 13 14 15 16 |
# File 'lib/cf_deployer/stack.rb', line 11 def initialize(stack_name, component, context) @stack_name = stack_name @cf_driver = context[:cf_driver] || CfDeployer::Driver::CloudFormation.new(stack_name) @context = context @component = component end |
Instance Method Details
#delete ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/cf_deployer/stack.rb', line 48 def delete if exists? CfDeployer::Driver::DryRun.guard "Skipping delete" do Log.info "deleting stack #{@stack_name}" @cf_driver.delete_stack wait_for_stack_to_delete end end end |
#deploy ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cf_deployer/stack.rb', line 18 def deploy config_dir = @context[:config_dir] template = CfDeployer::ConfigLoader.component_json(@component, @context) capabilities = @context[:capabilities] || [] notify = @context[:notify] || [] = @context[:tags] || {} params = to_str(@context[:inputs].select{|key, value| @context[:defined_parameters].keys.include?(key)}) CfDeployer::Driver::DryRun.guard "Skipping deploy" do exists? ? update_stack(template, params, capabilities, ) : create_stack(template, params, capabilities, , notify) end end |
#exists? ⇒ Boolean
58 59 60 |
# File 'lib/cf_deployer/stack.rb', line 58 def exists? @cf_driver.stack_exists? end |
#name ⇒ Object
91 92 93 |
# File 'lib/cf_deployer/stack.rb', line 91 def name @stack_name end |
#output(key) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/cf_deployer/stack.rb', line 40 def output key begin @cf_driver.query_output(key) || (raise ApplicationError.new("'#{key}' is empty from stack #{name} output")) rescue AWS::CloudFormation::Errors::ValidationError => e raise ResourceNotInReadyState.new("Resource stack not in ready state yet, perhaps you should provision it first?") end end |
#outputs ⇒ Object
30 31 32 33 |
# File 'lib/cf_deployer/stack.rb', line 30 def outputs return {} unless ready? @cf_driver.outputs end |
#parameters ⇒ Object
35 36 37 38 |
# File 'lib/cf_deployer/stack.rb', line 35 def parameters return {} unless ready? @cf_driver.parameters end |
#ready? ⇒ Boolean
62 63 64 |
# File 'lib/cf_deployer/stack.rb', line 62 def ready? READY_STATS.include? @cf_driver.stack_status end |
#resource_statuses ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/cf_deployer/stack.rb', line 74 def resource_statuses AWS.memoize do resources = @cf_driver.resource_statuses.merge( { :asg_instances => {}, :instances => {} } ) if resources['AWS::AutoScaling::AutoScalingGroup'] resources['AWS::AutoScaling::AutoScalingGroup'].keys.each do |asg_name| resources[:asg_instances][asg_name] = CfDeployer::Driver::AutoScalingGroup.new(asg_name).instance_statuses end end if resources['AWS::EC2::Instance'] resources['AWS::EC2::Instance'].keys.each do |instance_id| resources[:instances][instance_id] = CfDeployer::Driver::Instance.new(instance_id).status end end resources end end |
#status ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/cf_deployer/stack.rb', line 66 def status if exists? ready? ? :ready : :exists else :does_not_exist end end |
#template ⇒ Object
95 96 97 |
# File 'lib/cf_deployer/stack.rb', line 95 def template @cf_driver.template end |