class Lte::Session
Public Class Methods
new(options = {}, &blk)
click to toggle source
# File lib/eltex/lte/session.rb, line 7 def initialize(options = {}, &blk) @host = options[:host] @user = options[:user] @password = options[:password] @password_pat = options[:password_pat] || %r/Password:/io @prompt_pat = options[:prompt_pat] || %r/^LTE-8X/io $expect_verbose = true if options[:debug] == true begin @o, @i = PTY.spawn("ssh -oStrictHostKeyChecking=no #{@user}@#{@host}") @i.sync = true @o.expect(@password_pat){ @i.puts @password } @o.expect(/#{@password_pat}|#{@prompt_pat}/io) do |output| abort "Incorrect username or password!" if output.first =~ @password_pat @i.puts end rescue abort "Could not connect to device #{@host}!" end end
Public Instance Methods
cmd(command, options = {})
click to toggle source
Run command
# File lib/eltex/lte/session.rb, line 28 def cmd(command, options = {}) @o.expect(@prompt_pat){ @i.puts command } get_result(:array => options[:result_array]) if options[:get_result] == true end
get_list(command)
click to toggle source
Getting results in a list
# File lib/eltex/lte/session.rb, line 34 def get_list(command) out = [] cmd(command) get_result(:array => true).each do |line| out << line.split(/\s+/) end out end
ont_reconfigure(ont_mac)
click to toggle source
Reconfigure ONT
# File lib/eltex/lte/session.rb, line 44 def ont_reconfigure(ont_mac) cmd "ont_mac #{ont_mac}" cmd "reconfigure" ret_val = (get_result =~ /successfully reconfigured/m ? true : false) cmd "exit" return ret_val end
set_ont_profile_and_reconfigure(options = {})
click to toggle source
Setting ONT profile and reconfigure
# File lib/eltex/lte/session.rb, line 53 def set_ont_profile_and_reconfigure(options = {}) ont_mac = options[:ont_mac] profile_index = options[:profile_index] || 0 profile_name = options[:profile_name] || "ipmc" cmd "ont_mac #{ont_mac}" cmd "set profile #{profile_name} #{profile_index}" cmd "reconfigure" ret_val = (get_result =~ /successfully reconfigured/m ? true : false) cmd "exit" return ret_val end
Private Instance Methods
get_result(options = {})
click to toggle source
Getting result
# File lib/eltex/lte/session.rb, line 68 def get_result(options = {}) array = options[:array] || false out = [] @o.expect(@prompt_pat) do |output| out = output.first.split(/\n/) @i.puts end array ? out[1..-2] : out[1..-2].join("\n") end