class KnifeCssh::CsshSummon

Constants

SPECIFIC_OPTIONS

Public Instance Methods

run() click to toggle source
# File lib/chef/knife/cssh-summon.rb, line 61
def run
  # this chef is mainly from chef own knife search command
  if name_args.length < 1
    puts 'Missing argument QUERY!'
    show_usage
    exit 1
  end

  query = name_args[0]
  q = Chef::Search::Query.new
  escaped_query = URI.escape(query, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
  result_items = []

  begin
    q.search('node', escaped_query, 'X_CHEF_id_CHEF_X asc', 0, 100) do |item|
      remote_host = extract_host item
      result_items.push remote_host if not remote_host.nil?
    end
  rescue Net::HTTPServerException => e
    msg = Chef::JSONCompat.from_json(e.response.body)["error"].first
    ui.error("search failed: #{msg}")
    exit 1
  end

  call_cssh result_items
end

Private Instance Methods

call_cssh(hosts) click to toggle source
# File lib/chef/knife/cssh-summon.rb, line 96
def call_cssh(hosts)
  if config[:cssh_command].nil?
    puts "Unable to find any suitable cssh command on PATH!"
    exit 1
  end

  %x[#{config[:cssh_command]} #{get_impl_opt :user_switch} #{config[:login].shellescape} #{hosts.join(" ")}]
end
cssh_command_name() click to toggle source
# File lib/chef/knife/cssh-summon.rb, line 114
def cssh_command_name
  File.basename config[:cssh_command]
end
extract_host(item) click to toggle source
# File lib/chef/knife/cssh-summon.rb, line 90
def extract_host(item)
  return item[:ec2][:public_ipv4] if item.has_key? :ec2
  return item[:ipaddress] if not item[:ipaddress].nil?
  item[:fqdn]
end
get_impl_opt(key) click to toggle source
# File lib/chef/knife/cssh-summon.rb, line 105
def get_impl_opt(key)
  cmdname = cssh_command_name
  if SPECIFIC_OPTIONS.has_key?(cmdname) and SPECIFIC_OPTIONS[cmdname].has_key?(key)
    return SPECIFIC_OPTIONS[cmdname][key]
  end

  SPECIFIC_OPTIONS[:default][key]
end