Class: Ufo::Apps

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
Stack::Helper
Defined in:
lib/ufo/apps.rb,
lib/ufo/apps/cfn_map.rb,
lib/ufo/apps/cluster.rb,
lib/ufo/apps/service.rb

Defined Under Namespace

Classes: CfnMap, Cluster, Service

Instance Method Summary collapse

Methods included from Stack::Helper

#adjust_stack_name, #cfn, #find_stack, #status

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

#initialize(options) ⇒ Apps

Returns a new instance of Apps.



8
9
10
11
12
13
14
15
# File 'lib/ufo/apps.rb', line 8

def initialize(options)
  @options = options
  @clusters = @options[:cluster] || @options[:clusters]
  @clusters = [@clusters].flatten.compact
  if @clusters.empty?
    @clusters = Cluster.all
  end
end

Instance Method Details

#display_info(resp) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/ufo/apps.rb', line 42

def display_info(resp)
  table = Text::Table.new
  table.head = ["Service Name", "Task Definition", "Running", "Launch type", "Ufo?"]
  resp["services"].each do |s|
    table.rows << service_info(s)
  end
  puts table unless ENV['TEST']
end

#list(cluster) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ufo/apps.rb', line 23

def list(cluster)
  begin
    resp = ecs.list_services(cluster: cluster)
  rescue Aws::ECS::Errors::ClusterNotFoundException => e
    puts "ECS cluster #{cluster.color(:green)} not found."
    return
  end
  arns = resp.service_arns.sort

  puts "Listing ECS services in the #{cluster.color(:green)} cluster."
  if arns.empty?
    puts "No ECS services found in the #{cluster.color(:green)} cluster."
    return
  end

  resp = ecs.describe_services(services: arns, cluster: cluster)
  display_info(resp)
end

#list_allObject



17
18
19
20
21
# File 'lib/ufo/apps.rb', line 17

def list_all
  @clusters.each do |cluster|
    list(cluster)
  end
end

#service_info(s) ⇒ Object

for specs



52
53
54
# File 'lib/ufo/apps.rb', line 52

def service_info(s)
  Service.new(s, @options).to_a
end