Module: Kontena::Plugin::Upcloud::Prompts::NodeName::Defaults

Defined in:
lib/kontena/plugin/upcloud/prompts.rb

Instance Method Summary collapse

Instance Method Details

#default_nameObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/kontena/plugin/upcloud/prompts.rb', line 42

def default_name
  nodes = client.get("grids/#{current_grid}/nodes")
  nodes = nodes['nodes'].select{ |n|
    n['labels'] && n['labels'].include?('provider=upcloud'.freeze)
  }
  raise "Did not find any nodes with label provider=upcloud" if nodes.empty?
  prompt.select("Select node:") do |menu|
    nodes.sort_by{|n| n['node_number'] }.reverse.each do |node|
      initial = node['initial_member'] ? '(initial) ' : ''
      menu.choice "#{node['name']} #{initial}", node['name']
    end
  end
end