Sha256: 702e998fee2bbde7a02d37e08a2350a5495424beed85bfec9fa7c6a6b87219ee

Contents?: true

Size: 1.41 KB

Versions: 6

Compression:

Stored size: 1.41 KB

Contents

module Kontena::Cli::Nodes
  class ListCommand < Clamp::Command
    include Kontena::Cli::Common
    include Kontena::Cli::GridOptions

    option ["--all"], :flag, "List nodes for all grids", default: false

    def execute
      require_api_url
      require_current_grid
      token = require_token

      if all?
        grids = client(token).get("grids")
        puts "%-70s %-10s %-40s" % [ 'Name', 'Status', 'Labels']

        grids['grids'].each do |grid|
          nodes = client(token).get("grids/#{grid['name']}/nodes")
          nodes['nodes'].each do |node|
            if node['connected']
              status = 'online'
            else
              status = 'offline'
            end
            puts "%-70.70s %-10s %-40s" % [
              "#{grid['name']}/#{node['name']}",
              status,
              (node['labels'] || ['-']).join(",")
            ]
          end
        end
      else
        nodes = client(token).get("grids/#{current_grid}/nodes")
        puts "%-70s %-10s %-40s" % ['Name', 'Status', 'Labels']
        nodes = nodes['nodes'].sort_by{|n| n['node_number'] }
        nodes.each do |node|
          if node['connected']
            status = 'online'
          else
            status = 'offline'
          end
          puts "%-70.70s %-10s %-40s" % [
            node['name'],
            status,
            (node['labels'] || ['-']).join(",")
          ]
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
kontena-cli-0.13.4 lib/kontena/cli/nodes/list_command.rb
kontena-cli-0.13.3 lib/kontena/cli/nodes/list_command.rb
kontena-cli-0.13.2 lib/kontena/cli/nodes/list_command.rb
kontena-cli-0.13.1 lib/kontena/cli/nodes/list_command.rb
kontena-cli-0.13.0.1 lib/kontena/cli/nodes/list_command.rb
kontena-cli-0.13.0 lib/kontena/cli/nodes/list_command.rb