Skip to content

Commit

Permalink
support cisco ios xe
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
  • Loading branch information
arlimus committed Feb 22, 2018
1 parent 940227d commit 256368c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/train/platforms/detect/helpers/os_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ def cisco_show_version
return @cache[:cisco] = { version: m[2], model: m[1], type: 'ios' }
end

m = res.match(/^Cisco IOS Software, IOS-XE Software, [^,]+? \(([^,]+?)\), Version (\d+\.\d+\.\d+[A-Z]*)/)
unless m.nil?
return @cache[:cisco] = { version: m[2], model: m[1], type: 'ios-xe' }
end

m = res.match(/^Cisco Nexus Operating System \(NX-OS\) Software/)
unless m.nil?
v = res[/^\s*system:\s+version (\d+\.\d+)/, 1]
Expand Down
11 changes: 10 additions & 1 deletion lib/train/platforms/detect/specifications/os.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def self.load
.detect {
# we want to catch a special case here where cisco commands
# don't return an exit status and still print to stdout
if unix_uname_s =~ /./ && !unix_uname_s.start_with?('Line has invalid autocommand ')
if unix_uname_s =~ /./ && !unix_uname_s.start_with?('Line has invalid autocommand ') && !unix_uname_s.start_with?('The command you have entered')
@platform[:arch] = unix_uname_m
true
end
Expand All @@ -50,6 +50,15 @@ def self.load
true
}

plat.name('cisco_ios_xe').title('Cisco IOS XE').in_family('cisco')
.detect {
v = cisco_show_version
next unless v[:type] == 'ios-xe'
@platform[:release] = v[:version]
@platform[:arch] = nil
true
}

plat.name('cisco_nexus').title('Cisco Nexus').in_family('cisco')
.detect {
v = cisco_show_version
Expand Down
10 changes: 10 additions & 0 deletions test/unit/platforms/os_detect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ def debian_scan(id, version)
platform[:release].must_equal('12.2')
end

it 'recognizes Cisco IOS XE' do
mock = Train::Transports::Mock::Connection.new
mock.mock_command('show version', "Cisco IOS Software, IOS-XE Software, Catalyst L3 Switch Software (CAT3K_CAA-UNIVERSALK9-M), Version 03.03.03SE RELEASE SOFTWARE (fc2)")
platform = Train::Platforms::Detect.scan(mock)

platform[:name].must_equal('cisco_ios_xe')
platform[:family].must_equal('cisco')
platform[:release].must_equal('03.03.03SE')
end

it 'recognizes Cisco Nexus' do
mock = Train::Transports::Mock::Connection.new
mock.mock_command('show version', "Cisco Nexus Operating System (NX-OS) Software\n system: version 5.2(1)N1(8b)\n")
Expand Down

0 comments on commit 256368c

Please sign in to comment.