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
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
47 48 49 50 51 52 53 54 55 |
# File 'lib/cf_deployer/stack.rb', line 47 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 |
# 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] || [] = @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, ) end end |
#exists? ⇒ Boolean
57 58 59 |
# File 'lib/cf_deployer/stack.rb', line 57 def exists? @cf_driver.stack_exists? end |
#name ⇒ Object
90 91 92 |
# File 'lib/cf_deployer/stack.rb', line 90 def name @stack_name end |
#output(key) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/cf_deployer/stack.rb', line 39 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
29 30 31 32 |
# File 'lib/cf_deployer/stack.rb', line 29 def outputs return {} unless ready? @cf_driver.outputs end |
#parameters ⇒ Object
34 35 36 37 |
# File 'lib/cf_deployer/stack.rb', line 34 def parameters return {} unless ready? @cf_driver.parameters end |
#ready? ⇒ Boolean
61 62 63 |
# File 'lib/cf_deployer/stack.rb', line 61 def ready? READY_STATS.include? @cf_driver.stack_status end |
#resource_statuses ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/cf_deployer/stack.rb', line 73 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
65 66 67 68 69 70 71 |
# File 'lib/cf_deployer/stack.rb', line 65 def status if exists? ready? ? :ready : :exists else :does_not_exist end end |