Class: Sfn::Command::Update

Inherits:
Sfn::Command
  • Object
show all
Includes:
Sfn::CommandModule::Base, Sfn::CommandModule::Stack, Sfn::CommandModule::Template
Defined in:
lib/sfn/command/update.rb

Overview

Update command

Constant Summary

Constants included from Sfn::CommandModule::Template

Sfn::CommandModule::Template::TEMPLATE_IGNORE_DIRECTORIES

Instance Method Summary collapse

Methods included from Sfn::CommandModule::Stack

included

Methods included from Sfn::CommandModule::Template

included

Methods included from Sfn::CommandModule::Base

included

Methods inherited from Sfn::Command

#config, #initialize

Constructor Details

This class inherits a constructor from Sfn::Command

Instance Method Details

#execute!Object

Run the stack creation command



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/sfn/command/update.rb', line 13

def execute!
  name = name_args.first
  unless(name)
    ui.fatal "Formation name must be specified!"
    exit 1
  end

  stack_info = "#{ui.color('Name:', :bold)} #{name}"
  begin
    stack = provider.connection.stacks.get(name)
  rescue Miasma::Error::ApiError::RequestError
    stack = nil
  end

  if(config[:file])
    file = load_template_file(:stack => stack)
    stack_info << " #{ui.color('Path:', :bold)} #{config[:file]}"
    nested_stacks = file.delete('sfn_nested_stack')
  end

  if(nested_stacks)
    unpack_nesting(name, file, :update)
  else
    unless(stack)
      ui.fatal "Failed to locate requested stack: #{ui.color(name, :red, :bold)}"
      raise "Failed to locate stack: #{name}"
    end

    ui.info "#{ui.color('Cloud Formation:', :bold)} #{ui.color('update', :green)}"

    unless(file)
      if(config[:template])
        file = config[:template]
        stack_info << " #{ui.color('(template provided)', :green)}"
      else
        stack_info << " #{ui.color('(no template update)', :yellow)}"
      end
    end
    ui.info "  -> #{stack_info}"

    apply_stacks!(stack)

    if(file)
      if(config[:print_only])
        ui.puts _format_json(translate_template(file))
        return
      end
      populate_parameters!(file, :current_parameters => stack.parameters)
      stack.template = translate_template(file)
      stack.parameters = config_root_parameters
      stack.template = Sfn::Utils::StackParameterScrubber.scrub!(stack.template)
    else
      populate_parameters!(stack.template, :current_parameters => stack.parameters)
      stack.parameters = config_root_parameters
    end

    begin
      api_action!(:api_stack => stack) do
        stack.save
        if(config[:poll])
          poll_stack(stack.name)
          if(stack.reload.state == :update_complete)
            ui.info "Stack update complete: #{ui.color('SUCCESS', :green)}"
            namespace.const_get(:Describe).new({:outputs => true}, [name]).execute!
          else
            ui.fatal "Update of stack #{ui.color(name, :bold)}: #{ui.color('FAILED', :red, :bold)}"
            raise
          end
        else
          ui.warn 'Stack state polling has been disabled.'
          ui.info "Stack update initialized for #{ui.color(name, :green)}"
        end
      end
    rescue Miasma::Error::ApiError::RequestError => e
      if(e.message.downcase.include?('no updates'))
        ui.warn "No updates detected for stack (#{stack.name})"
      else
        raise
      end
    end

  end
end