Sha256: 2164d46b180d66fdd4fd1ef0bf8bef92a8d9321b73df68074e13313bb5824276

Contents?: true

Size: 1.2 KB

Versions: 7

Compression:

Stored size: 1.2 KB

Contents

require 'text-table'

module Ufo
  class Apps
    autoload :CfnMap, "ufo/apps/cfn_map"
    autoload :Service, "ufo/apps/service"

    extend Memoist
    include Stack::Helper

    def initialize(options)
      @options = options
      @cluster = @options[:cluster] || default_cluster
    end

    def list
      begin
        resp = ecs.list_services(cluster: @cluster)
      rescue Aws::ECS::Errors::ClusterNotFoundException => e
        puts "ECS cluster #{@cluster.color(:green)} not found."
        exit 1
      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

7 entries across 7 versions & 1 rubygems

Version Path
ufo-4.4.3 lib/ufo/apps.rb
ufo-4.4.2 lib/ufo/apps.rb
ufo-4.4.1 lib/ufo/apps.rb
ufo-4.4.0 lib/ufo/apps.rb
ufo-4.3.1 lib/ufo/apps.rb
ufo-4.3.0 lib/ufo/apps.rb
ufo-4.2.0 lib/ufo/apps.rb