Skip to content

Instantly share code, notes, and snippets.

@mdpuma
Created December 13, 2020 07:18
Show Gist options
  • Select an option

  • Save mdpuma/0df4bc4fe6dd8d0aad6d0445902a9f63 to your computer and use it in GitHub Desktop.

Select an option

Save mdpuma/0df4bc4fe6dd8d0aad6d0445902a9f63 to your computer and use it in GitHub Desktop.
VSOL OLT oxidized model
class VSOLOLT < Oxidized::Model
prompt /^([\w.@()-]+[#>]\s?)$/
comment '! '
cmd :all do |cfg|
cfg.gsub! /^% Invalid input detected at '\^' marker\.$|^\s+\^$/, ''
cfg.cut_both
end
# cmd :secret do |cfg|
# cfg.gsub! /^(snmp-server community).*/, '\\1 <configuration removed>'
# cfg.gsub! /^(tacacs-server (.+ )?key) .+/, '\\1 <secret hidden>'
# cfg.gsub! /^username (\S+) privilege (\d+) (\S+).*/, '<secret hidden>'
# cfg.gsub! /^(enable (password|secret)( level \d+)? \d) .+/, '\\1 <secret hidden>'
# cfg
# end
# cmd 'show version-running' do |cfg|
# comment cfg
# end
#
# cmd 'show patch-running' do |cfg|
# comment cfg
# end
cmd 'show running-config' do |cfg|
cfg.gsub! /^Current configuration:/, ''
cfg
end
cfg :telnet do
username /^Login:/i
password /^Password:/i
end
cfg :telnet, :ssh do
# preferred way to handle additional passwords
post_login do
if vars(:enable) == true
cmd "enable"
elsif vars(:enable)
cmd "enable", /^[pP]assword:/
cmd vars(:enable)
end
end
post_login 'terminal length 0'
pre_logout 'disable'
pre_logout 'exit'
end
end
@WojRep
Copy link

WojRep commented Aug 2, 2022

Small change -> VSOL V1600G1 OLT series -> ssh connection:


  prompt /^([\w.@()-]+[#>]\s?)$/
  comment  '! '

  cmd :all do |cfg|
    cfg.gsub! /^% Invalid input detected at '\^' marker\.$|^\s+\^$/, ''
    cfg.cut_both
  end

#   cmd :secret do |cfg|
#     cfg.gsub! /^(snmp-server community).*/, '\\1 <configuration removed>'
#     cfg.gsub! /^(tacacs-server (.+ )?key) .+/, '\\1 <secret hidden>'
#     cfg.gsub! /^username (\S+) privilege (\d+) (\S+).*/, '<secret hidden>'
#     cfg.gsub! /^(enable (password|secret)( level \d+)? \d) .+/, '\\1 <secret hidden>'
#     cfg
#   end

#   cmd 'show version-running' do |cfg|
#     comment cfg
#   end
# 
#   cmd 'show patch-running' do |cfg|
#     comment cfg
#   end

  cmd 'show running-config' do |cfg|
	cfg.gsub! /^Current configuration:/, ''
    cfg
  end

  cfg :telnet, :ssh do
    username /^Login:/i
    password /^Password:/i
    # preferred way to handle additional passwords
    post_login do
      if vars(:enable) == true
        cmd "enable"
      elsif vars(:enable)
        cmd "enable", /^[pP]assword:/
        cmd vars(:enable)
      end
    end
    post_login 'terminal length 0'
    pre_logout 'disable'
    pre_logout 'exit'
  end
end

@AAm-kun
Copy link

AAm-kun commented Mar 14, 2024

FOR
Hardware Version V1.3.4 Firmware Version V2.03.75R (tested on UPLINK EPON OLT 4440 as it seems to use the same firmware as VSOL)

This also works for UPLINK EPON OLT 4440 or should work on any uplink OLT.

class VSOLOLT < Oxidized::Model

  prompt /^([\w.@()-]+[#>]\s?)$/
  comment  '! '

  cmd :all do |cfg|
    cfg.gsub! /^% Invalid input detected at '\^' marker\.$|^\s+\^$/, ''
    cfg.gsub!(/^show running-config$/, '')
    cfg.gsub!(/^.*\s*#\s*$/, '')

    # Remove leading and trailing whitespace
    cfg.strip!

    # Remove empty lines
    cfg.gsub!(/^\s*$/, '')

    cfg
  end


  cmd 'show running-config' do |cfg|
        cfg.gsub! /^Current configuration:/, ''
    cfg
  end

  cfg :telnet, :ssh do
    username /^Login:/i
    password /^Password:/i
    # preferred way to handle additional passwords
    post_login do
      if vars(:enable) == true
        cmd "enable"
      elsif vars(:enable)
        cmd "enable", /^[pP]assword:/
        cmd vars(:enable)
      end
    end
    post_login 'terminal length 0'
    pre_logout 'disable'
    pre_logout 'exit'
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment