Class: Expect4r::Ios

Instance Attribute Summary

Attributes inherited from BaseLoginObject

#host, #method, #port, #proxy, #ssh_options, #user

Instance Method Summary collapse

Methods included from Router::Ios::TermServer

#clear_line, #powercycle

Methods included from Router::CiscoCommon::Ping

#ping

Methods included from Router::CiscoCommon::Show

#show

Methods included from Router::CiscoCommon

#config_lvl?, #enable, #login, #top, #top?

Methods included from Router::Ios::Modes

#_mode_?, #config, #config?, #exec, #exec?, #in?, #to_config, #to_exec, #to_user, #user?

Methods included from Router::Common::Modes

#_mode_?, #change_mode_to, #in?

Methods included from Router::Common

#console?, #io_escape_char_cb

Methods included from Expect4r

#_login, #child_exit, #connected?, #exp_print, #exp_puts, #exp_send, #expect, #get_prompt, #getc, #interact, #login_by_proxy, #logout, #putc, #putcr, #read_until, #readline, #spawn

Methods inherited from BaseLoginObject

add, #cmp, #connect_retry, #connect_retry=, #dup, #enable_password, new_ssh, new_telnet, #password, #spawnee, #spawnee_prompt, #spawnee_username

Methods inherited from Base

add, all

Constructor Details

#initialize(*args) ⇒ Ios

Returns a new instance of Ios.



14
15
16
17
18
# File 'lib/router/cisco/ios/ios.rb', line 14

def initialize(*args)
  super
  @ps1 = /(.*)(>|#|\$)\s*$/
  @more = / --More-- /
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/router/cisco/ios/ios.rb', line 46

def method_missing(name, *args, &block)
  if name.to_s =~ /^show_/
    filters=[]
    if args.last.is_a?(Hash)
      _begin = args.last.delete(:begin) 
      _section = args.last.delete(:section)
      _count = args.last.delete(:count)
      _exclude = args.last.delete(:exclude)
      _include = args.last.delete(:include)
      filters << "| begin #{_begin}" if _begin
      filters << "| count #{_count}" if _count
      filters << "| section #{_section}" if _section
      filters << "| exclude #{_exclude}" if _exclude
      filters << "| include #{_include}" if _include
    end   
    cmd = name.to_s.split('_').join(' ')
    cmd += " " + filters.join(' ') if filters
    cmd.gsub!(/running config/, 'running-config')
    output = __send__ :exec, cmd, *args
  elsif name.to_s =~ /^shell_/
    cmd = name.to_s.split('_')[1..-1].join(' ') + args.join(' ')
    output = __send__ :shell, cmd, *args
  else
    super
  end
end

Instance Method Details

#putline(line, *args) ⇒ Object

Raises:



20
21
22
23
24
25
# File 'lib/router/cisco/ios/ios.rb', line 20

def putline(line,*args)
  output, rc = super
  return output unless error?(output)
  raise BadPasswordError.new(self.class.to_s,line) if output =~ /Bad password/ 
  raise SyntaxError.new(self.class.to_s,line)
end