Parent

Included Modules

Class/Module Index [+]

Quicksearch

Chef::Knife::ClusterSsh

Public Instance Methods

configure_session() click to toggle source
# File lib/chef/knife/cluster_ssh.rb, line 43
      def configure_session
        target = get_slice(@name_args[0]).select(&:running?)

        display(target) if config[:verbose] || config[:display_target]

        config[:attribute]     ||= Chef::Config[:knife][:ssh_address_attribute] || "fqdn"
        config[:ssh_user]      ||= Chef::Config[:knife][:ssh_user]
#        config[:identity_file] ||= target.ssh_identity_file

#         @action_nodes = target.chef_nodes
        target = target.select {|t| not t.bogus? }
        addresses = target.map {|c| c.machine.public_hostname }.compact

        (ui.fatal("No nodes returned from search!"); exit 10) if addresses.nil? || addresses.length == 0

        session_from_list(addresses)
      end
cssh() click to toggle source
# File lib/chef/knife/cluster_ssh.rb, line 107
def cssh
  exec "cssh "+session.servers_for.map{|server| server.user ? "#{server.user}@#{server.host}" : server.host}.join(" ")
end
run() click to toggle source
# File lib/chef/knife/cluster_ssh.rb, line 111
def run
  load_ironfan
  die(banner) if @name_args.empty?
  extend Chef::Mixin::Command

  @longest = 0
  configure_session

  case @name_args[1]
  when "screen",nil   then screen
  when "interactive"  then interactive
  when "tmux"         then tmux
  when "macterm"      then macterm
  when "cssh"         then cssh
  else
    ssh_command(@name_args[1..-1].join(" "))
  end

  session.close
  exit_if_unhealthy!
end
ssh_command(command, subsession=nil) click to toggle source

Override the one in Chef::Knife::Ssh to give a big red warning if the process executes with badness

# File lib/chef/knife/cluster_ssh.rb, line 79
def ssh_command(command, subsession=nil)
  subsession ||= session
  command = fixup_sudo(command)
  #
  subsession.open_channel do |ch|
    ch.request_pty
    ch.exec command do |ch, success|
      raise ArgumentError, "Cannot execute #{command}" unless success
      # note: you can't do the stderr calback because requesting a pty
      # squashes stderr and stdout together
      ch.on_data do |ichannel, data|
        print_data(ichannel[:host], data)
        if data =~ /^knife sudo password: /
          ichannel.send_data("#{get_password}\n")
        end
      end
      ch.on_request "exit-status" do |ichannel, data|
        exit_status = data.read_long
        if exit_status != 0
          command_snippet = (command.length < 70) ? command : (command[0..45] + ' ... ' + command[-19..-1])
          has_problem ->{ print_data(ichannel[:host], "'#{command_snippet.gsub(/[\r\n]+/, "; ")}' terminated with error status #{exit_status}", :err) }
        end
      end
    end
  end
  session.loop
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.