Class: Ghaki::NetSSH::Telnet

Inherits:
Net::SSH::Telnet
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ghaki/net_ssh/telnet.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ssh, in_opts = {}) ⇒ Telnet

Returns a new instance of Telnet.



56
57
58
59
60
61
62
63
# File 'lib/ghaki/net_ssh/telnet.rb', line 56

def initialize ssh, in_opts={}
  @auto_close = false
  @shell = ssh
  out_opts = in_opts.dup
  out_opts['Session'] = @shell.raw_ssh
  @raw_telnet = ::Net::SSH::Telnet.new(out_opts)
  super @raw_telnet
end

Instance Attribute Details

#auto_closeObject

Returns the value of attribute auto_close.



13
14
15
# File 'lib/ghaki/net_ssh/telnet.rb', line 13

def auto_close
  @auto_close
end

#raw_telnetObject

Returns the value of attribute raw_telnet.



13
14
15
# File 'lib/ghaki/net_ssh/telnet.rb', line 13

def raw_telnet
  @raw_telnet
end

#shellObject

Returns the value of attribute shell.



13
14
15
# File 'lib/ghaki/net_ssh/telnet.rb', line 13

def shell
  @shell
end

Class Method Details

.args_to_tel_opts(args) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/ghaki/net_ssh/telnet.rb', line 20

def self.args_to_tel_opts args
  case args.length
  when 2
    return Hash.new
  when 1, 3
    return args.last[:telnet_options] || {}
  else
    raise ArgumentError, "Invalid Arguments Passed: (1..3) != #{args.length}"
  end
end

.start(*args, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ghaki/net_ssh/telnet.rb', line 31

def self.start *args, &block
  tel_opt = args_to_tel_opts( args )
  gak_ssh = Shell.start( *args )
  gak_tel = Telnet.new( gak_ssh, tel_opt )
  gak_tel.auto_close = true
  if block_given?
    begin
      block.call( gak_tel )
    ensure
      gak_tel.close
    end
  else
    return gak_tel
  end
end

Instance Method Details

#auto_close?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/ghaki/net_ssh/telnet.rb', line 47

def auto_close?
  @auto_close
end

#closeObject



51
52
53
54
# File 'lib/ghaki/net_ssh/telnet.rb', line 51

def close
  super
  @shell.close if @auto_close
end

#exec!(cmd) ⇒ Object



65
66
67
68
69
# File 'lib/ghaki/net_ssh/telnet.rb', line 65

def exec! cmd
  log_exec!( 'TELNET', cmd ) do
    @raw_telnet.cmd( cmd )
  end
end