Module: Oxidized::Input::CLI

Included in:
Exec, FTP, HTTP, SSH, TFTP, Telnet
Defined in:
lib/oxidized/input/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



4
5
6
# File 'lib/oxidized/input/cli.rb', line 4

def node
  @node
end

Instance Method Details

#connect_cliObject



22
23
24
25
26
27
28
# File 'lib/oxidized/input/cli.rb', line 22

def connect_cli
  Oxidized.logger.debug "lib/oxidized/input/cli.rb: Running post_login commands at #{node.name}"
  @post_login.each do |command, block|
    Oxidized.logger.debug "lib/oxidized/input/cli.rb: Running post_login command: #{command.inspect}, block: #{block.inspect} at #{node.name}"
    block ? block.call : (cmd command)
  end
end

#disconnect_cliObject



30
31
32
33
# File 'lib/oxidized/input/cli.rb', line 30

def disconnect_cli
  Oxidized.logger.debug "lib/oxidized/input/cli.rb Running pre_logout commands at #{node.name}"
  @pre_logout.each { |command, block| block ? block.call : (cmd command, nil) }
end

#getObject



12
13
14
15
16
17
18
19
20
# File 'lib/oxidized/input/cli.rb', line 12

def get
  connect_cli
  d = node.model.get
  disconnect
  d
rescue PromptUndetect
  disconnect
  raise
end

#initializeObject



6
7
8
9
10
# File 'lib/oxidized/input/cli.rb', line 6

def initialize
  @post_login = []
  @pre_logout = []
  @username, @password, @exec = nil
end

#loginObject



55
56
57
58
59
60
61
62
63
64
# File 'lib/oxidized/input/cli.rb', line 55

def 
  match_re = [@node.prompt]
  match_re << @username if @username
  match_re << @password if @password
  until (match = expect(match_re)) == @node.prompt
    cmd(@node.auth[:username], nil) if match == @username
    cmd(@node.auth[:password], nil) if match == @password
    match_re.delete match
  end
end

#password(regex = /^Password/) ⇒ Object



51
52
53
# File 'lib/oxidized/input/cli.rb', line 51

def password(regex = /^Password/)
  @password || (@password = regex)
end

#post_login(cmd = nil, &block) ⇒ Object



35
36
37
38
39
# File 'lib/oxidized/input/cli.rb', line 35

def (cmd = nil, &block)
  return if @exec

  @post_login << [cmd, block]
end

#pre_logout(cmd = nil, &block) ⇒ Object



41
42
43
44
45
# File 'lib/oxidized/input/cli.rb', line 41

def pre_logout(cmd = nil, &block)
  return if @exec

  @pre_logout << [cmd, block]
end

#username(regex = /^(Username|login)/) ⇒ Object



47
48
49
# File 'lib/oxidized/input/cli.rb', line 47

def username(regex = /^(Username|login)/)
  @username || (@username = regex)
end