Module: Oxidized::Input::CLI

Included in:
Exec, FTP, HTTP, SCP, 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
29
# File 'lib/oxidized/input/cli.rb', line 22

def connect_cli
  logger.debug "Running post_login commands at #{node.name}"
  @post_login.each do |command, block|
    logger.debug "Running post_login command: #{command.inspect}, " \
                 "block: #{block.inspect} at #{node.name}"
    block ? block.call : (cmd command)
  end
end

#disconnect_cliObject



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

def disconnect_cli
  logger.debug "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



60
61
62
63
64
65
66
67
68
69
# File 'lib/oxidized/input/cli.rb', line 60

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

#newline(newline_str = "\n") ⇒ Object



56
57
58
# File 'lib/oxidized/input/cli.rb', line 56

def newline(newline_str = "\n")
  @newline || (@newline = newline_str)
end

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



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

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

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



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

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

  @post_login << [cmd, block]
end

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



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

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

  @pre_logout << [cmd, block]
end

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



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

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