Class: Oxidized::Script::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/oxidized/script/cli.rb

Defined Under Namespace

Classes: CLIError, NothingToDo

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cmd_classObject

Returns the value of attribute cmd_class.



7
8
9
# File 'lib/oxidized/script/cli.rb', line 7

def cmd_class
  @cmd_class
end

Instance Method Details

#runObject



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
40
41
42
43
44
# File 'lib/oxidized/script/cli.rb', line 11

def run
  if @group or @regex or @ostype
    $stdout.sync = true
    nodes = get_hosts
    counter = @threads.to_i
    Signal.trap("CLD") { counter += 1 }
    nodes.each do |node|
      Process.wait if counter <= 0
      puts "Forking " + node if @verbose
      counter -= 1
      fork {
        begin
          @host = node
          connect
          if @opts[:commands]
            puts "Running commands on #{node}:\n#{run_file @opts[:commands]}"
          elsif @cmd
            puts "Running commands on #{node}:\n#{@oxs.cmd @cmd}"
          end
        rescue => error
          puts "We had the following error on node #{node}:\n#{error}"
        end
      }
    end
    Process.waitall
  else
    connect
    if @opts[:commands]
      puts run_file @opts[:commands]
    elsif @cmd
      puts @oxs.cmd @cmd
    end
  end
end