Sha256: 87c20b3fb592076e092881c245a363e30addb732757d34cb5a821d39393a107d

Contents?: true

Size: 1.67 KB

Versions: 54

Compression:

Stored size: 1.67 KB

Contents

require_relative 'services_helper'

module Kontena::Cli::Services
  class ListCommand < Kontena::Command
    include Kontena::Cli::Common
    include Kontena::Cli::GridOptions
    include ServicesHelper

    option ["-q", "--quiet"], :flag, "Show only service names"
    option '--stack', 'STACK', 'Stack name'

    def execute
      require_api_url
      token = require_token

      grids = client(token).get("grids/#{current_grid}/services?stack=#{stack}")
      services = grids['services'].sort_by{|s| s['updated_at'] }.reverse
      if quiet?
        services.each do |service|
          puts "#{service.dig('stack', 'id')}/#{service['name']}"
        end
      else
        titles = ['NAME', 'INSTANCES', 'STATEFUL', 'STATE', 'EXPOSED PORTS']
        puts "%-60s %-10s %-8s %-10s %-50s" % titles
        services.each do |service|
          print_service_row(service)
        end
      end
    end

    def print_service_row(service)
      stateful = service['stateful'] ? 'yes' : 'no'
      running = service['instance_counts']['running']
      desired = service['instances']
      instances = "#{running} / #{desired}"
      ports = service['ports'].map{|p|
        "#{p['ip']}:#{p['node_port']}->#{p['container_port']}/#{p['protocol']}"
      }.join(", ")
      health = health_status(service)
      if service.dig('stack', 'name').to_s == 'null'.freeze
        name = service['name']
      else
        name = "#{service.dig('stack', 'name')}/#{service['name']}"
      end
      vars = [
        health_status_icon(health),
        name,
        instances,
        stateful,
        service['state'],
        ports
      ]
      puts "%s %-58s %-10.10s %-8s %-10s %-50s" % vars
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
kontena-cli-1.3.0.pre1 lib/kontena/cli/services/list_command.rb
kontena-cli-1.2.2 lib/kontena/cli/services/list_command.rb
kontena-cli-1.2.2.rc2 lib/kontena/cli/services/list_command.rb
kontena-cli-1.2.2.rc1 lib/kontena/cli/services/list_command.rb
kontena-cli-1.2.1 lib/kontena/cli/services/list_command.rb
kontena-cli-1.2.1.rc1 lib/kontena/cli/services/list_command.rb
kontena-cli-1.2.0 lib/kontena/cli/services/list_command.rb
kontena-cli-1.2.0.rc3 lib/kontena/cli/services/list_command.rb
kontena-cli-1.2.0.rc2 lib/kontena/cli/services/list_command.rb
kontena-cli-1.2.0.rc1 lib/kontena/cli/services/list_command.rb
kontena-cli-1.2.0.pre3 lib/kontena/cli/services/list_command.rb
kontena-cli-1.2.0.pre2 lib/kontena/cli/services/list_command.rb
kontena-cli-1.1.6 lib/kontena/cli/services/list_command.rb
kontena-cli-1.2.0.pre1 lib/kontena/cli/services/list_command.rb
kontena-cli-1.1.5 lib/kontena/cli/services/list_command.rb
kontena-cli-1.1.5.rc3 lib/kontena/cli/services/list_command.rb
kontena-cli-1.1.5.rc2 lib/kontena/cli/services/list_command.rb
kontena-cli-1.1.5.rc1 lib/kontena/cli/services/list_command.rb
kontena-cli-1.1.4 lib/kontena/cli/services/list_command.rb
kontena-cli-1.2.0.dev1 lib/kontena/cli/services/list_command.rb