Sha256: 29e9e511142a20f1f5e5468245959b9de35b79d6ac6cdd1601c754e0565a80e1

Contents?: true

Size: 1.33 KB

Versions: 24

Compression:

Stored size: 1.33 KB

Contents

require 'text-table'

module Ufo
  class Apps
    extend Memoist
    include Stack::Helper

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

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

    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

    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

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

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
ufo-5.0.7 lib/ufo/apps.rb
ufo-5.0.6 lib/ufo/apps.rb
ufo-5.0.5 lib/ufo/apps.rb
ufo-5.0.4 lib/ufo/apps.rb
ufo-5.0.3 lib/ufo/apps.rb
ufo-5.0.2 lib/ufo/apps.rb
ufo-5.0.1 lib/ufo/apps.rb
ufo-5.0.0 lib/ufo/apps.rb
ufo-4.6.3 lib/ufo/apps.rb
ufo-4.6.2 lib/ufo/apps.rb
ufo-4.6.1 lib/ufo/apps.rb
ufo-4.6.0 lib/ufo/apps.rb
ufo-4.5.11 lib/ufo/apps.rb
ufo-4.5.10 lib/ufo/apps.rb
ufo-4.5.9 lib/ufo/apps.rb
ufo-4.5.8 lib/ufo/apps.rb
ufo-4.5.7 lib/ufo/apps.rb
ufo-4.5.6 lib/ufo/apps.rb
ufo-4.5.5 lib/ufo/apps.rb
ufo-4.5.4 lib/ufo/apps.rb