From 256368cee76a0af384515f398b55101f096895ea Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Wed, 21 Feb 2018 21:10:30 -0800 Subject: [PATCH] support cisco ios xe Signed-off-by: Dominik Richter --- lib/train/platforms/detect/helpers/os_common.rb | 5 +++++ lib/train/platforms/detect/specifications/os.rb | 11 ++++++++++- test/unit/platforms/os_detect_test.rb | 10 ++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/train/platforms/detect/helpers/os_common.rb b/lib/train/platforms/detect/helpers/os_common.rb index 955e4836..e4c80d79 100644 --- a/lib/train/platforms/detect/helpers/os_common.rb +++ b/lib/train/platforms/detect/helpers/os_common.rb @@ -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] diff --git a/lib/train/platforms/detect/specifications/os.rb b/lib/train/platforms/detect/specifications/os.rb index 00d3e30f..a4a1f020 100644 --- a/lib/train/platforms/detect/specifications/os.rb +++ b/lib/train/platforms/detect/specifications/os.rb @@ -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 @@ -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 diff --git a/test/unit/platforms/os_detect_test.rb b/test/unit/platforms/os_detect_test.rb index a0593260..da21a677 100644 --- a/test/unit/platforms/os_detect_test.rb +++ b/test/unit/platforms/os_detect_test.rb @@ -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")