Class: KnifeCssh::CsshSummon

Inherits:
Chef::Knife
  • Object
show all
Defined in:
lib/chef/knife/cssh-summon.rb

Constant Summary collapse

SPECIFIC_OPTIONS =
{
  'tmux-cssh' => {
    :user_switch => '-u'
  },
  :default => {
    :user_switch => '-l'
  }
}

Instance Method Summary collapse

Instance Method Details

#runObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# 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