Class: Awshark::CloudFormation::Manager
- Inherits:
-
Object
- Object
- Awshark::CloudFormation::Manager
- Defined in:
- lib/awshark/cloud_formation/manager.rb
Instance Attribute Summary collapse
-
#capabilities ⇒ Object
readonly
Returns the value of attribute capabilities.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
-
#stage ⇒ Object
readonly
Returns the value of attribute stage.
Instance Method Summary collapse
- #diff_stack_template ⇒ Object
-
#initialize(path, options = {}) ⇒ Manager
constructor
A new instance of Manager.
- #save_stack_template ⇒ Object
- #tail_stack_events ⇒ Object
- #update_stack ⇒ Object
Constructor Details
#initialize(path, options = {}) ⇒ Manager
Returns a new instance of Manager.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/awshark/cloud_formation/manager.rb', line 12 def initialize(path, = {}) @path = path @options = @stage = [:stage] @capabilities = if [:iam] %w[CAPABILITY_IAM CAPABILITY_NAMED_IAM] else [] end @stack = Stack.new(name: inferrer.stack_name) end |
Instance Attribute Details
#capabilities ⇒ Object (readonly)
Returns the value of attribute capabilities.
10 11 12 |
# File 'lib/awshark/cloud_formation/manager.rb', line 10 def capabilities @capabilities end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/awshark/cloud_formation/manager.rb', line 9 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/awshark/cloud_formation/manager.rb', line 9 def path @path end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
10 11 12 |
# File 'lib/awshark/cloud_formation/manager.rb', line 10 def stack @stack end |
#stage ⇒ Object (readonly)
Returns the value of attribute stage.
10 11 12 |
# File 'lib/awshark/cloud_formation/manager.rb', line 10 def stage @stage end |
Instance Method Details
#diff_stack_template ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/awshark/cloud_formation/manager.rb', line 26 def diff_stack_template new_template = template.body old_template = stack.template = { context: 2 } diff = Diffy::Diff.new(old_template, new_template, ) diff.to_s(:color) end |
#save_stack_template ⇒ Object
49 50 51 52 53 |
# File 'lib/awshark/cloud_formation/manager.rb', line 49 def save_stack_template filename = "#{stack.name}.json" File.write(filename, template.body) filename end |
#tail_stack_events ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/awshark/cloud_formation/manager.rb', line 55 def tail_stack_events stack.reload stack_events = StackEvents.new(stack) loop do events = stack_events.new_events print_stack_events(events) break if stack_events.done? sleep(event_polling) end end |
#update_stack ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/awshark/cloud_formation/manager.rb', line 35 def update_stack stack.create_or_update( capabilities: capabilities, stack_name: stack.name, template_url: template.url, parameters: parameters.stack_parameters ) rescue Aws::CloudFormation::Errors::ValidationError => e raise GracefulFail, e. if e..match(/No updates are to be performed/) raise GracefulFail, e. if e..match(/ROLLBACK_COMPLETE state and can not be updated/) raise e end |