Class: Ufo::Status

Inherits:
Base
  • Object
show all
Defined in:
lib/ufo/status.rb

Instance Method Summary collapse

Methods inherited from Base

#full_service, #info, #initialize, #no_service_message, #switch_current

Methods included from Ufo::Stack::Helper

#adjust_stack_name, #find_stack, #status

Methods included from Settings

#cfn, #network, #settings

Methods included from Util

#default_cluster, #display_params, #execute, #pretty_time, #settings, #task_definition_arns, #user_params

Methods included from AwsService

#cloudformation, #cloudwatchlogs, #ec2, #ecr, #ecs, #elb

Constructor Details

This class inherits a constructor from Ufo::Base

Instance Method Details

#runObject

used for the ufo status command



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ufo/status.rb', line 4

def run
  unless stack_exists?(@stack_name)
    puts "The stack #{@stack_name.color(:green)} does not exist."
    return
  end

  resp = cloudformation.describe_stacks(stack_name: @stack_name)
  stack = resp.stacks.first

  puts "The current status for the stack #{@stack_name.color(:green)} is #{stack.stack_status.color(:green)}"

  status_poller = Stack::Status.new(@stack_name)

  if stack.stack_status =~ /_IN_PROGRESS$/
    puts "Stack events (tailing):"
    # tail all events until done
    status_poller.hide_time_took = true
    status_poller.wait
  else
    puts "Stack events:"
    # show the last events that was user initiated
    status_poller.refresh_events
    status_poller.show_events(true)
  end
end

#stack_exists?(stack_name) ⇒ Boolean

Returns:

  • (Boolean)


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
# File 'lib/ufo/status.rb', line 30

def stack_exists?(stack_name)
  return true if ENV['TEST']
  return false if @options[:noop]

  exist = nil
  begin
    # When the stack does not exist an exception is raised. Example:
    # Aws::CloudFormation::Errors::ValidationError: Stack with id blah does not exist
    resp = cloudformation.describe_stacks(stack_name: stack_name)
    exist = true
  rescue Aws::CloudFormation::Errors::ValidationError => e
    if e.message =~ /does not exist/
      exist = false
    elsif e.message.include?("'stackName' failed to satisfy constraint")
      # Example of e.message when describe_stack with invalid stack name
      # "1 validation error detected: Value 'instance_and_route53' at 'stackName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z][-a-zA-Z0-9]*|arn:[-a-zA-Z0-9:/._+]*"
      puts "Invalid stack name: #{stack_name}"
      puts "Full error message: #{e.message}"
      exit 1
    else
      raise # re-raise exception  because unsure what other errors can happen
    end
  end
  exist
end