Sha256: d365182f7cef15a4c24d325ed56fd0176932073fbe2673df9e6a30357f01c476

Contents?: true

Size: 1.4 KB

Versions: 51

Compression:

Stored size: 1.4 KB

Contents

module Kontena::Cli::Nodes
  class ListCommand < Kontena::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 %-10s %-40s" % ['Name', 'Status', 'Initial', 'Labels']
        nodes = nodes['nodes'].sort_by{|n| n['node_number'] }
        nodes.each do |node|
          puts "%-70.70s %-10s %-10s %-40s" % [
            node['name'],
            node['connected'] ? 'online' : 'offline',
            node['initial_member'] ? 'yes' : 'no',
            (node['labels'] || ['-']).join(",")
          ]
        end
      end
    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
kontena-cli-1.0.6 lib/kontena/cli/nodes/list_command.rb
kontena-cli-1.0.6.rc1 lib/kontena/cli/nodes/list_command.rb
kontena-cli-1.0.5 lib/kontena/cli/nodes/list_command.rb
kontena-cli-1.0.5.rc1 lib/kontena/cli/nodes/list_command.rb
kontena-cli-1.0.5.pre1 lib/kontena/cli/nodes/list_command.rb
kontena-cli-1.0.4 lib/kontena/cli/nodes/list_command.rb
kontena-cli-1.0.4.rc2 lib/kontena/cli/nodes/list_command.rb
kontena-cli-1.0.4.rc1 lib/kontena/cli/nodes/list_command.rb
kontena-cli-1.0.3 lib/kontena/cli/nodes/list_command.rb
kontena-cli-1.0.3.rc1 lib/kontena/cli/nodes/list_command.rb
kontena-cli-1.0.2 lib/kontena/cli/nodes/list_command.rb
kontena-cli-1.0.2.rc2 lib/kontena/cli/nodes/list_command.rb
kontena-cli-1.0.2.rc1 lib/kontena/cli/nodes/list_command.rb
kontena-cli-1.0.2.pre1 lib/kontena/cli/nodes/list_command.rb
kontena-cli-1.0.1 lib/kontena/cli/nodes/list_command.rb
kontena-cli-1.0.1.rc3 lib/kontena/cli/nodes/list_command.rb
kontena-cli-1.0.1.rc2 lib/kontena/cli/nodes/list_command.rb
kontena-cli-1.0.1.rc1 lib/kontena/cli/nodes/list_command.rb
kontena-cli-1.0.0 lib/kontena/cli/nodes/list_command.rb
kontena-cli-1.0.0.rc2 lib/kontena/cli/nodes/list_command.rb