Skip to content

Commit

Permalink
Add Enterprise SONiC support (#3383)
Browse files Browse the repository at this point in the history
* add Enterprise SONiC support

* move post_login

* fix prompt to match linux & sonic-cli

* grab platform & version details

* rename model

* fix CI rubocop errors

* add model to changelog
  • Loading branch information
ohai89 authored Feb 3, 2025
1 parent 2ba0ed6 commit 4aa5df8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- junos: add unit test (@systeembeheerder)
- apc_aos: support for scp (@robertcheramy)
- config: allow model_map and group_map keys to be regexp. Fixes #3360 (@ytti)
- enterprise_sonic: add new model enterprise_sonic (@ohai89)

### Changed
- sonicos: accept policy message. Fixes #3339 (@Steve-M-C, @robertcheramy)
Expand Down
46 changes: 46 additions & 0 deletions lib/oxidized/model/enterprise_sonic.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
class Enterprise_SONiC < Oxidized::Model # rubocop:disable Naming/ClassAndModuleCamelCase
using Refinements

# Remove ANSI escape codes
expect /\e\[[0-?]*[ -\/]*[@-~]\r?/ do |data, re|
data.gsub re, ''
end

# Matches both sonic-cli and linux terminal
prompt /^(?:[\w.-]+@[\w.-]+:[~\w\/-]+\$|[\w.-]+#)\s*/
comment "# "

def add_comment(comment)
"\n##### #{comment} #####\n"
end

post do
cmd 'show running-configuration' do |cfg|
add_comment('CONFIGURATION') + cfg
end
end

cmd 'show version' do |cfg|
cfg = cfg.each_line.reject { |line| line.match /Uptime/ }.join
add_comment('VERSION') + cfg
end

cmd 'show platform syseeprom' do |cfg|
add_comment('SYSEEPROM') + cfg
end

cmd :all do |cfg|
cfg.cut_both
end

cfg :ssh do
# if user logs in to linux == has admin rights
if vars(:admin) == true
post_login do
cmd "sonic-cli\n"
end
end
post_login 'terminal length 0'
pre_logout 'exit'
end
end

0 comments on commit 4aa5df8

Please sign in to comment.