Class: Expect4r::J

Instance Attribute Summary

Attributes inherited from BaseLoginObject

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

Instance Method Summary collapse

Methods included from Router::Junos::Ping

#ping

Methods included from Router::Junos::Show

#method_missing, #show

Methods included from Router::Junos::Modes

#clear_cli_logical_router, #config, #config?, #exec, #exec?, #set_cli_logical_router, #shell, #shell?

Methods included from Router::Common::Modes

#_mode_?, #change_mode_to, #in?

Methods included from Router::Common

#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, #dup, #enable_password, new_ssh, new_telnet, #password, #spawnee, #spawnee_prompt, #spawnee_username

Methods inherited from Base

add, all

Constructor Details

#initialize(*args) ⇒ J

Returns a new instance of J



10
11
12
13
14
# File 'lib/router/juniper/junos/junos.rb', line 10

def initialize(*args)
  super
  @ps1 = /(^|\r\r)([-a-zA-z@_~=\.\(\)\d]+(>|\#|%)|%|\$) $/
  @more =  /---\(more(| \d+\%)\)---/
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Expect4r::Router::Junos::Show

Instance Method Details

#cliObject



50
51
52
# File 'lib/router/juniper/junos/junos.rb', line 50

def cli
  putline 'cli'
end

#commit(arg = {}) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/router/juniper/junos/junos.rb', line 54

def commit(arg={})
  return unless config?
  @matches << [/Exit with uncommitted changes.+\(yes\)/, 'yes']
  output = putline "commit", arg
  if /error: configuration check-out failed/.match(output.join)
    rollback
    raise SemanticError.new(self.class.to_s, output)
  end
  output
end

#console?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/router/juniper/junos/junos.rb', line 26

def console?
  @port>0
end

#exitObject



46
47
48
# File 'lib/router/juniper/junos/junos.rb', line 46

def exit
  putline 'exit'
end

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



16
17
18
19
20
# File 'lib/router/juniper/junos/junos.rb', line 16

def (arg={})
  super(spawnee, arg)
  exec 'set cli screen-length 0'
  self
end

#putline(line, arg = {}) ⇒ Object

Raises:



30
31
32
33
34
# File 'lib/router/juniper/junos/junos.rb', line 30

def putline(line,arg={})
  o, rc = super
  raise SyntaxError.new(self.class.to_s, line) if o.join =~ /(unknown command|syntax error)/
  o
end

#rollbackObject



36
37
38
39
40
# File 'lib/router/juniper/junos/junos.rb', line 36

def rollback
  return unless config?
  top
  putline 'rollback'
end

#topObject



42
43
44
# File 'lib/router/juniper/junos/junos.rb', line 42

def top
  putline 'top'
end