-
Notifications
You must be signed in to change notification settings - Fork 950
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Enterprise SONiC support (#3383)
* 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
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |