Class: Cloudkick::Command::Pssh

Inherits:
Base
  • Object
show all
Defined in:
lib/cloudkick/commands/parallel.rb

Instance Attribute Summary

Attributes inherited from Base

#args

Instance Method Summary collapse

Methods inherited from Base

#client, #credentials, #display, #extract_option, #initialize

Constructor Details

This class inherits a constructor from Cloudkick::Command::Base

Instance Method Details

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cloudkick/commands/parallel.rb', line 5

def index
  unless args.size > 0
    raise CommandFailed, 'usage: cloudkick pssh --query <query> ' \
    '<command> ' \
    '[--username <username>]'
  end

  query = extract_option('--query')
  username = extract_option('--username')
  command = args.last.strip rescue nil
  
  file = Tempfile.new('ck')

  if query
    client.get('nodes', query).each do |node|
      file.puts node.ipaddress
    end
  else
    client.get('nodes').each do |node|
      file.puts node.ipaddress
    end
  end
  
  file.flush
  begin
    if username
      system("pssh --inline --timeout=-1  --hosts=#{file.path} --user=#{username} '#{command}'")
    else
      system("pssh --inline --timeout=-1 --hosts=#{file.path} '#{command}'")
    end
  rescue
    raise CommandFailed, 'cloudkick: command not found: pssh'
  end
  file.close
end