Skip to content

Instantly share code, notes, and snippets.

@mdpuma
Last active August 17, 2026 18:28
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

File location

/var/lib/gems/<ruby_version>/gems/oxidized-/lib/oxidized/model

# frozen_string_literal: true
class JunOS < Oxidized::Model
using Refinements
comment '# '
def telnet
@input.class.to_s.match(/Telnet/)
end
cmd :all do |cfg|
cfg = cfg.cut_both if screenscrape
cfg.gsub!(/ scale-subscriber (\s+)(\d+)/, ' scale-subscriber <count>')
cfg.gsub!(/VMX-BANDWIDTH\s+(\d+) (.*)/, 'VMX-BANDWIDTH <count> \2')
cfg.lines.map { |line| line.rstrip }.join("\n") + "\n"
end
cmd :secret do |cfg|
cfg.gsub!(/community (\S+) {/, 'community <hidden> {')
cfg.gsub!(/(ssh-(rsa|dsa|ecdsa|ecdsa-sk|ed25519|ed25519-sk) )".*; ## SECRET-DATA/, '<secret removed>')
cfg.gsub!(/ "\$\d\$\S+; ## SECRET-DATA/, ' <secret removed>;')
cfg
end
cmd 'show version' do |cfg|
@model = Regexp.last_match(1) if cfg =~ /^Model: (\S+)/
comment cfg
end
post do
out = String.new
case @model
when 'mx960'
out << cmd('show chassis fabric reachability') { |cfg| comment cfg }
when /^(ex22|ex3[34]|ex4|ex8|qfx)/
out << cmd('show virtual-chassis') { |cfg| comment cfg }
when /^srx/
out << cmd('show chassis cluster status') do |cfg|
cfg.lines.count <= 1 && cfg.include?("error:") ? String.new : comment(cfg)
end
end
out
end
cmd('show chassis hardware') { |cfg| comment cfg }
cmd('show system license') do |cfg|
cfg.gsub!(/ fib[-\s]scale\s+(\d+)/i, ' fib-scale <count>')
cfg.gsub!(/ rib[-\s]scale\s+(\d+)/i, ' rib-scale <count>')
comment cfg
end
cmd('show system license keys') { |cfg| comment cfg }
cmd 'show configuration | display omit'
comment 'show configuration | display omit | display set'
cmd 'show configuration | display omit | display set'
cfg :telnet do
username(/^login:/)
password(/^Password:/)
end
cfg :ssh do
exec true # don't run shell, run each command in exec channel
end
cfg :telnet, :ssh do
post_login 'set cli screen-length 0'
post_login 'set cli screen-width 0'
pre_logout 'exit'
end
end
class OS9 < Oxidized::Model
# used for Dell S4810 v9.14
using Refinements
comment "! "
cmd 'show inventory' do |cfg|
comment cfg
end
cmd 'show inventory media' do |cfg|
comment cfg
end
cmd 'show running-config'
cfg :telnet do
username /^Login:/
password /^Password:/
end
cfg :telnet, :ssh do
if vars :enable
post_login do
send "enable\n"
cmd vars(:enable)
end
end
post_login 'terminal length 0'
pre_logout 'exit'
pre_logout 'exit'
end
end
class VSOLOLT < Oxidized::Model
using Refinements
prompt /^([\w.@()-]+[#>]\s?)$/
comment '! '
cmd :all do |cfg|
cfg.cut_both
end
cmd 'show running-config' do |cfg|
cfg.gsub(/Current configuration:/, '')
end
cfg :telnet do
username /^Login:/i
password /^Password:/i
end
cfg :telnet 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
@AAm-kun

AAm-kun commented Mar 14, 2024

Copy link
Copy Markdown

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