Module: Expect4r::Router::Junos::Modes

Included in:
J
Defined in:
lib/router/juniper/junos/modes.rb

Instance Method Summary collapse

Instance Method Details

#clear_cli_logical_routerObject



107
108
109
110
111
112
# File 'lib/router/juniper/junos/modes.rb', line 107

def clear_cli_logical_router()
  return unless @ps1_bis
  to_exec
  @ps1_bis=nil
  putline "clear cli logical-router"
end

#config(stmts = nil, arg = {}) ⇒ Object

Adds a Junos config mixin.

Example:

j.config %{
  edit logical-router Orleans protocols bgp
    edit group session-to-200
      set type external
      set peer-as 200
      set neighbor 40.0.2.1 peer-as 200
}


18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/router/juniper/junos/modes.rb', line 18

def config(stmts=nil, arg={})
   unless connected?
  if stmts
    mode = in?
    to_config
    output = exp_send(stmts, arg)
    output << commit
    change_mode_to(mode)
    output.flatten
  else
    to_config
  end
end

#config?Boolean

returns true if router is in :config mode, false otherwise.

Returns:

  • (Boolean)


81
82
83
# File 'lib/router/juniper/junos/modes.rb', line 81

def config?
  @lp =~ /^.+# $/ ? true : false
end

#exec(cmd = nil, *args) ⇒ Object

Adds a Junos exec mixin.

Example:

j.exec 'set cli screen-length 0'


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/router/juniper/junos/modes.rb', line 38

def exec(cmd=nil, *args)
   unless connected?
  if cmd.nil?
    to_exec
  else
    if config?
      exp_send("run #{cmd}", *args)
    elsif exec?
      exp_send cmd, *args
    else
      mode = _mode_?
      to_exec
      output = exp_send(cmd, *args)
      change_mode_to mode
      output
    end
  end
end

#exec?Boolean

returns true if router is in :exec mode, false otherwise.

Returns:

  • (Boolean)


74
75
76
# File 'lib/router/juniper/junos/modes.rb', line 74

def exec?
  @lp =~ /> $/ ? true : false
end

#set_cli_logical_router(logical_router) ⇒ Object



98
99
100
101
102
103
104
105
# File 'lib/router/juniper/junos/modes.rb', line 98

def set_cli_logical_router(logical_router)
  return if @ps1_bis
  to_exec
  arr= @lp.split(">")
  @ps1_bis = /#{arr[0]}:#{logical_router}(\#|>)\s*$/
  p @ps1_bis
  putline "set cli logical-router #{logical_router}"
end

#shell(cmd = nil, *args) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/router/juniper/junos/modes.rb', line 57

def shell(cmd=nil, *args)
  connected = connected?
   unless connected?
  if cmd.nil?
    to_shell
  else
    mode = _mode_?
    to_shell
    output = exp_send(cmd, *args)
    change_mode_to mode
    output
  end
end

#shell?Boolean

returns true if router is in :shell mode, false otherwise.

Returns:

  • (Boolean)


88
89
90
91
92
93
94
95
96
# File 'lib/router/juniper/junos/modes.rb', line 88

def shell?
  if @lp == '% '
    true
  elsif logged_as_root? and @lp =~ /root@.+% $/
    true
  else
    false
  end
end