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

Returns a new instance of Telnet.



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

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



35
36
37
38
# File 'lib/net/netconf/telnet.rb', line 35

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

#trans_open(&block) ⇒ Object



29
30
31
32
33
# File 'lib/net/netconf/telnet.rb', line 29

def trans_open(&block)
  
  trans_start_netconf
  self
end

#trans_receiveObject



44
45
46
47
# File 'lib/net/netconf/telnet.rb', line 44

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

#trans_send(cmd_str) ⇒ Object



40
41
42
# File 'lib/net/netconf/telnet.rb', line 40

def trans_send(cmd_str)
  @trans.write cmd_str
end