Class: MCollective::Util::Playbook::Nodes::ShellNodes

Inherits:
Object
  • Object
show all
Defined in:
lib/mcollective/util/playbook/nodes/shell_nodes.rb

Instance Method Summary collapse

Constructor Details

#initializeShellNodes

Returns a new instance of ShellNodes.



6
7
8
# File 'lib/mcollective/util/playbook/nodes/shell_nodes.rb', line 6

def initialize
  @script = nil
end

Instance Method Details

#dataObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/mcollective/util/playbook/nodes/shell_nodes.rb', line 29

def data
  return @_data if @_data

  shell = Shell.new(@script, "timeout" => 10)
  shell.runcommand

  exitcode = shell.status.exitstatus

  raise("Could not discover nodes via shell method, command exited with code %d" % [exitcode]) unless exitcode == 0

  @_data = shell.stdout.lines.map do |line|
    line.chomp!

    raise("%s is not a valid hostname" % line) unless valid_hostname?(line)

    line
  end
end

#discoverObject



48
49
50
# File 'lib/mcollective/util/playbook/nodes/shell_nodes.rb', line 48

def discover
  data
end

#from_hash(data) ⇒ Object



18
19
20
21
22
23
# File 'lib/mcollective/util/playbook/nodes/shell_nodes.rb', line 18

def from_hash(data)
  @script = data["script"]
  @_data = nil

  self
end

#prepareObject



10
# File 'lib/mcollective/util/playbook/nodes/shell_nodes.rb', line 10

def prepare; end

#valid_hostname?(host) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/mcollective/util/playbook/nodes/shell_nodes.rb', line 25

def valid_hostname?(host)
  host =~ /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/
end

#validate_configuration!Object



12
13
14
15
16
# File 'lib/mcollective/util/playbook/nodes/shell_nodes.rb', line 12

def validate_configuration!
  raise("No node source script specified") unless @script
  raise("Node source script is not executable") unless File.executable?(@script)
  raise("Node source script produced no results") if data.empty?
end