class Netconf::Serial
Constants
- DEFAULT_BAUD
- DEFAULT_DATABITS
- DEFAULT_PARITY
- DEFAULT_RDBLKSZ
- DEFAULT_STOPBITS
Attributes
args[R]
Public Class Methods
new( args_h, &block )
click to toggle source
Calls superclass method
Netconf::Transport::new
# File lib/net/netconf/serial.rb, line 15 def initialize( args_h, &block ) os_type = args_h[:os_type] || Netconf::DEFAULT_OS_TYPE raise Netconf::InitError, "Missing 'port' param" unless args_h[:port] raise Netconf::InitError, "Missing 'username' param" unless args_h[:username] @args = args_h.clone @args[:prompt] ||= /([%>])\s+$/ # extend this instance with the capabilities of the specific console # type; it needs to define #trans_start_netconf session # this must be provided! if the caller does not, this will # throw a NameError exception. extend Netconf::const_get( os_type )::TransSerial @trans_timeout = @args[:timeout] || Netconf::DEFAULT_TIMEOUT @trans_waitio = @args[:waitio] || Netconf::DEFAULT_WAITIO super( &block ) end
Public Instance Methods
login()
click to toggle source
# File lib/net/netconf/serial.rb, line 37 def login begin puts waitfor(/ogin:/) rescue Timeout::Error puts waitfor(/ogin:/) end puts @args[:username] waitfor(/assword:/) puts @args[:password] waitfor( @args[:prompt] ) end
puts( str = nil )
click to toggle source
# File lib/net/netconf/serial.rb, line 95 def puts( str = nil ) @trans.puts str end
trans_close()
click to toggle source
# File lib/net/netconf/serial.rb, line 82 def trans_close @trans.write Netconf::RPC::MSG_CLOSE_SESSION @trans.close end
trans_open() { |self| ... }
click to toggle source
# File lib/net/netconf/serial.rb, line 55 def trans_open # :yield: self baud = @args[:speed] || DEFAULT_BAUD data_bits = @args[:bits] || DEFAULT_DATABITS stop_bits = @args[:stop] || DEFAULT_STOPBITS parity = @args[:parity] || DEFAULT_PARITY @trans = SerialPort.new( @args[:port], baud, data_bits, stop_bits, parity ) got = login() yield self if block_given? trans_start_netconf( got ) self end
trans_receive()
click to toggle source
# File lib/net/netconf/serial.rb, line 91 def trans_receive Netconf.trans_receive end
trans_receive_hello()
click to toggle source
# File lib/net/netconf/serial.rb, line 71 def trans_receive_hello hello_str = trans_receive() so_xml = hello_str.index("\n") + 1 hello_str.slice!(0, so_xml) hello_str end
trans_send( cmd_str )
click to toggle source
# File lib/net/netconf/serial.rb, line 87 def trans_send( cmd_str ) @trans.write( cmd_str ) end
trans_send_hello()
click to toggle source
# File lib/net/netconf/serial.rb, line 78 def trans_send_hello nil end
waitfor( this_re = nil )
click to toggle source
# File lib/net/netconf/serial.rb, line 99 def waitfor( this_re = nil ) Netconf.waitfor(on_re) end