Module: Expect4r::Router::CiscoCommon

Included in:
Ios, Iox
Defined in:
lib/expect4r.rb,
lib/router/cisco/common/ping.rb,
lib/router/cisco/common/show.rb,
lib/router/cisco/common/common.rb

Defined Under Namespace

Modules: Ping, Show

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/router/cisco/common/common.rb', line 33

def method_missing(name, *args, &block)
  if name.to_s =~ /^show_/
    cmd = name.to_s.split('_').join(' ') + args.join(' ')
    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

#config_lvl?Boolean

Returns the config level depths:

Example:

  iox(config-ospf-ar)#

  irb> iox.config_lvl?
  => 3


15
16
17
18
19
20
# File 'lib/router/cisco/common/common.rb', line 15

def config_lvl?
  return -1 unless config?
  @lp =~ /\(config(|.+)\)/
  lvl = Regexp.last_match(1).split('-').size
  lvl == 0 ? 1 : lvl
end

#enableObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/router/cisco/common/common.rb', line 46

def enable
  proc = Proc.new {
    puts "FOUND WE HAVE A BAD PASSWORD SITUATION"
  }
  @pre_matches ||= []
  @pre_matches << [/Bad Password/i, proc]

  enable_pwd = [/^Password: $/, spawnee_enable_password]
  @matches << enable_pwd
  exp_send 'enable'
  @matches =[]
  @pre_matches=[]
  exec "term len 0\nterm width 0"
rescue 
  raise
ensure
  @matches.delete enable_pwd
end

#login(arg = {}) ⇒ Object Also known as: _login_



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/router/cisco/common/common.rb', line 65

def (arg={})
  # Skip the default banner.
  proc = Proc.new {
    read_until /QUICK START GUIDE/, 2
  }
  @pre_matches = []
  @pre_matches << [/Cisco Configuration Professional/, proc]
  
  super(spawnee,arg)
  enable unless arg[:no_enable]

  self
end

#topObject



22
23
24
25
# File 'lib/router/cisco/common/common.rb', line 22

def top
  return unless config?
  1.upto(config_lvl? - 1) { putline 'exit'}
end

#top?Boolean



27
28
29
30
31
# File 'lib/router/cisco/common/common.rb', line 27

def top?
  return false unless config?
  @lp =~ /\(config(|.+)\)/
  Regexp.last_match(1).size == 0
end