Top Level Namespace

Defined Under Namespace

Modules: Gaptool

Instance Method Summary collapse

Instance Method Details

#infohelper(nodes, parseable, grepable) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gaptool-client.rb', line 10

def infohelper(nodes, parseable, grepable)
  if parseable
    puts nodes.to_json
  else
    nodes.each do |node|
      @host = "#{node['role']}:#{node['environment']}:#{node['instance']}"
      unless grepable
        puts @host.color(:green)
      end
      node.keys.each do |key|
        if grepable
          puts "#{@host}|#{key}|#{node[key]}"
        else
          unless key == node.keys.last
            puts "  ┠  #{key.color(:cyan)}: #{node[key]}"
          else
            puts "  ┖  #{key.color(:cyan)}: #{node[key]}\n\n"
          end
        end
      end
    end
  end
end

#sshcmd(node, commands) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/gaptool-client.rb', line 34

def sshcmd(node, commands)
  Net::SSH.start(
    node['hostname'],
    'admin',
    :key_data => [$api.ssh(node['role'], node['environment'], node['instance'])['key']],
    :config => false,
    :keys_only => true,
    :paranoid => false
  ) do |ssh|
    stdout_data = ""
    stderr_data = ""
    exit_code = nil
    exit_signal = nil
    commands.each do |command|
      ssh.open_channel do |channel|
        channel.exec(command) do |ch, success|
          unless success
            abort "FAILED: couldn't execute command (ssh.channel.exec)"
          end
          channel.on_data do |ch,data|
            puts "#{node['role'].color(:yellow)}:#{node['environment'].color(:yellow)}:#{node['instance'].color(:yellow)}> #{data}"
          end

          channel.on_extended_data do |ch,type,data|
            puts "#{node['role'].color(:yellow)}:#{node['environment'].color(:yellow)}:#{node['instance'].color(:red)}> #{data}"
          end

          channel.on_request("exit-status") do |ch,data|
            exit_code = data.read_long
            if exit_code != 0
              exit exit_code
            end
          end

          channel.on_request("exit-signal") do |ch, data|
            exit_signal = data.read_string
          end
        end
      end
    end
#    ssh.loop
#    [stdout_data, stderr_data, exit_code, exit_signal]
  end
end