class Kontena::Cli::Nodes::RemoveCommand

Public Instance Methods

execute() click to toggle source
# File lib/kontena/cli/nodes/remove_command.rb, line 9
def execute
  require_api_url
  require_current_grid
  token = require_token

  nodes.each do |node_name|
    node = client(token).get("nodes/#{current_grid}/#{node_name}")

    if node['has_token'] && node['connected']
      warning "Node #{node['name']} is still connected using a node token, but will be force-disconnected"
    elsif node['connected']
      exit_with_error "Node #{node['name']} is still connected using a grid token. You must terminate the node before removing it."
    end

    confirm_command(node_name) unless forced?

    spinner "Removing #{pastel.cyan(node_name)} node from #{pastel.cyan(current_grid)} grid " do
      client(token).delete("nodes/#{node['id']}")
    end
  end
end