Class: Netconf::Telnet

Inherits:
Transport show all
Defined in:
lib/net/netconf/telnet.rb

Instance Attribute Summary

Attributes inherited from Transport

#capabilities, #rpc, #session_id, #state, #timeout, #waitio

Instance Method Summary collapse

Methods inherited from Transport

#close, #closed?, #has_capability?, #open, #open?, #rpc_exec, #send_and_receive, #trans_receive_hello, #trans_send_hello

Constructor Details

#initialize(args, trans_args = nil, &block) ⇒ Telnet


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/net/netconf/telnet.rb', line 7

def initialize( args, trans_args = nil, &block )
  os_type = args[:os_type] || Netconf::DEFAULT_OS_TYPE            
  @args = args.clone
        
  # extend this instance with the capabilities of the specific console
  # type; it needs to define #login and #start_netconf session
  begin
    extend Netconf::const_get( os_type )::TransTelnet        
  rescue NameError
    # no extensions available ...
  end     
  
  my_trans_args = {}
  my_trans_args["Host"] = @args[:target]
  my_trans_args["Port"] = @args[:port] if @args[:port]
  
  @trans = Net::Telnet.new( my_trans_args )
  
  @trans_timeout = @args[:timeout] || Netconf::DEFAULT_TIMEOUT
  @trans_waitio = @args[:waitio] || Netconf::DEFAULT_WAITIO      
 
  super( &block )      
end

Instance Method Details

#trans_closeObject


37
38
39
40
# File 'lib/net/netconf/telnet.rb', line 37

def trans_close
  @trans.write Netconf::RPC::MSG_CLOSE_SESSION
  @trans.close
end

#trans_open(&block) ⇒ Object


31
32
33
34
35
# File 'lib/net/netconf/telnet.rb', line 31

def trans_open( &block )
  ()
  trans_start_netconf() 
  self
end

#trans_receiveObject


46
47
48
49
# File 'lib/net/netconf/telnet.rb', line 46

def trans_receive      
  rsp = @trans.waitfor( Netconf::RPC::MSG_END_RE )
  rsp.chomp!( Netconf::RPC::MSG_END + "\n" )      
end

#trans_send(cmd_str) ⇒ Object


42
43
44
# File 'lib/net/netconf/telnet.rb', line 42

def trans_send( cmd_str )
  @trans.write( cmd_str )
end